diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 783dc7333af7e..b9415b2275d8e 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -641,6 +641,10 @@ Bug Fixes in This Version Fixes (`#67317 `_) - Clang now properly diagnoses use of stand-alone OpenMP directives after a label (including ``case`` or ``default`` labels). +- Fix crash when dealing with ill-formed code where we were not handling invalid + redeclarations properly. + Fixes (`#69468 `_) + Before: diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp index 4eae308ef5b34..2ccd83a1d4823 100644 --- a/clang/lib/AST/APValue.cpp +++ b/clang/lib/AST/APValue.cpp @@ -70,11 +70,13 @@ QualType APValue::LValueBase::getType() const { // constexpr int *p = &arr[1]; // valid? // // For now, we take the most complete type we can find. - for (auto *Redecl = cast(D->getMostRecentDecl()); Redecl; + for (auto *Redecl = cast(D->getMostRecentDecl()); + Redecl && !Redecl->isInvalidDecl(); Redecl = cast_or_null(Redecl->getPreviousDecl())) { QualType T = Redecl->getType(); if (!T->isIncompleteArrayType()) return T; + D = Redecl; } return D->getType(); } diff --git a/clang/test/AST/gh69468.cpp b/clang/test/AST/gh69468.cpp new file mode 100644 index 0000000000000..8c93fa5e828ac --- /dev/null +++ b/clang/test/AST/gh69468.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -verify %s + + +a[i] = b[i]; // expected-error {{use of undeclared identifier 'i'}} \ + // expected-error {{a type specifier is required for all declarations}} \ + // expected-error {{use of undeclared identifier 'b'}} \ + // expected-error {{use of undeclared identifier 'i'}} +extern char b[]; +extern char a[]; + +void foo(int j) { + // This used to crash here + a[j] = b[j]; +}