Crash with optimization for size

Here’s a code generated with -Os on darwin/x86_64 with clang from the Xcode 4.2 GM toolset on Mac OSX 10.7.2 (Apple clang version 3.0 (tags/Apple/clang-211.10.1) (based on LLVM 3.0svn), Target: x86_64-apple-darwin11.2.0)

0x000000010277d281 <+2102> lea 0x1d43bd0(%rip),%rax # 0x1044c0e58
0x000000010277d288 <+2109> movaps 0x80(%rax),%xmm0
0x000000010277d28f <+2116> movaps %xmm0,-0x40(%rbp)

The documentation for ‘movaps’ states: “When the source or destination operand is a memory location, it must be aligned on a 16-byte boundary.” The problem is that the address of the global variable loaded into AX is not necessarily aligned; as it isn’t in our case, which leads to the crash.

Here’s is the code; it is loading the address of a global variable into AX, and tries to copy the data member, coming from the following class:

MD5::FingerPrint cutDataCheckSum = ::gFloorPlanCutData.GetCutDataCheckSum ();

memcpy (elemData->cutDataCheckSum,, sizeof (elemData->cutDataCheckSum));

namespace MD5 {

class GSROOT_DLL_EXPORT FingerPrint {


FingerPrint ();

virtual ~FingerPrint () {};

FingerPrint (unsigned char fp[16]);

void Set (unsigned char fp[16]);

virtual GSErrCode Write (GS::OChannel& oc) const;

virtual GSErrCode Read (GS::IChannel& ic);

virtual GSErrCode GetAsString (char* md5String) const;

bool IsEmpty (void) const;

void Clear (void);

bool operator == (const FingerPrint& rhs) const;

bool operator != (const FingerPrint& rhs) const;

FingerPrint& operator= (const FingerPrint& source);


unsigned char data[16];



The type of gFloorPlanCutData is

class FloorPlanCutData: public GS::Object,

public GS::StateEventSource {



double currCutLevel;

double topCutLevel;

double bottomCutLevel;

short topCutBaseStoryRelativeIndex;

short bottomCutBaseStoryRelativeIndex;

double fixLevel2Absolute0;

Int32 lock;

// temporary data dependent from the current story

double currCutLevelCalculated;

double topCutLevelCalculated;

double currentStoryLevel;

double topBase2Current;

double bottomBase2Current;

short currentFloorIndex;

bool relativeCalculated;

MD5::FingerPrint cutDataCheckSum;


The optimization kicks in because ‘data’ is 16-bytes; but there’s no alignment check…

This seems to be a code generation error, but I couldn’t reproduce it in a small application. Is this a known bug, or shall I adjust my build settings?


Ákos Somorjai

Developer Support Manager

GRAPHISOFT | Graphisoft Park 1. Budapest 1031 Hungary | +36 1 437-3000 |

This is
Unfortunately the fix did not make it into that version of clang.

Does Xcode 4.2 allow you to adjust the build settings for individual
source files?

I would check in 4.1myself but I've got a long job running in Ubuntu.

Select the project in the navigator, then select the target from the list.
Select the Build Phases tab, then expand the Compile Sources phase. The
Compiler Flags column is where you specify per-file compiler flags.


Ákos Somorjai
Developer Support Manager

GRAPHISOFT | Graphisoft Park 1. Budapest 1031 Hungary | +36 1 437-3000 |

Thanks, Bob!

I guess we should be expecting a 4.2.1 update after clang 3.0 has been released, shouldn’t we?



Apple release schedules and LLVM release schedules are completely unrelated.