[cfe-dev] Is this an over alignment bug for ARM?

Zhao, Weiming via cfe-dev cfe-dev at lists.llvm.org
Thu Feb 18 12:56:44 PST 2016


Hi,

I'm debugging an Android code which caused data violation fault and it 
seems Clang is generating a store with over alignment.

Given test.cpp:
class F {
   public:
     F(void);
   private:
     F(const F& f);
     const F& operator= (const F& f);
     char *mFileName;
     void *mBasePtr;
     unsigned int mBaseLen;
     long long mOffset;
     void *mDataPtr;
     unsigned int mDataLen;
};

F::F(void)
   :mFileName(0), mBasePtr(0), mBaseLen(0), mDataPtr(0), mDataLen(0) { }

clang++ -S -march=armv7-a -mfloat-abi=softfp -mfpu=neon -std=gnu++11   
-target arm-linux-androideabi -mthumb -Os test.cpp -S -o test.s

THe asm of the constructor is:
     vmov.i32    d16, #0x0
     mov    r1, r0
     vst1.32    {d16}, [r1:64]!   =========> the store assumes *this ptr 
has 8-byte alignment, which seems wrong
     movs    r2, #0
     str    r2, [r1]
     strd    r2, r2, [r0, #24]
     bx    lr

It's because Clang generates a store with alignment of 8:
   %mFileName = getelementptr inbounds %"class.android::FileMap", 
%"class.android::FileMap"* %this, i32 0, i32 0
   store i8* null, i8** %mFileName, align 8

And I trace it back to Clang patch r246985 "Compute and preserve 
alignment more faithfully in IR-generation."

It seems a bug to me.

Thanks,
Weiming


-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation




More information about the cfe-dev mailing list