llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: None (nataliakokoromyti) <details> <summary>Changes</summary> Fix assertion failure 'getType() == Other.getType()' in TypeLoc::initializeFullCopy when parsing malformed _Atomic types with nested sizeof/alignof expressions. When error recovery produces a type that differs from the original TypeSourceInfo, we now fall back to initialize() instead of initializeFullCopy() to avoid the assertion failure. Fixes #<!-- -->173886 --- Full diff: https://github.com/llvm/llvm-project/pull/174583.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaType.cpp (+11-2) - (added) clang/test/Sema/atomic-type-mismatch-crash.c (+10) ``````````diff diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 7ef83433326ed..bf8bc6e9d82a4 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -6138,7 +6138,11 @@ namespace { TypeSourceInfo *TInfo = nullptr; Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); assert(TInfo); - TL.getValueLoc().initializeFullCopy(TInfo->getTypeLoc()); + if (TL.getValueLoc().getType() == TInfo->getTypeLoc().getType()) + TL.getValueLoc().initializeFullCopy(TInfo->getTypeLoc()); + else + TL.getValueLoc().initialize(Context, + TInfo->getTypeLoc().getBeginLoc()); } else { TL.setKWLoc(DS.getAtomicSpecLoc()); // No parens, to indicate this was spelled as an _Atomic qualifier. @@ -6152,7 +6156,12 @@ namespace { TypeSourceInfo *TInfo = nullptr; Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); - TL.getValueLoc().initializeFullCopy(TInfo->getTypeLoc()); + if (TInfo && TL.getValueLoc().getType() == TInfo->getTypeLoc().getType()) + TL.getValueLoc().initializeFullCopy(TInfo->getTypeLoc()); + else + TL.getValueLoc().initialize(Context, + TInfo ? TInfo->getTypeLoc().getBeginLoc() + : DS.getTypeSpecTypeLoc()); } void VisitExtIntTypeLoc(BitIntTypeLoc TL) { diff --git a/clang/test/Sema/atomic-type-mismatch-crash.c b/clang/test/Sema/atomic-type-mismatch-crash.c new file mode 100644 index 0000000000000..03c1b1f2ca54d --- /dev/null +++ b/clang/test/Sema/atomic-type-mismatch-crash.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// This test checks that we don't crash when parsing malformed _Atomic types +// with nested sizeof/alignof expressions. See GitHub issue #173886. + +int a[100]; +int main() { + a[__alignof__(_Atomic(void) _Atomic double unsigned)]; // expected-error {{cannot combine with previous '_Atomic' declaration specifier}} \ + // expected-error {{'_Atomic' cannot be signed or unsigned}} \ + // expected-error {{_Atomic cannot be applied to incomplete type 'void'}} +} `````````` </details> https://github.com/llvm/llvm-project/pull/174583 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
