r227954 - MS ABI: Records with fields with required aligmnet shouldn't be common

David Majnemer david.majnemer at gmail.com
Tue Feb 3 00:49:32 PST 2015


Author: majnemer
Date: Tue Feb  3 02:49:32 2015
New Revision: 227954

URL: http://llvm.org/viewvc/llvm-project?rev=227954&view=rev
Log:
MS ABI: Records with fields with required aligmnet shouldn't be common

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGen/ms-align-tentative.c

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=227954&r1=227953&r2=227954&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Feb  3 02:49:32 2015
@@ -2162,9 +2162,25 @@ static bool isVarDeclStrongDefinition(co
 
   // Declarations with a required alignment do not have common linakge in MSVC
   // mode.
-  if (Context.getLangOpts().MSVCCompat &&
-      (Context.isAlignmentRequired(D->getType()) || D->hasAttr<AlignedAttr>()))
-    return true;
+  if (Context.getLangOpts().MSVCCompat) {
+    if (D->hasAttr<AlignedAttr>())
+      return true;
+    QualType VarType = D->getType();
+    if (Context.isAlignmentRequired(VarType))
+      return true;
+
+    if (const auto *RT = VarType->getAs<RecordType>()) {
+      const RecordDecl *RD = RT->getDecl();
+      for (const FieldDecl *FD : RD->fields()) {
+        if (FD->isBitField())
+          continue;
+        if (FD->hasAttr<AlignedAttr>())
+          return true;
+        if (Context.isAlignmentRequired(FD->getType()))
+          return true;
+      }
+    }
+  }
 
   return false;
 }

Modified: cfe/trunk/test/CodeGen/ms-align-tentative.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-align-tentative.c?rev=227954&r1=227953&r2=227954&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/ms-align-tentative.c (original)
+++ cfe/trunk/test/CodeGen/ms-align-tentative.c Tue Feb  3 02:49:32 2015
@@ -18,3 +18,8 @@ struct __declspec(align(64)) S {
   char fd;
 } s;
 // CHECK-DAG: @s = global %struct.S zeroinitializer, align 64
+
+struct Wrap {
+  struct S x;
+} w;
+// CHECK-DAG: @w = global %struct.Wrap zeroinitializer, align 64





More information about the cfe-commits mailing list