llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Akira Hatanaka (ahatanak) <details> <summary>Changes</summary> TypeProcessingState::takeAttrForAttributedType assumed every AttributedType encountered while filling a declarator's TypeLoc had an (AttributedType*, Attr*) pair registered earlier in the same TypeProcessingState's AttrsForTypes. That assumption doesn't hold when the AttributedType is inherited from another declarator, for example when __typeof__ reuses a type built for a different declaration. In that case, TypeProcessingState::getAttributedType, the function that registers the pair, is never called. Return a null Attr* instead of calling llvm_unreachable when no entry is found. This is the Attr* that AttributedTypeLoc uses for the current declarator's TypeLoc, and null is right here because the current declarator never spelled the attribute itself. Fixes #<!-- -->217489 rdar://184781693 --- Full diff: https://github.com/llvm/llvm-project/pull/220139.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaType.cpp (+5-1) - (modified) clang/test/Sema/nullability.c (+8) ``````````diff diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 27197f36bcc5a..5eb346e0c7c93 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -343,7 +343,11 @@ namespace { } } - llvm_unreachable("no Attr* for AttributedType*"); + // The AttributedType can be inherited from another declarator, for + // example when __typeof__ reuses a type built for a different + // declaration, in which case there is no entry for it in this + // TypeProcessingState. Return null in that case. + return nullptr; } SourceLocation diff --git a/clang/test/Sema/nullability.c b/clang/test/Sema/nullability.c index 5af473ecc41b5..26ff74cb5ff5c 100644 --- a/clang/test/Sema/nullability.c +++ b/clang/test/Sema/nullability.c @@ -250,3 +250,11 @@ void arraysInBlocks(void) { } struct _Nullable NotCplusplusClass {}; // expected-error {{'_Nullable' attribute only applies to classes}} + +// This code used to crash in TypeProcessingState::takeAttrForAttributedType. +struct NullabilityAtomicTypeofS { + int * _Nonnull f1; +}; +void nullabilityAtomicTypeof(const struct NullabilityAtomicTypeofS *s) { + (void)(__typeof__(s->f1) _Atomic *)(&s->f1); +} `````````` </details> https://github.com/llvm/llvm-project/pull/220139 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
