Skip to content

Commit 76bb963

Browse files
authored
No longer assert when using noderef on an _Atomic type (#116237)
When filling out the type locations for a declarator, we handled atomic types and we handled noderef types, but we didn't handle atomic noderef types. Fixes #116124
1 parent 6fb7cdf commit 76bb963

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ Bug Fixes in This Version
553553
the unsupported type instead of the ``register`` keyword (#GH109776).
554554
- Fixed a crash when emit ctor for global variant with flexible array init (#GH113187).
555555
- Fixed a crash when GNU statement expression contains invalid statement (#GH113468).
556+
- Fixed a failed assertion when using ``__attribute__((noderef))`` on an
557+
``_Atomic``-qualified type (#GH116124).
556558

557559
Bug Fixes to Compiler Builtins
558560
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaType.cpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5837,6 +5837,30 @@ static void fillMatrixTypeLoc(MatrixTypeLoc MTL,
58375837
llvm_unreachable("no matrix_type attribute found at the expected location!");
58385838
}
58395839

5840+
static void fillAtomicQualLoc(AtomicTypeLoc ATL, const DeclaratorChunk &Chunk) {
5841+
SourceLocation Loc;
5842+
switch (Chunk.Kind) {
5843+
case DeclaratorChunk::Function:
5844+
case DeclaratorChunk::Array:
5845+
case DeclaratorChunk::Paren:
5846+
case DeclaratorChunk::Pipe:
5847+
llvm_unreachable("cannot be _Atomic qualified");
5848+
5849+
case DeclaratorChunk::Pointer:
5850+
Loc = Chunk.Ptr.AtomicQualLoc;
5851+
break;
5852+
5853+
case DeclaratorChunk::BlockPointer:
5854+
case DeclaratorChunk::Reference:
5855+
case DeclaratorChunk::MemberPointer:
5856+
// FIXME: Provide a source location for the _Atomic keyword.
5857+
break;
5858+
}
5859+
5860+
ATL.setKWLoc(Loc);
5861+
ATL.setParensRange(SourceRange());
5862+
}
5863+
58405864
namespace {
58415865
class TypeSpecLocFiller : public TypeLocVisitor<TypeSpecLocFiller> {
58425866
Sema &SemaRef;
@@ -6223,6 +6247,9 @@ namespace {
62236247
void VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
62246248
TL.setNameLoc(Chunk.Loc);
62256249
}
6250+
void VisitAtomicTypeLoc(AtomicTypeLoc TL) {
6251+
fillAtomicQualLoc(TL, Chunk);
6252+
}
62266253
void
62276254
VisitDependentSizedExtVectorTypeLoc(DependentSizedExtVectorTypeLoc TL) {
62286255
TL.setNameLoc(Chunk.Loc);
@@ -6237,30 +6264,6 @@ namespace {
62376264
};
62386265
} // end anonymous namespace
62396266

6240-
static void fillAtomicQualLoc(AtomicTypeLoc ATL, const DeclaratorChunk &Chunk) {
6241-
SourceLocation Loc;
6242-
switch (Chunk.Kind) {
6243-
case DeclaratorChunk::Function:
6244-
case DeclaratorChunk::Array:
6245-
case DeclaratorChunk::Paren:
6246-
case DeclaratorChunk::Pipe:
6247-
llvm_unreachable("cannot be _Atomic qualified");
6248-
6249-
case DeclaratorChunk::Pointer:
6250-
Loc = Chunk.Ptr.AtomicQualLoc;
6251-
break;
6252-
6253-
case DeclaratorChunk::BlockPointer:
6254-
case DeclaratorChunk::Reference:
6255-
case DeclaratorChunk::MemberPointer:
6256-
// FIXME: Provide a source location for the _Atomic keyword.
6257-
break;
6258-
}
6259-
6260-
ATL.setKWLoc(Loc);
6261-
ATL.setParensRange(SourceRange());
6262-
}
6263-
62646267
static void
62656268
fillDependentAddressSpaceTypeLoc(DependentAddressSpaceTypeLoc DASTL,
62666269
const ParsedAttributesView &Attrs) {

clang/test/Frontend/noderef.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,8 @@ int *const_cast_check(NODEREF const int *x) {
183183
const int *const_cast_check(NODEREF int *x) {
184184
return const_cast<const int *>(x); // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}}
185185
}
186+
187+
namespace GH116124 {
188+
// This declaration would previously cause a failed assertion.
189+
int *_Atomic a __attribute__((noderef));
190+
}

0 commit comments

Comments
 (0)