[clang] 304d130 - Apply the alignment specifier attribute to anonymous unions and structs.

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 20 11:42:46 PST 2019


Author: Kamlesh Kumar
Date: 2019-12-20T14:42:37-05:00
New Revision: 304d1304b7bac190b6c9733eb07be284bfc17030

URL: https://github.com/llvm/llvm-project/commit/304d1304b7bac190b6c9733eb07be284bfc17030
DIFF: https://github.com/llvm/llvm-project/commit/304d1304b7bac190b6c9733eb07be284bfc17030.diff

LOG: Apply the alignment specifier attribute to anonymous unions and structs.

Added: 
    clang/test/AST/pr43983.cpp

Modified: 
    clang/lib/Sema/SemaDecl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 715e8757d43f..8f68be716bd3 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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
index 000000000000..0f4f596361aa
--- /dev/null
+++ b/clang/test/AST/pr43983.cpp
@@ -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


        


More information about the cfe-commits mailing list