r235395 - Fix __alignof__ of global variables on SystemZ

Ulrich Weigand ulrich.weigand at de.ibm.com
Tue Apr 21 10:26:18 PDT 2015


Author: uweigand
Date: Tue Apr 21 12:26:18 2015
New Revision: 235395

URL: http://llvm.org/viewvc/llvm-project?rev=235395&view=rev
Log:
Fix __alignof__ of global variables on SystemZ

SystemZ prefers to align all global variables to two bytes, which is
implemented by setting the TargetInfo member MinGlobalAlign.

However, for compatibility with existing compilers this should *not*
change the ABI alignment value as retrieved via __alignof__, which
it currently does.

This patch fixes the issue by having ASTContext::getDeclAlign ignore
the MinGlobalAlign setting in the ForAlignof case.

Since SystemZ is the only platform setting MinGlobalAlign, this should
cause no change for any other target.


Added:
    cfe/trunk/test/CodeGen/align-systemz.c
    cfe/trunk/test/Sema/align-systemz.c
Modified:
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=235395&r1=235394&r2=235395&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Apr 21 12:26:18 2015
@@ -1335,7 +1335,7 @@ CharUnits ASTContext::getDeclAlign(const
       }
       Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr()));
       if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
-        if (VD->hasGlobalStorage())
+        if (VD->hasGlobalStorage() && !ForAlignof)
           Align = std::max(Align, getTargetInfo().getMinGlobalAlign());
       }
     }

Added: cfe/trunk/test/CodeGen/align-systemz.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/align-systemz.c?rev=235395&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/align-systemz.c (added)
+++ cfe/trunk/test/CodeGen/align-systemz.c Tue Apr 21 12:26:18 2015
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple s390x-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+// SystemZ prefers to align all global variables to two bytes.
+
+struct test {
+   signed char a;
+};
+
+char c;
+// CHECK-DAG: @c = common global i8 0, align 2
+
+struct test s;
+// CHECK-DAG: @s = common global %struct.test zeroinitializer, align 2
+

Added: cfe/trunk/test/Sema/align-systemz.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/align-systemz.c?rev=235395&view=auto
==============================================================================
--- cfe/trunk/test/Sema/align-systemz.c (added)
+++ cfe/trunk/test/Sema/align-systemz.c Tue Apr 21 12:26:18 2015
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple s390x-linux-gnu -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+// SystemZ prefers to align all global variables to two bytes,
+// but this should *not* be reflected in the ABI alignment as
+// retrieved via __alignof__.
+
+struct test {
+  signed char a;
+};
+
+char c;
+struct test s;
+
+int chk1[__alignof__(c) == 1 ? 1 : -1];
+int chk2[__alignof__(s) == 1 ? 1 : -1];
+





More information about the cfe-commits mailing list