[clang] 82e29c6 - Fixed failed assertion w/attribute on anon unions

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 23 05:58:47 PDT 2023


Author: Aaron Ballman
Date: 2023-06-23T08:58:37-04:00
New Revision: 82e29c65e3112fd5d7ed71250bf53ffaec87c2be

URL: https://github.com/llvm/llvm-project/commit/82e29c65e3112fd5d7ed71250bf53ffaec87c2be
DIFF: https://github.com/llvm/llvm-project/commit/82e29c65e3112fd5d7ed71250bf53ffaec87c2be.diff

LOG: Fixed failed assertion w/attribute on anon unions

This amends 304d1304b7bac190b6c9733eb07be284bfc17030 to process the
declaration attributes rather than assert on them; nothing prevents an
attribute from being written on an anonymous union.

Fixes https://github.com/llvm/llvm-project/issues/48512

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaDecl.cpp
    clang/test/SemaCXX/anonymous-union.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 52669132be889..117449f4e2fad 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -528,6 +528,9 @@ Bug Fixes in This Version
   statement expression that appears outside of a function block scope. The
   assertion was benign outside of asserts builds and would only fire in C.
   (`#48579 <https://github.com/llvm/llvm-project/issues/48579>_`).
+- Fixed a failing assertion when applying an attribute to an anonymous union.
+  The assertion was benign outside of asserts builds and would only fire in C++.
+  (`#48512 <https://github.com/llvm/llvm-project/issues/48512>_`).
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9fe1cb20a76f6..f33542e05b983 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5716,10 +5716,10 @@ 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);
+    ProcessDeclAttributes(S, Anon, Dc);
 
     // Default-initialize the implicit variable. This initialization will be
     // trivial in almost all cases, except if a union member has an in-class

diff  --git a/clang/test/SemaCXX/anonymous-union.cpp b/clang/test/SemaCXX/anonymous-union.cpp
index 27dd2f0083b8a..0f1a972d0aa05 100644
--- a/clang/test/SemaCXX/anonymous-union.cpp
+++ b/clang/test/SemaCXX/anonymous-union.cpp
@@ -215,3 +215,8 @@ namespace PR16630 {
     b.y = 0; // expected-error {{'y' is a private member of 'PR16630::A'}}
   }
 }
+
+namespace GH48512 {
+  // This would previously cause an assertion in C++ mode.
+  static __attribute__((a)) union { int a; }; // expected-warning {{unknown attribute 'a' ignored}}
+}


        


More information about the cfe-commits mailing list