Skip to content
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

[Clang] Do not try to diagnose parameter packs in invalid pack expressions #89257

Merged
merged 3 commits into from
Apr 21, 2024

Conversation

cor3ntin
Copy link
Contributor

@cor3ntin cor3ntin commented Apr 18, 2024

In a pack expression, if the id-expression is not valid, do no try to detect whether it is a pack as that would lead to a crash trying to print a recovery expression.

Fixes #88929

…sions

In a pack expression, if the id-expression is not valid,
do no try to detect whether it is a pack as that would lead to a crash trying
to print a recovery expression.

Fixes llvm#88929
@cor3ntin cor3ntin changed the title [Clang] Do not try to diagnose parameter packs in invalid pack expres… [Clang] Do not try to diagnose parameter packs in invalid pack expressions Apr 18, 2024
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Apr 18, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 18, 2024

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)

Changes

In a pack expression, if the id-expression is not valid, do no try to detect whether it is a pack as that would lead to a crash trying to print a recovery expression.

Fixes #88929


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+1-1)
  • (modified) clang/test/SemaCXX/cxx2c-pack-indexing.cpp (+6)
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 4909414c0c78d4..2fdd5aeb736883 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1084,7 +1084,7 @@ ExprResult Sema::ActOnPackIndexingExpr(Scope *S, Expr *PackExpression,
                                        Expr *IndexExpr,
                                        SourceLocation RSquareLoc) {
   bool isParameterPack = ::isParameterPack(PackExpression);
-  if (!isParameterPack) {
+  if (!PackExpression->containsErrors() && !isParameterPack) {
     CorrectDelayedTyposInExpr(IndexExpr);
     Diag(PackExpression->getBeginLoc(), diag::err_expected_name_of_pack)
         << PackExpression;
diff --git a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
index e13635383b6ca6..606715e6aacffd 100644
--- a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
+++ b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
@@ -154,3 +154,9 @@ void f() {
 }
 
 }
+
+namespace GH88929 {
+    bool b = a...[0];  // expected-error {{use of undeclared identifier 'a'}}
+    using E = P...[0]; // expected-error {{unknown type name 'P'}} \
+                       // expected-error {{expected ';' after alias declaration}}
+}

Copy link

github-actions bot commented Apr 18, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@cor3ntin cor3ntin merged commit aa22d44 into llvm:main Apr 21, 2024
3 of 4 checks passed
@cor3ntin cor3ntin deleted the gh88929 branch April 21, 2024 09:43
aniplcc pushed a commit to aniplcc/llvm-project that referenced this pull request Apr 21, 2024
…sions (llvm#89257)

In a pack expression, if the id-expression is not valid, do no try to
detect whether it is a pack as that would lead to a crash trying to
print a recovery expression.

Fixes llvm#88929
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.

Assertion failure when indexing into non-existent pack
3 participants