Author: Aaron Ballman Date: 2024-11-14T11:29:52-05:00 New Revision: 76bb9633a77965cbfce9c3a8985d9a59cf420877
URL: https://github.com/llvm/llvm-project/commit/76bb9633a77965cbfce9c3a8985d9a59cf420877 DIFF: https://github.com/llvm/llvm-project/commit/76bb9633a77965cbfce9c3a8985d9a59cf420877.diff LOG: 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 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaType.cpp clang/test/Frontend/noderef.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 78ba70c624d18c..eecfd585c1c03d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -553,6 +553,8 @@ Bug Fixes in This Version the unsupported type instead of the ``register`` keyword (#GH109776). - Fixed a crash when emit ctor for global variant with flexible array init (#GH113187). - Fixed a crash when GNU statement expression contains invalid statement (#GH113468). +- Fixed a failed assertion when using ``__attribute__((noderef))`` on an + ``_Atomic``-qualified type (#GH116124). Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index dd7c438cbd33ec..4fac71ba095668 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -5837,6 +5837,30 @@ static void fillMatrixTypeLoc(MatrixTypeLoc MTL, llvm_unreachable("no matrix_type attribute found at the expected location!"); } +static void fillAtomicQualLoc(AtomicTypeLoc ATL, const DeclaratorChunk &Chunk) { + SourceLocation Loc; + switch (Chunk.Kind) { + case DeclaratorChunk::Function: + case DeclaratorChunk::Array: + case DeclaratorChunk::Paren: + case DeclaratorChunk::Pipe: + llvm_unreachable("cannot be _Atomic qualified"); + + case DeclaratorChunk::Pointer: + Loc = Chunk.Ptr.AtomicQualLoc; + break; + + case DeclaratorChunk::BlockPointer: + case DeclaratorChunk::Reference: + case DeclaratorChunk::MemberPointer: + // FIXME: Provide a source location for the _Atomic keyword. + break; + } + + ATL.setKWLoc(Loc); + ATL.setParensRange(SourceRange()); +} + namespace { class TypeSpecLocFiller : public TypeLocVisitor<TypeSpecLocFiller> { Sema &SemaRef; @@ -6223,6 +6247,9 @@ namespace { void VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { TL.setNameLoc(Chunk.Loc); } + void VisitAtomicTypeLoc(AtomicTypeLoc TL) { + fillAtomicQualLoc(TL, Chunk); + } void VisitDependentSizedExtVectorTypeLoc(DependentSizedExtVectorTypeLoc TL) { TL.setNameLoc(Chunk.Loc); @@ -6237,30 +6264,6 @@ namespace { }; } // end anonymous namespace -static void fillAtomicQualLoc(AtomicTypeLoc ATL, const DeclaratorChunk &Chunk) { - SourceLocation Loc; - switch (Chunk.Kind) { - case DeclaratorChunk::Function: - case DeclaratorChunk::Array: - case DeclaratorChunk::Paren: - case DeclaratorChunk::Pipe: - llvm_unreachable("cannot be _Atomic qualified"); - - case DeclaratorChunk::Pointer: - Loc = Chunk.Ptr.AtomicQualLoc; - break; - - case DeclaratorChunk::BlockPointer: - case DeclaratorChunk::Reference: - case DeclaratorChunk::MemberPointer: - // FIXME: Provide a source location for the _Atomic keyword. - break; - } - - ATL.setKWLoc(Loc); - ATL.setParensRange(SourceRange()); -} - static void fillDependentAddressSpaceTypeLoc(DependentAddressSpaceTypeLoc DASTL, const ParsedAttributesView &Attrs) { diff --git a/clang/test/Frontend/noderef.cpp b/clang/test/Frontend/noderef.cpp index 68342a8e6467b8..44c11da0dc56a0 100644 --- a/clang/test/Frontend/noderef.cpp +++ b/clang/test/Frontend/noderef.cpp @@ -183,3 +183,8 @@ int *const_cast_check(NODEREF const int *x) { const int *const_cast_check(NODEREF int *x) { return const_cast<const int *>(x); // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}} } + +namespace GH116124 { +// This declaration would previously cause a failed assertion. +int *_Atomic a __attribute__((noderef)); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits