]> granicus.if.org Git - clang/commitdiff
MS ABI: Records with fields with required aligmnet shouldn't be common
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 3 Feb 2015 08:49:32 +0000 (08:49 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 3 Feb 2015 08:49:32 +0000 (08:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@227954 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGen/ms-align-tentative.c

index dc7ec6f6548a57e7b4c2164779edad0a7a428742..bc52028a064b383d1e4bb42c12c5d6d5d768a49e 100644 (file)
@@ -2162,9 +2162,25 @@ static bool isVarDeclStrongDefinition(const ASTContext &Context,
 
   // 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;
 }
index 13d7440e8809486175a810846bb22fb029430ca4..eb68e69f586bd0b970a56cd4684b73cf02b3c3ac 100644 (file)
@@ -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