[dragonegg] r179668 - If the user gave an alignment explicitly, keep it as an explicit alignment even
Duncan Sands
baldrick at free.fr
Tue Apr 16 23:38:50 PDT 2013
Author: baldrick
Date: Wed Apr 17 01:38:49 2013
New Revision: 179668
URL: http://llvm.org/viewvc/llvm-project?rev=179668&view=rev
Log:
If the user gave an alignment explicitly, keep it as an explicit alignment even
if it is the same as the ABI alignment. Based on a patch by Peter Collingbourne.
Added:
dragonegg/trunk/test/validator/c/GlobalAlignment.c
Modified:
dragonegg/trunk/src/Backend.cpp
dragonegg/trunk/src/Convert.cpp
Modified: dragonegg/trunk/src/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Backend.cpp?rev=179668&r1=179667&r2=179668&view=diff
==============================================================================
--- dragonegg/trunk/src/Backend.cpp (original)
+++ dragonegg/trunk/src/Backend.cpp Wed Apr 17 01:38:49 2013
@@ -1117,9 +1117,11 @@ static void emit_global(tree decl) {
TARGET_ADJUST_CSTRING_ALIGN(GV);
#endif
- // If this is the alignment we would have given the variable anyway then don't
- // use an explicit alignment, making the IR look more portable.
- if (GV->getAlignment() ==
+ // If this is the alignment we would have given the variable anyway and it
+ // was not user specified, then don't use an explicit alignment, making the
+ // IR look more portable.
+ if (!DECL_USER_ALIGN(decl) &&
+ GV->getAlignment() ==
getDataLayout().getABITypeAlignment(GV->getType()->getElementType()))
GV->setAlignment(0);
Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=179668&r1=179667&r2=179668&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Wed Apr 17 01:38:49 2013
@@ -2385,9 +2385,11 @@ void TreeToLLVM::EmitAutomaticVariableDe
unsigned Alignment = DECL_ALIGN(decl) / 8; // Alignment in octets.
assert(Alignment != 0 && "Local variable with unknown alignment!");
- // If this is the alignment we would have given the variable anyway then don't
- // use an explicit alignment, making the IR look more portable.
- if (Alignment == getDataLayout().getABITypeAlignment(Ty))
+ // If this is the alignment we would have given the variable anyway and it was
+ // not user specified then don't use an explicit alignment, making the IR look
+ // more portable.
+ if (!DECL_USER_ALIGN(decl) &&
+ Alignment == getDataLayout().getABITypeAlignment(Ty))
Alignment = 0;
// Insert an alloca for this variable.
Added: dragonegg/trunk/test/validator/c/GlobalAlignment.c
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c/GlobalAlignment.c?rev=179668&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c/GlobalAlignment.c (added)
+++ dragonegg/trunk/test/validator/c/GlobalAlignment.c Wed Apr 17 01:38:49 2013
@@ -0,0 +1,8 @@
+// RUN: %dragonegg -S -o - %s | FileCheck %s
+
+struct s {
+ char *a, *b, *c;
+};
+
+// CHECK: @s1 = {{.*}}, align 8
+struct s s1 __attribute__((aligned(8))) = { 0, 0, 0 };
More information about the llvm-commits
mailing list