Skip to content

[Clang] enhance error recovery with RecoveryExpr for trailing commas in call arguments #114684

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 15 commits into from
Nov 22, 2024

Conversation

a-tarasyuk
Copy link
Member

Fixes #100921

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

llvmbot commented Nov 2, 2024

@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)

Changes

Fixes #100921


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

2 Files Affected:

  • (modified) clang/lib/Parse/ParseExpr.cpp (+3)
  • (modified) clang/test/AST/ast-dump-recovery.cpp (+16-1)
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 4570a18bc0d5e5..5fccd2ae106015 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -3705,6 +3705,9 @@ bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
     Token Comma = Tok;
     ConsumeToken();
     checkPotentialAngleBracketDelimiter(Comma);
+
+    if (Tok.is(tok::r_paren))
+      break;
   }
   if (SawError) {
     // Ensure typos get diagnosed when errors were encountered while parsing the
diff --git a/clang/test/AST/ast-dump-recovery.cpp b/clang/test/AST/ast-dump-recovery.cpp
index a88dff471d9f04..1876f4ace32a5a 100644
--- a/clang/test/AST/ast-dump-recovery.cpp
+++ b/clang/test/AST/ast-dump-recovery.cpp
@@ -9,7 +9,7 @@ int some_func(int *);
 // CHECK-NEXT:    `-IntegerLiteral {{.*}} 123
 // DISABLED-NOT: -RecoveryExpr {{.*}} contains-errors
 int invalid_call = some_func(123);
-void test_invalid_call(int s) {
+void test_invalid_call_1(int s) {
   // CHECK:      CallExpr {{.*}} '<dependent type>' contains-errors
   // CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} 'some_func'
   // CHECK-NEXT: |-RecoveryExpr {{.*}} <col:13>
@@ -32,6 +32,21 @@ void test_invalid_call(int s) {
   int var = some_func(undef1);
 }
 
+int some_func2(int a, int b);
+void test_invalid_call_2() {
+  // CHECK:   `-RecoveryExpr {{.*}} 'int' contains-errors
+  // CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} '<overloaded function type>' lvalue (ADL) = 'some_func2'
+  // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
+  some_func2(1, );
+}
+
+void test_invalid_call_3() {
+  // CHECK:   `-RecoveryExpr {{.*}} 'int' contains-errors
+  // CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} '<overloaded function type>' lvalue (ADL) = 'some_func2'
+  // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
+  some_func2(1);
+}
+
 int ambig_func(double);
 int ambig_func(float);
 

@Sirraide Sirraide requested review from cor3ntin and hokein November 19, 2024 09:48
Copy link
Collaborator

@hokein hokein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is nice.

Can you also add a release note?

@a-tarasyuk a-tarasyuk requested a review from hokein November 21, 2024 00:17
@a-tarasyuk a-tarasyuk requested a review from zyn0217 November 21, 2024 08:14
Copy link
Collaborator

@hokein hokein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good.

@hokein hokein merged commit 925e195 into llvm:main Nov 22, 2024
9 checks passed
@shafik
Copy link
Collaborator

shafik commented Jan 31, 2025

This PR is linked to the following regression: #125225

@a-tarasyuk
Copy link
Member Author

@shafik thanks for pointing that out! I'll check it ASAP

@hokein
Copy link
Collaborator

hokein commented Jan 31, 2025

I have a fix for it #125232

hokein added a commit that referenced this pull request Feb 14, 2025
This patch fixes a regression caused by
#114684 where clang accepts
trailing commas for function calls.

Fixes #125225
github-actions bot pushed a commit to arm/arm-toolchain that referenced this pull request Feb 14, 2025
…. (#125232)

This patch fixes a regression caused by
llvm/llvm-project#114684 where clang accepts
trailing commas for function calls.

Fixes #125225
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
)

This patch fixes a regression caused by
llvm#114684 where clang accepts
trailing commas for function calls.

Fixes llvm#125225
swift-ci pushed a commit to swiftlang/llvm-project that referenced this pull request Feb 14, 2025
)

This patch fixes a regression caused by
llvm#114684 where clang accepts
trailing commas for function calls.

Fixes llvm#125225

(cherry picked from commit 922f339)
github-actions bot pushed a commit to arm/arm-toolchain that referenced this pull request Feb 14, 2025
…. (#125232)

This patch fixes a regression caused by
llvm/llvm-project#114684 where clang accepts
trailing commas for function calls.

Fixes #125225

(cherry picked from commit 922f339)
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
)

This patch fixes a regression caused by
llvm#114684 where clang accepts
trailing commas for function calls.

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

Build a RecoveryExpr for a call expression with a trailing comma in the argument list
6 participants