Skip to content

Commit

Permalink
Fixed failed assertion w/attribute on anon unions
Browse files Browse the repository at this point in the history
This amends 304d130 to process the
declaration attributes rather than assert on them; nothing prevents an
attribute from being written on an anonymous union.

Fixes #48512
  • Loading branch information
AaronBallman committed Jun 23, 2023
1 parent 5421ab4 commit 82e29c6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions clang/test/SemaCXX/anonymous-union.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}

0 comments on commit 82e29c6

Please sign in to comment.