[cfe-dev] alignment of internal Global Values

Chris Lattner clattner at apple.com
Mon Mar 8 11:07:39 PST 2010


On Mar 8, 2010, at 9:24 AM, Arnaud Allard de Grandmaison wrote:

> Hi,
>  
> I am a bit puzzled by the alignement set on GlobalValues for which the only differences should be the linkage. I get the same behaviour with llvm-2.6 or with the svn head, using x86 as the target.

Sounds like something that would be good to fix, but your patch doesn't build on mainline:

CGDecl.cpp: In member function ‘llvm::GlobalVariable* clang::CodeGen::CodeGenFunction::AddInitializerToGlobalBlockVarDecl(const clang::VarDecl&, llvm::GlobalVariable*)’:
CGDecl.cpp:190: error: ‘class clang::ASTContext’ has no member named ‘getDeclAlignInBytes’
make[2]: *** [/Volumes/Projects/cvs/llvm/tools/clang/lib/CodeGen/Debug/CGDecl.o] Error 1
m

-Chris

>  
> The following C code can be used to reproduce it:
>  
> short GV[] = { 1,2,3,4,5,6,7,8 };
>  
> int test(unsigned a)
> {
>   static short internalGV[] = { 1,2,3,4,5,6,7,8};
>  
>   return internalGV[a]++;
> }
>  
> The IR output from clang looks like:
> @GV = global [8 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8], align 2
> @test.internalGV = internal global [8 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8]
>  
> Note the alignement specifier for GV, which does not show up for internalGV. The issue will happen later on, when the backend will choose some default alignement, which may even depend on the size of the global value : the size of the data section will depend on the visibility of its data. For example, running the above example with 16 elements in GV & internalGV will make a big difference in the x86 .S file : GV will still be 2 bytes aligned, whereas internalGV will be 16bytes aligned.
>  
> I can not see any obvious reason why this could be the desired behaviour, so I attached a patch to fix this.
>  
> Best regards,
> --
> Arnaud de Grandmaison
> <internalGV-alignment.patch>_______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100308/47444d4b/attachment.html>


More information about the cfe-dev mailing list