Apply the alignment specifier attribute to anonymous unions and structs.
authorKamlesh Kumar <kamleshbhalui@gmail.com>
Fri, 20 Dec 2019 19:41:46 +0000 (14:41 -0500)
committerAaron Ballman <aaron@aaronballman.com>
Fri, 20 Dec 2019 19:42:37 +0000 (14:42 -0500)
clang/lib/Sema/SemaDecl.cpp
clang/test/AST/pr43983.cpp [new file with mode: 0644]

index 715e875..8f68be7 100644 (file)
@@ -5025,6 +5025,8 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
         /*BitWidth=*/nullptr, /*Mutable=*/false,
         /*InitStyle=*/ICIS_NoInit);
     Anon->setAccess(AS);
+    ProcessDeclAttributes(S, Anon, Dc);
+
     if (getLangOpts().CPlusPlus)
       FieldCollector->Add(cast<FieldDecl>(Anon));
   } else {
@@ -5038,6 +5040,7 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
       SC = SC_None;
     }
 
+    assert(DS.getAttributes().empty() && "No attribute expected");
     Anon = VarDecl::Create(Context, Owner, DS.getBeginLoc(),
                            Record->getLocation(), /*IdentifierInfo=*/nullptr,
                            Context.getTypeDeclType(Record), TInfo, SC);
diff --git a/clang/test/AST/pr43983.cpp b/clang/test/AST/pr43983.cpp
new file mode 100644 (file)
index 0000000..0f4f596
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only %s -ast-dump | FileCheck %s
+
+struct B { _Alignas(64) struct { int b; };   };
+
+// CHECK: AlignedAttr {{.*}} _Alignas
+// CHECK: ConstantExpr {{.*}} 64
+// CHECK: IntegerLiteral {{.*}} 64