[clang] [clang] fix(85447): clang 18.1.0 crashes in clang::ASTContext::getTypeInfoImpl (PR #89850)

Oleksandr T. via cfe-commits cfe-commits at lists.llvm.org
Wed May 1 06:35:34 PDT 2024


https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/89850

>From f4e4e7b91e85d12c861063e1461b160b9bd22da6 Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.tarasiuk at outlook.com>
Date: Mon, 29 Apr 2024 01:53:47 +0300
Subject: [PATCH 1/2] fix(85447): refine handling of incomplete anonymous
 struct declarations

---
 clang/lib/Sema/SemaDecl.cpp                |  3 +++
 clang/test/Sema/incomplete-struct-decl.cpp | 10 ++++++++++
 2 files changed, 13 insertions(+)
 create mode 100644 clang/test/Sema/incomplete-struct-decl.cpp

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 671752b56e01f4..d3871bb7447405 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5789,6 +5789,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 '}'}}

>From fedc5eab0765ae999d849a49eba88a995f558405 Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.tarasiuk at outlook.com>
Date: Wed, 1 May 2024 16:35:17 +0300
Subject: [PATCH 2/2] update changelog

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2c5308fbcb319a..a146dedb125a34 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -630,6 +630,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
 ^^^^^^^^^^^^^^^^^^^^^^^^^



More information about the cfe-commits mailing list