[cfe-dev] alignment of internal Global Values
Arnaud Allard de Grandmaison
Arnaud.AllardDeGrandMaison at dibcom.com
Mon Mar 8 13:00:35 PST 2010
All apologies. I should have check it against head.
The corrected patch is attached. It applies cleanly on the head of llvm + clang
--
Arnaud de Grandmaison
________________________________________
From: Chris Lattner [clattner at apple.com]
Sent: Monday, March 08, 2010 8:07 PM
To: Arnaud Allard de Grandmaison
Cc: cfe-dev at cs.uiuc.edu
Subject: Re: [cfe-dev] alignment of internal Global Values
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<mailto:cfe-dev at cs.uiuc.edu>
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: internalGV-alignment.patch
Type: text/x-patch
Size: 509 bytes
Desc: internalGV-alignment.patch
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100308/4ffd0559/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_internalGV-alignment.c
Type: text/x-csrc
Size: 172 bytes
Desc: test_internalGV-alignment.c
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100308/4ffd0559/attachment.c>
More information about the cfe-dev
mailing list