[clang] cd132dc - [clang] fix(85447): clang 18.1.0 crashes in clang::ASTContext::getTypeInfoImpl (#89850)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 2 00:23:03 PDT 2024
Author: Oleksandr T
Date: 2024-05-02T09:22:59+02:00
New Revision: cd132dcbeb0fc79fd657bd5e0a8e9244c3fb5da6
URL: https://github.com/llvm/llvm-project/commit/cd132dcbeb0fc79fd657bd5e0a8e9244c3fb5da6
DIFF: https://github.com/llvm/llvm-project/commit/cd132dcbeb0fc79fd657bd5e0a8e9244c3fb5da6.diff
LOG: [clang] fix(85447): clang 18.1.0 crashes in clang::ASTContext::getTypeInfoImpl (#89850)
Fixes #85447
---
This PR resolves a crash in `ActOnUninitializedDecl` due to an oversight
in updating the `isInvalidDecl` state before invocation. The crash
occurs due to a missing invocation of `setInvalidDecl()` for an invalid
`Anon` declaration. To address this issue, the `setInvalidDecl()` method
is now properly invoked to mark the `Anon` declaration as invalid before
running `ActOnUninitializedDecl()`.
Added:
clang/test/Sema/incomplete-struct-decl.cpp
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d402babc8aaa6c..818dce8fb83b9e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -649,6 +649,7 @@ Bug Fixes to C++ Support
- Fix a bug on template partial specialization with issue on deduction of nontype template parameter
whose type is `decltype(auto)`. Fixes (#GH68885).
- Clang now correctly treats the noexcept-specifier of a friend function to be a complete-class context.
+- Fix an assertion failure when parsing an invalid members of an anonymous class. (#GH85447)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 79fb6c0417e33d..19968452f0d566 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5790,6 +5790,9 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
Anon = VarDecl::Create(Context, Owner, DS.getBeginLoc(),
Record->getLocation(), /*IdentifierInfo=*/nullptr,
Context.getTypeDeclType(Record), TInfo, SC);
+ if (Invalid)
+ Anon->setInvalidDecl();
+
ProcessDeclAttributes(S, Anon, Dc);
// Default-initialize the implicit variable. This initialization will be
diff --git a/clang/test/Sema/incomplete-struct-decl.cpp b/clang/test/Sema/incomplete-struct-decl.cpp
new file mode 100644
index 00000000000000..bc3bd6b2eae2f0
--- /dev/null
+++ b/clang/test/Sema/incomplete-struct-decl.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify=cxx,expected %s
+
+template <class a> using __impl_of = a; // expected-note {{'__impl_of' declared here}} \
+ expected-note {{template is declared here}}
+struct { // expected-error {{anonymous structs and classes must be class members}} \
+ expected-note {{to match this '{'}}
+ __impl_; // expected-error {{no template named '__impl_'; did you mean '__impl_of'?}} \
+ expected-error {{cannot specify deduction guide for alias template '__impl_of'}} \
+ expected-error {{expected ';' after struct}}
+ // expected-error {{expected '}'}}
More information about the cfe-commits
mailing list