Skip to content

[Clang] Avoid a crash when parsing an invalid pseudo-destructor #111666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

cor3ntin
Copy link
Contributor

@cor3ntin cor3ntin commented Oct 9, 2024

Fixes #111460.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 9, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 9, 2024

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)

Changes

Fixes #11460.


Full diff: https://github.com/llvm/llvm-project/pull/111666.diff

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+1)
  • (modified) clang/lib/Sema/SemaExprCXX.cpp (+2-1)
  • (modified) clang/test/Parser/cxx2c-pack-indexing.cpp (+11)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 583c1e6b4215c5..fdf197f802ed33 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -481,6 +481,7 @@ Bug Fixes to C++ Support
 - Clang now uses the correct set of template argument lists when comparing the constraints of
   out-of-line definitions and member templates explicitly specialized for a given implicit instantiation of
   a class template. (#GH102320)
+- Fix a crash when parsing a pseudo destructor involving an invalid type. (#GH11460)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d490452e91c3bb..8e9bcb10a80b46 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -8429,7 +8429,8 @@ ExprResult Sema::ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
   QualType ObjectType;
   QualType T;
   TypeLocBuilder TLB;
-  if (CheckArrow(*this, ObjectType, Base, OpKind, OpLoc))
+  if (CheckArrow(*this, ObjectType, Base, OpKind, OpLoc) ||
+      DS.getTypeSpecType() == DeclSpec::TST_error)
     return ExprError();
 
   switch (DS.getTypeSpecType()) {
diff --git a/clang/test/Parser/cxx2c-pack-indexing.cpp b/clang/test/Parser/cxx2c-pack-indexing.cpp
index 1b84ddfc6c20a5..c279bdd7af8c44 100644
--- a/clang/test/Parser/cxx2c-pack-indexing.cpp
+++ b/clang/test/Parser/cxx2c-pack-indexing.cpp
@@ -63,3 +63,14 @@ struct base {
 int main() {
     SS<int, base>().f(0);
 }
+
+
+namespace GH11460 {
+template <typename... T>
+requires( ); // expected-error {{expected expression}}
+struct SS {
+    void f( ) {
+        (*p).~T...[](); // expected-error {{use of undeclared identifier 'p'}}
+    }
+};
+}

@zyn0217
Copy link
Contributor

zyn0217 commented Oct 9, 2024

FYI it's #111460

@erichkeane
Copy link
Collaborator

Linux failure is an unrelated 'hip driver' test.

@cor3ntin cor3ntin merged commit 1ad5f31 into llvm:main Oct 9, 2024
8 of 10 checks passed
@cor3ntin cor3ntin deleted the corentin/gh11460 branch October 9, 2024 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[clang++] Assertion trunk crashes at clang::Sema::ActOnPseudoDestructorExpr
4 participants