[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-06-10 Thread David Spickett via cfe-commits

DavidSpickett wrote:

I've disabled the failing `RUN` line on Windows and opened 
https://github.com/llvm/llvm-project/issues/143547 with details of what's 
happening.

Let me know if anything stands out to you. Also would be useful if I can see 
the code produced at the different optimisation levels.

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-06-10 Thread David Spickett via cfe-commits

DavidSpickett wrote:

Thanks for confirming, yes, your patch is working as expected but something 
about Windows' output is tripping up FileCheck I think.

Linux does not print the `clang-repl>` (maybe because it can tell it's 
outputting to a non-interactive pipe):
```
$ cat ../llvm-project/clang/test/Interpreter/lambda.cpp | ./bin/clang-repl -Xcc 
-Xclang -Xcc -verify -Xcc -O2
ONE
TWO
TWO
error: Parsing failed.
x = 42
```
Which should not be a problem in theory.

I'll will figure it out.

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-06-10 Thread Anutosh Bhat via cfe-commits

anutosh491 wrote:

Hi, 

On phone right now so shall have a better look at the error in sometime but 
just for some clarification, the parsing error is expected (we had a seg fault 
on master for this whereas a parsing error is expected and that's what the Pr 
is trying to achieve)

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-06-10 Thread David Spickett via cfe-commits

DavidSpickett wrote:

Also failing on Windows x64, but this time the error is better:
https://lab.llvm.org/buildbot/#/builders/63/builds/7023

And now I see the actual problem, all I had to do was scroll up :)
```
# .---command stderr
# | In file included from <<< inputs >>>:1:
# | input_line_22:1:17: error: non-local lambda expression cannot have a 
capture-default
# | 1 | auto capture = [&]() { return x * 2; };
# |   | ^
# | error: Parsing failed.
# `-
```

Puzzling that we don't see this on other platforms though.

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-06-10 Thread David Spickett via cfe-commits

DavidSpickett wrote:

After this change the test labda.cpp is failing on Linaro's Windows on Arm 
clang bots. They were stuck for other reasons and only just got back up to 
date, so here's a new build showing the failure:
https://lab.llvm.org/buildbot/#/builders/161/builds/6473
```
cat 
C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp
 | c:\users\tcwg\llvm-worker\clang-arm64-windows-msvc\build\bin\clang-repl.exe 
-Xcc -Xclang -Xcc -verify -Xcc -O2 | 
c:\users\tcwg\llvm-worker\clang-arm64-windows-msvc\build\bin\filecheck.exe 
C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp
# executed command: cat 
'C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp'
# executed command: 
'c:\users\tcwg\llvm-worker\clang-arm64-windows-msvc\build\bin\clang-repl.exe' 
-Xcc -Xclang -Xcc -verify -Xcc -O2
# .---command stderr
# | error: Parsing failed.
# `-
# executed command: 
'c:\users\tcwg\llvm-worker\clang-arm64-windows-msvc\build\bin\filecheck.exe' 
'C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp'
# .---command stderr
# | 
C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp:26:11:
 error: CHECK: expected string not found in input
# | // CHECK: x = 42
# |   ^
# | :4:28: note: scanning from here
# | clang-repl> clang-repl> TWO
# |^
# | :5:9: note: possible intended match here
# | clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> 
# | ^
# | 
# | Input file: 
# | Check file: 
C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<
# | 1: x = 42 
# | 2: clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> ONE 
# | 3: clang-repl> clang-repl> TWO 
# | 4: clang-repl> clang-repl> TWO 
# | check:26'0X error: no match found
# | 5: clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl>  
# | check:26'0 
~
# | check:26'1 ?

 possible intended match
# | >>
# `-
# error: command failed with exit status: 1
--
```
I've confirmed locally that the test passed before this change.

The first RUN line is ok:
```
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build>cat 
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\clang\test\Interpreter\lambda.cpp
 | .\bin\clang-repl.exe
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-repl> ONE
clang-repl> clang-repl> TWO
clang-repl> clang-repl> TWO
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> In file included from <<< inputs >>>:1:
input_line_21:1:17: error: non-local lambda expression cannot have a 
capture-default
1 | auto capture = [&]() { return x * 2; };
  | ^
error: Parsing failed.
clang-repl> clang-repl> clang-repl> x = 42
clang-repl> clang-repl> clang-repl>
```
The second one fails to parse the lambda:
```
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build>cat 
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\clang\test\Interpreter\lambda.cpp
 | .\bin\clang-repl.exe -Xcc -Xclang -Xcc -verify -Xcc -O2
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-repl> ONE
clang-repl> clang-repl> TWO
clang-repl> clang-repl> TWO
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> error: Parsing failed.
clang-repl> clang-repl> clang-repl> x = 42
clang-repl> clang-repl> clang-repl>
```
(also the repeated `clang-repl>` is strange but maybe that is expected?)

How can I debug this further, is there a way to enable some verbose parsing / 
verification? (seems more likely that verification is actually the failing part)

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-06-02 Thread via cfe-commits

llvmbot wrote:

/pull-request llvm/llvm-project#142445

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-06-02 Thread Anutosh Bhat via cfe-commits

anutosh491 wrote:

/cherry-pick 
https://github.com/llvm/llvm-project/commit/3b4c51bb3243a02526313c51207a674139b67a00

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-06-02 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 milestoned 
https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-06-02 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 closed 
https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-06-02 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev approved this pull request.

LGTM! Thank you.

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-06-02 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/127467

>From bd1b0b2a14afeb73755db3a7deb6bffd4f50778c Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Mon, 17 Feb 2025 15:33:20 +0530
Subject: [PATCH 1/4] Fix error recovery while PTU cleanup

---
 clang/lib/Interpreter/IncrementalParser.cpp |  2 +-
 clang/test/Interpreter/lambda.cpp   | 11 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 41d6304bd5f65..6343f17ed822a 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -176,7 +176,7 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
   // FIXME: We should de-allocate MostRecentTU
   for (Decl *D : MostRecentTU->decls()) {
 auto *ND = dyn_cast(D);
-if (!ND)
+if (!ND || ND->getDeclName().isEmpty())
   continue;
 // Check if we need to clean up the IdResolver chain.
 if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index df75274a050b2..8f49f870fddb6 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s
+
 extern "C" int printf(const char *, ...);
 
 auto l1 = []() { printf("ONE\n"); return 42; };
@@ -14,4 +15,10 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+auto capture = [&]() { return x * 2; };
+
+%quit
\ No newline at end of file

>From 1963cc341cd356f06a6c582235e47ac3cf144a63 Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Wed, 12 Mar 2025 16:43:45 +0530
Subject: [PATCH 2/4] Fix test as per review

---
 clang/test/Interpreter/lambda.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index 8f49f870fddb6..7e8dcd61f20c8 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck %s
 
 extern "C" int printf(const char *, ...);
 
@@ -21,4 +21,7 @@ int x = 42;
 // expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
 auto capture = [&]() { return x * 2; };
 
+// Ensure valid C++ code before exiting
+x = 100;
+
 %quit
\ No newline at end of file

>From 45924cdddab5fdb89823792ebf5577469e474432 Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Wed, 12 Mar 2025 17:31:35 +0530
Subject: [PATCH 3/4] fix failing lambda.cpp

---
 clang/test/Interpreter/lambda.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index 7e8dcd61f20c8..07eb6fb017360 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -18,7 +18,7 @@ auto r3 = l2();
 // Verify non-local lambda capture error is correctly reported
 int x = 42;
 
-// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+// expected-error {{non-local lambda expression cannot have a capture-default}}
 auto capture = [&]() { return x * 2; };
 
 // Ensure valid C++ code before exiting

>From 056555cb8ae70d01de6258aaf10cae754b33714c Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Mon, 2 Jun 2025 16:59:55 +0530
Subject: [PATCH 4/4] print the value for x after the parsing failed error on
 capture

---
 clang/test/Interpreter/lambda.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index 07eb6fb017360..7e5e1057e4c9e 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -21,7 +21,8 @@ int x = 42;
 // expected-error {{non-local lambda expression cannot have a capture-default}}
 auto capture = [&]() { return x * 2; };
 
-// Ensure valid C++ code before exiting
-x = 100;
+// Ensure interpreter continues and x is still valid
+printf("x = %d\n", x);
+// CHECK: x = 42
 
 %quit
\ No newline at end of file

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-06-02 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/127467

>From bd1b0b2a14afeb73755db3a7deb6bffd4f50778c Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Mon, 17 Feb 2025 15:33:20 +0530
Subject: [PATCH 1/3] Fix error recovery while PTU cleanup

---
 clang/lib/Interpreter/IncrementalParser.cpp |  2 +-
 clang/test/Interpreter/lambda.cpp   | 11 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 41d6304bd5f65..6343f17ed822a 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -176,7 +176,7 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
   // FIXME: We should de-allocate MostRecentTU
   for (Decl *D : MostRecentTU->decls()) {
 auto *ND = dyn_cast(D);
-if (!ND)
+if (!ND || ND->getDeclName().isEmpty())
   continue;
 // Check if we need to clean up the IdResolver chain.
 if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index df75274a050b2..8f49f870fddb6 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s
+
 extern "C" int printf(const char *, ...);
 
 auto l1 = []() { printf("ONE\n"); return 42; };
@@ -14,4 +15,10 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+auto capture = [&]() { return x * 2; };
+
+%quit
\ No newline at end of file

>From 1963cc341cd356f06a6c582235e47ac3cf144a63 Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Wed, 12 Mar 2025 16:43:45 +0530
Subject: [PATCH 2/3] Fix test as per review

---
 clang/test/Interpreter/lambda.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index 8f49f870fddb6..7e8dcd61f20c8 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck %s
 
 extern "C" int printf(const char *, ...);
 
@@ -21,4 +21,7 @@ int x = 42;
 // expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
 auto capture = [&]() { return x * 2; };
 
+// Ensure valid C++ code before exiting
+x = 100;
+
 %quit
\ No newline at end of file

>From 45924cdddab5fdb89823792ebf5577469e474432 Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Wed, 12 Mar 2025 17:31:35 +0530
Subject: [PATCH 3/3] fix failing lambda.cpp

---
 clang/test/Interpreter/lambda.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index 7e8dcd61f20c8..07eb6fb017360 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -18,7 +18,7 @@ auto r3 = l2();
 // Verify non-local lambda capture error is correctly reported
 int x = 42;
 
-// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+// expected-error {{non-local lambda expression cannot have a capture-default}}
 auto capture = [&]() { return x * 2; };
 
 // Ensure valid C++ code before exiting

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-05-13 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 edited 
https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-05-13 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/127467



  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-05-13 Thread Anutosh Bhat via cfe-commits


@@ -14,4 +15,13 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error {{non-local lambda expression cannot have a capture-default}}
+auto capture = [&]() { return x * 2; };
+

anutosh491 wrote:

I think this is all that we need here. Should be ready. let me try updating !

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-05-13 Thread Anutosh Bhat via cfe-commits


@@ -14,4 +15,13 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error {{non-local lambda expression cannot have a capture-default}}
+auto capture = [&]() { return x * 2; };
+

anutosh491 wrote:

Sorry, I think I might have missed this. 

If I remember correctly, the above is an expected error 
```
clang-repl> int x = 42; auto capture = [&]() { return x * 2; };
In file included from <<< inputs >>>:1:
input_line_1:1:28: error: non-local lambda expression cannot have a 
capture-default
1 | int x = 42; auto capture = [&]() { return x * 2; };
  |^
error: Parsing failed.
```
So we wouldn't have to check for the value to be 84 here !

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-04-04 Thread Vassil Vassilev via cfe-commits


@@ -14,4 +15,13 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error {{non-local lambda expression cannot have a capture-default}}
+auto capture = [&]() { return x * 2; };
+

vgvassilev wrote:

Don’t we want to check the value of X here to be 84?

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-03-31 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev approved this pull request.

Lgtm!

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-03-12 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/127467

>From bd1b0b2a14afeb73755db3a7deb6bffd4f50778c Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Mon, 17 Feb 2025 15:33:20 +0530
Subject: [PATCH 1/3] Fix error recovery while PTU cleanup

---
 clang/lib/Interpreter/IncrementalParser.cpp |  2 +-
 clang/test/Interpreter/lambda.cpp   | 11 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 41d6304bd5f65..6343f17ed822a 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -176,7 +176,7 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
   // FIXME: We should de-allocate MostRecentTU
   for (Decl *D : MostRecentTU->decls()) {
 auto *ND = dyn_cast(D);
-if (!ND)
+if (!ND || ND->getDeclName().isEmpty())
   continue;
 // Check if we need to clean up the IdResolver chain.
 if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index df75274a050b2..8f49f870fddb6 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s
+
 extern "C" int printf(const char *, ...);
 
 auto l1 = []() { printf("ONE\n"); return 42; };
@@ -14,4 +15,10 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+auto capture = [&]() { return x * 2; };
+
+%quit
\ No newline at end of file

>From 1963cc341cd356f06a6c582235e47ac3cf144a63 Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Wed, 12 Mar 2025 16:43:45 +0530
Subject: [PATCH 2/3] Fix test as per review

---
 clang/test/Interpreter/lambda.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index 8f49f870fddb6..7e8dcd61f20c8 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck %s
 
 extern "C" int printf(const char *, ...);
 
@@ -21,4 +21,7 @@ int x = 42;
 // expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
 auto capture = [&]() { return x * 2; };
 
+// Ensure valid C++ code before exiting
+x = 100;
+
 %quit
\ No newline at end of file

>From 45924cdddab5fdb89823792ebf5577469e474432 Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Wed, 12 Mar 2025 17:31:35 +0530
Subject: [PATCH 3/3] fix failing lambda.cpp

---
 clang/test/Interpreter/lambda.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index 7e8dcd61f20c8..07eb6fb017360 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -18,7 +18,7 @@ auto r3 = l2();
 // Verify non-local lambda capture error is correctly reported
 int x = 42;
 
-// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+// expected-error {{non-local lambda expression cannot have a capture-default}}
 auto capture = [&]() { return x * 2; };
 
 // Ensure valid C++ code before exiting

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-03-12 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-03-12 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/127467

>From bd1b0b2a14afeb73755db3a7deb6bffd4f50778c Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Mon, 17 Feb 2025 15:33:20 +0530
Subject: [PATCH 1/2] Fix error recovery while PTU cleanup

---
 clang/lib/Interpreter/IncrementalParser.cpp |  2 +-
 clang/test/Interpreter/lambda.cpp   | 11 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 41d6304bd5f65..6343f17ed822a 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -176,7 +176,7 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
   // FIXME: We should de-allocate MostRecentTU
   for (Decl *D : MostRecentTU->decls()) {
 auto *ND = dyn_cast(D);
-if (!ND)
+if (!ND || ND->getDeclName().isEmpty())
   continue;
 // Check if we need to clean up the IdResolver chain.
 if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index df75274a050b2..8f49f870fddb6 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s
+
 extern "C" int printf(const char *, ...);
 
 auto l1 = []() { printf("ONE\n"); return 42; };
@@ -14,4 +15,10 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+auto capture = [&]() { return x * 2; };
+
+%quit
\ No newline at end of file

>From 1963cc341cd356f06a6c582235e47ac3cf144a63 Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Wed, 12 Mar 2025 16:43:45 +0530
Subject: [PATCH 2/2] Fix test as per review

---
 clang/test/Interpreter/lambda.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index 8f49f870fddb6..7e8dcd61f20c8 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck %s
 
 extern "C" int printf(const char *, ...);
 
@@ -21,4 +21,7 @@ int x = 42;
 // expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
 auto capture = [&]() { return x * 2; };
 
+// Ensure valid C++ code before exiting
+x = 100;
+
 %quit
\ No newline at end of file

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-03-11 Thread Vassil Vassilev via cfe-commits


@@ -1,7 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s

vgvassilev wrote:

We should not need a `not` here. You can probably avoid it by adding a correct 
C++ code before calling `quit`.

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-03-11 Thread Anutosh Bhat via cfe-commits


@@ -1,7 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s

anutosh491 wrote:

Sure shall take care of it. Thanks 

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-03-11 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/127467

>From 6ff448ed506e0ef75db2c9974a628a965e85df2f Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Mon, 17 Feb 2025 15:33:20 +0530
Subject: [PATCH 1/5] Fix error recovery while PTU cleanup

---
 clang/lib/Interpreter/IncrementalParser.cpp | 4 ++--
 clang/unittests/Interpreter/InterpreterTest.cpp | 7 +++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index e43cea1baf43a..1ebef0e434b3d 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -178,8 +178,8 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
 if (!ND)
   continue;
 // Check if we need to clean up the IdResolver chain.
-if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
-!D->getLangOpts().CPlusPlus)
+if (!ND->getDeclName().isEmpty() && ND->getDeclName().getFETokenInfo() &&
+!D->getLangOpts().ObjC && !D->getLangOpts().CPlusPlus)
   S.IdResolver.RemoveDecl(ND);
   }
 }
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 578f1d4c0eac6..56ab155ebf5a4 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -114,6 +114,13 @@ TEST_F(InterpreterTest, Errors) {
 
   RecoverErr = Interp->Parse("var1 = 424;");
   EXPECT_TRUE(!!RecoverErr);
+
+  Err = Interp->Parse("int x = 5; auto capture = [&]() { return x * 2; 
};").takeError();
+  EXPECT_THAT(DiagnosticOutput, HasSubstr("error: non-local lambda expression 
cannot have a capture-default"));
+  EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
+
+  RecoverErr = Interp->Parse("int validVar = 10;");
+  EXPECT_TRUE(!!RecoverErr);
 }
 
 // Here we test whether the user can mix declarations and statements. The

>From 8b9a112721c45662374fd9995af6da4031507c89 Mon Sep 17 00:00:00 2001
From: Anutosh Bhat 
Date: Wed, 26 Feb 2025 16:55:31 +0530
Subject: [PATCH 2/5] Update IncrementalParser.cpp

---
 clang/lib/Interpreter/IncrementalParser.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 1ebef0e434b3d..774219d9fc9ab 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -175,11 +175,11 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
   // FIXME: We should de-allocate MostRecentTU
   for (Decl *D : MostRecentTU->decls()) {
 auto *ND = dyn_cast(D);
-if (!ND)
+if (!ND || ND->getDeclName().isEmpty()) 
   continue;
 // Check if we need to clean up the IdResolver chain.
-if (!ND->getDeclName().isEmpty() && ND->getDeclName().getFETokenInfo() &&
-!D->getLangOpts().ObjC && !D->getLangOpts().CPlusPlus)
+if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
+!D->getLangOpts().CPlusPlus)
   S.IdResolver.RemoveDecl(ND);
   }
 }

>From dae6ca63f0d443a6ec0df12e1abef183203c12de Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Tue, 11 Mar 2025 11:29:32 +0530
Subject: [PATCH 3/5] Add tests in lambda.cpp

---
 clang/test/Interpreter/lambda.cpp   | 11 +--
 clang/unittests/Interpreter/InterpreterTest.cpp |  7 ---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index df75274a050b2..135f5fe604ae5 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify | FileCheck %s
+
 extern "C" int printf(const char *, ...);
 
 auto l1 = []() { printf("ONE\n"); return 42; };
@@ -14,4 +15,10 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+auto capture = [&]() { return x * 2; };
+
+%quit
\ No newline at end of file
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 56ab155ebf5a4..578f1d4c0eac6 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -114,13 +114,6 @@ TEST_F(InterpreterTest, Errors) {
 
   RecoverErr = Interp->Parse("var1 = 424;");
   EXPECT_TRUE(!!RecoverErr);
-
-  Err = Interp->Parse("int x = 5; auto capture = [&]() { return x * 2; 
};").takeError();
-  EXPECT_THAT(DiagnosticOutput, HasSubstr("error: non-local lambda expression 
cannot ha

[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-03-10 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/127467

>From bd1b0b2a14afeb73755db3a7deb6bffd4f50778c Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Mon, 17 Feb 2025 15:33:20 +0530
Subject: [PATCH] Fix error recovery while PTU cleanup

---
 clang/lib/Interpreter/IncrementalParser.cpp |  2 +-
 clang/test/Interpreter/lambda.cpp   | 11 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 41d6304bd5f65..6343f17ed822a 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -176,7 +176,7 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
   // FIXME: We should de-allocate MostRecentTU
   for (Decl *D : MostRecentTU->decls()) {
 auto *ND = dyn_cast(D);
-if (!ND)
+if (!ND || ND->getDeclName().isEmpty())
   continue;
 // Check if we need to clean up the IdResolver chain.
 if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index df75274a050b2..8f49f870fddb6 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck 
%s
+
 extern "C" int printf(const char *, ...);
 
 auto l1 = []() { printf("ONE\n"); return 42; };
@@ -14,4 +15,10 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+auto capture = [&]() { return x * 2; };
+
+%quit
\ No newline at end of file

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-03-10 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/127467

>From 6ff448ed506e0ef75db2c9974a628a965e85df2f Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Mon, 17 Feb 2025 15:33:20 +0530
Subject: [PATCH 1/4] Fix error recovery while PTU cleanup

---
 clang/lib/Interpreter/IncrementalParser.cpp | 4 ++--
 clang/unittests/Interpreter/InterpreterTest.cpp | 7 +++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index e43cea1baf43a..1ebef0e434b3d 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -178,8 +178,8 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
 if (!ND)
   continue;
 // Check if we need to clean up the IdResolver chain.
-if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
-!D->getLangOpts().CPlusPlus)
+if (!ND->getDeclName().isEmpty() && ND->getDeclName().getFETokenInfo() &&
+!D->getLangOpts().ObjC && !D->getLangOpts().CPlusPlus)
   S.IdResolver.RemoveDecl(ND);
   }
 }
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 578f1d4c0eac6..56ab155ebf5a4 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -114,6 +114,13 @@ TEST_F(InterpreterTest, Errors) {
 
   RecoverErr = Interp->Parse("var1 = 424;");
   EXPECT_TRUE(!!RecoverErr);
+
+  Err = Interp->Parse("int x = 5; auto capture = [&]() { return x * 2; 
};").takeError();
+  EXPECT_THAT(DiagnosticOutput, HasSubstr("error: non-local lambda expression 
cannot have a capture-default"));
+  EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
+
+  RecoverErr = Interp->Parse("int validVar = 10;");
+  EXPECT_TRUE(!!RecoverErr);
 }
 
 // Here we test whether the user can mix declarations and statements. The

>From 8b9a112721c45662374fd9995af6da4031507c89 Mon Sep 17 00:00:00 2001
From: Anutosh Bhat 
Date: Wed, 26 Feb 2025 16:55:31 +0530
Subject: [PATCH 2/4] Update IncrementalParser.cpp

---
 clang/lib/Interpreter/IncrementalParser.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 1ebef0e434b3d..774219d9fc9ab 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -175,11 +175,11 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
   // FIXME: We should de-allocate MostRecentTU
   for (Decl *D : MostRecentTU->decls()) {
 auto *ND = dyn_cast(D);
-if (!ND)
+if (!ND || ND->getDeclName().isEmpty()) 
   continue;
 // Check if we need to clean up the IdResolver chain.
-if (!ND->getDeclName().isEmpty() && ND->getDeclName().getFETokenInfo() &&
-!D->getLangOpts().ObjC && !D->getLangOpts().CPlusPlus)
+if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
+!D->getLangOpts().CPlusPlus)
   S.IdResolver.RemoveDecl(ND);
   }
 }

>From dae6ca63f0d443a6ec0df12e1abef183203c12de Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Tue, 11 Mar 2025 11:29:32 +0530
Subject: [PATCH 3/4] Add tests in lambda.cpp

---
 clang/test/Interpreter/lambda.cpp   | 11 +--
 clang/unittests/Interpreter/InterpreterTest.cpp |  7 ---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index df75274a050b2..135f5fe604ae5 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify | FileCheck %s
+
 extern "C" int printf(const char *, ...);
 
 auto l1 = []() { printf("ONE\n"); return 42; };
@@ -14,4 +15,10 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+auto capture = [&]() { return x * 2; };
+
+%quit
\ No newline at end of file
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 56ab155ebf5a4..578f1d4c0eac6 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -114,13 +114,6 @@ TEST_F(InterpreterTest, Errors) {
 
   RecoverErr = Interp->Parse("var1 = 424;");
   EXPECT_TRUE(!!RecoverErr);
-
-  Err = Interp->Parse("int x = 5; auto capture = [&]() { return x * 2; 
};").takeError();
-  EXPECT_THAT(DiagnosticOutput, HasSubstr("error: non-local lambda expression 
cannot ha

[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-03-10 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/127467

>From 6ff448ed506e0ef75db2c9974a628a965e85df2f Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Mon, 17 Feb 2025 15:33:20 +0530
Subject: [PATCH 1/3] Fix error recovery while PTU cleanup

---
 clang/lib/Interpreter/IncrementalParser.cpp | 4 ++--
 clang/unittests/Interpreter/InterpreterTest.cpp | 7 +++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index e43cea1baf43a..1ebef0e434b3d 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -178,8 +178,8 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
 if (!ND)
   continue;
 // Check if we need to clean up the IdResolver chain.
-if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
-!D->getLangOpts().CPlusPlus)
+if (!ND->getDeclName().isEmpty() && ND->getDeclName().getFETokenInfo() &&
+!D->getLangOpts().ObjC && !D->getLangOpts().CPlusPlus)
   S.IdResolver.RemoveDecl(ND);
   }
 }
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 578f1d4c0eac6..56ab155ebf5a4 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -114,6 +114,13 @@ TEST_F(InterpreterTest, Errors) {
 
   RecoverErr = Interp->Parse("var1 = 424;");
   EXPECT_TRUE(!!RecoverErr);
+
+  Err = Interp->Parse("int x = 5; auto capture = [&]() { return x * 2; 
};").takeError();
+  EXPECT_THAT(DiagnosticOutput, HasSubstr("error: non-local lambda expression 
cannot have a capture-default"));
+  EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
+
+  RecoverErr = Interp->Parse("int validVar = 10;");
+  EXPECT_TRUE(!!RecoverErr);
 }
 
 // Here we test whether the user can mix declarations and statements. The

>From 8b9a112721c45662374fd9995af6da4031507c89 Mon Sep 17 00:00:00 2001
From: Anutosh Bhat 
Date: Wed, 26 Feb 2025 16:55:31 +0530
Subject: [PATCH 2/3] Update IncrementalParser.cpp

---
 clang/lib/Interpreter/IncrementalParser.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 1ebef0e434b3d..774219d9fc9ab 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -175,11 +175,11 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
   // FIXME: We should de-allocate MostRecentTU
   for (Decl *D : MostRecentTU->decls()) {
 auto *ND = dyn_cast(D);
-if (!ND)
+if (!ND || ND->getDeclName().isEmpty()) 
   continue;
 // Check if we need to clean up the IdResolver chain.
-if (!ND->getDeclName().isEmpty() && ND->getDeclName().getFETokenInfo() &&
-!D->getLangOpts().ObjC && !D->getLangOpts().CPlusPlus)
+if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
+!D->getLangOpts().CPlusPlus)
   S.IdResolver.RemoveDecl(ND);
   }
 }

>From dae6ca63f0d443a6ec0df12e1abef183203c12de Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Tue, 11 Mar 2025 11:29:32 +0530
Subject: [PATCH 3/3] Add tests in lambda.cpp

---
 clang/test/Interpreter/lambda.cpp   | 11 +--
 clang/unittests/Interpreter/InterpreterTest.cpp |  7 ---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index df75274a050b2..135f5fe604ae5 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify | FileCheck %s
+
 extern "C" int printf(const char *, ...);
 
 auto l1 = []() { printf("ONE\n"); return 42; };
@@ -14,4 +15,10 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+auto capture = [&]() { return x * 2; };
+
+%quit
\ No newline at end of file
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 56ab155ebf5a4..578f1d4c0eac6 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -114,13 +114,6 @@ TEST_F(InterpreterTest, Errors) {
 
   RecoverErr = Interp->Parse("var1 = 424;");
   EXPECT_TRUE(!!RecoverErr);
-
-  Err = Interp->Parse("int x = 5; auto capture = [&]() { return x * 2; 
};").takeError();
-  EXPECT_THAT(DiagnosticOutput, HasSubstr("error: non-local lambda expression 
cannot ha

[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-03-10 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/127467

>From 6ff448ed506e0ef75db2c9974a628a965e85df2f Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Mon, 17 Feb 2025 15:33:20 +0530
Subject: [PATCH 1/3] Fix error recovery while PTU cleanup

---
 clang/lib/Interpreter/IncrementalParser.cpp | 4 ++--
 clang/unittests/Interpreter/InterpreterTest.cpp | 7 +++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index e43cea1baf43a..1ebef0e434b3d 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -178,8 +178,8 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
 if (!ND)
   continue;
 // Check if we need to clean up the IdResolver chain.
-if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
-!D->getLangOpts().CPlusPlus)
+if (!ND->getDeclName().isEmpty() && ND->getDeclName().getFETokenInfo() &&
+!D->getLangOpts().ObjC && !D->getLangOpts().CPlusPlus)
   S.IdResolver.RemoveDecl(ND);
   }
 }
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 578f1d4c0eac6..56ab155ebf5a4 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -114,6 +114,13 @@ TEST_F(InterpreterTest, Errors) {
 
   RecoverErr = Interp->Parse("var1 = 424;");
   EXPECT_TRUE(!!RecoverErr);
+
+  Err = Interp->Parse("int x = 5; auto capture = [&]() { return x * 2; 
};").takeError();
+  EXPECT_THAT(DiagnosticOutput, HasSubstr("error: non-local lambda expression 
cannot have a capture-default"));
+  EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
+
+  RecoverErr = Interp->Parse("int validVar = 10;");
+  EXPECT_TRUE(!!RecoverErr);
 }
 
 // Here we test whether the user can mix declarations and statements. The

>From 8b9a112721c45662374fd9995af6da4031507c89 Mon Sep 17 00:00:00 2001
From: Anutosh Bhat 
Date: Wed, 26 Feb 2025 16:55:31 +0530
Subject: [PATCH 2/3] Update IncrementalParser.cpp

---
 clang/lib/Interpreter/IncrementalParser.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 1ebef0e434b3d..774219d9fc9ab 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -175,11 +175,11 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
   // FIXME: We should de-allocate MostRecentTU
   for (Decl *D : MostRecentTU->decls()) {
 auto *ND = dyn_cast(D);
-if (!ND)
+if (!ND || ND->getDeclName().isEmpty()) 
   continue;
 // Check if we need to clean up the IdResolver chain.
-if (!ND->getDeclName().isEmpty() && ND->getDeclName().getFETokenInfo() &&
-!D->getLangOpts().ObjC && !D->getLangOpts().CPlusPlus)
+if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
+!D->getLangOpts().CPlusPlus)
   S.IdResolver.RemoveDecl(ND);
   }
 }

>From dae6ca63f0d443a6ec0df12e1abef183203c12de Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Tue, 11 Mar 2025 11:29:32 +0530
Subject: [PATCH 3/3] Add tests in lambda.cpp

---
 clang/test/Interpreter/lambda.cpp   | 11 +--
 clang/unittests/Interpreter/InterpreterTest.cpp |  7 ---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index df75274a050b2..135f5fe604ae5 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,7 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify | FileCheck %s
+
 extern "C" int printf(const char *, ...);
 
 auto l1 = []() { printf("ONE\n"); return 42; };
@@ -14,4 +15,10 @@ auto r2 = l2();
 auto r3 = l2();
 // CHECK: TWO
 
-%quit
+// Verify non-local lambda capture error is correctly reported
+int x = 42;
+
+// expected-error@+1 {{non-local lambda expression cannot have a 
capture-default}}
+auto capture = [&]() { return x * 2; };
+
+%quit
\ No newline at end of file
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 56ab155ebf5a4..578f1d4c0eac6 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -114,13 +114,6 @@ TEST_F(InterpreterTest, Errors) {
 
   RecoverErr = Interp->Parse("var1 = 424;");
   EXPECT_TRUE(!!RecoverErr);
-
-  Err = Interp->Parse("int x = 5; auto capture = [&]() { return x * 2; 
};").takeError();
-  EXPECT_THAT(DiagnosticOutput, HasSubstr("error: non-local lambda expression 
cannot ha

[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-02-26 Thread Anutosh Bhat via cfe-commits


@@ -114,6 +114,13 @@ TEST_F(InterpreterTest, Errors) {
 
   RecoverErr = Interp->Parse("var1 = 424;");
   EXPECT_TRUE(!!RecoverErr);
+
+  Err = Interp->Parse("int x = 5; auto capture = [&]() { return x * 2; 
};").takeError();

anutosh491 wrote:

Shall shift it there if that's what is needed 

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-02-26 Thread Anutosh Bhat via cfe-commits


@@ -114,6 +114,13 @@ TEST_F(InterpreterTest, Errors) {
 
   RecoverErr = Interp->Parse("var1 = 424;");
   EXPECT_TRUE(!!RecoverErr);
+
+  Err = Interp->Parse("int x = 5; auto capture = [&]() { return x * 2; 
};").takeError();

anutosh491 wrote:

I meant I see quite some error recovery stuff being added in this place hence I 
added it here !

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-02-26 Thread Vassil Vassilev via cfe-commits


@@ -114,6 +114,13 @@ TEST_F(InterpreterTest, Errors) {
 
   RecoverErr = Interp->Parse("var1 = 424;");
   EXPECT_TRUE(!!RecoverErr);
+
+  Err = Interp->Parse("int x = 5; auto capture = [&]() { return x * 2; 
};").takeError();

vgvassilev wrote:

There is no such a distinction in the test suite.

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-02-26 Thread Anutosh Bhat via cfe-commits


@@ -114,6 +114,13 @@ TEST_F(InterpreterTest, Errors) {
 
   RecoverErr = Interp->Parse("var1 = 424;");
   EXPECT_TRUE(!!RecoverErr);
+
+  Err = Interp->Parse("int x = 5; auto capture = [&]() { return x * 2; 
};").takeError();

anutosh491 wrote:

Hmmm @vgvassilev 

Don't you think we should look at this from an error recovery perspective 
rather than something for lambdas ? If that's the case, the test is placed 
correctly.

The above test cause clang-repl to crash but should work if wrapped in a 
function or not presented as a top level decl.

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-02-26 Thread Vassil Vassilev via cfe-commits


@@ -114,6 +114,13 @@ TEST_F(InterpreterTest, Errors) {
 
   RecoverErr = Interp->Parse("var1 = 424;");
   EXPECT_TRUE(!!RecoverErr);
+
+  Err = Interp->Parse("int x = 5; auto capture = [&]() { return x * 2; 
};").takeError();

vgvassilev wrote:

Can we move this test perhaps somewhere in `test/Interpreter/lambda.cpp`?

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-02-26 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/127467

>From 6ff448ed506e0ef75db2c9974a628a965e85df2f Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Mon, 17 Feb 2025 15:33:20 +0530
Subject: [PATCH 1/2] Fix error recovery while PTU cleanup

---
 clang/lib/Interpreter/IncrementalParser.cpp | 4 ++--
 clang/unittests/Interpreter/InterpreterTest.cpp | 7 +++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index e43cea1baf43a..1ebef0e434b3d 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -178,8 +178,8 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
 if (!ND)
   continue;
 // Check if we need to clean up the IdResolver chain.
-if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
-!D->getLangOpts().CPlusPlus)
+if (!ND->getDeclName().isEmpty() && ND->getDeclName().getFETokenInfo() &&
+!D->getLangOpts().ObjC && !D->getLangOpts().CPlusPlus)
   S.IdResolver.RemoveDecl(ND);
   }
 }
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 578f1d4c0eac6..56ab155ebf5a4 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -114,6 +114,13 @@ TEST_F(InterpreterTest, Errors) {
 
   RecoverErr = Interp->Parse("var1 = 424;");
   EXPECT_TRUE(!!RecoverErr);
+
+  Err = Interp->Parse("int x = 5; auto capture = [&]() { return x * 2; 
};").takeError();
+  EXPECT_THAT(DiagnosticOutput, HasSubstr("error: non-local lambda expression 
cannot have a capture-default"));
+  EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
+
+  RecoverErr = Interp->Parse("int validVar = 10;");
+  EXPECT_TRUE(!!RecoverErr);
 }
 
 // Here we test whether the user can mix declarations and statements. The

>From 8b9a112721c45662374fd9995af6da4031507c89 Mon Sep 17 00:00:00 2001
From: Anutosh Bhat 
Date: Wed, 26 Feb 2025 16:55:31 +0530
Subject: [PATCH 2/2] Update IncrementalParser.cpp

---
 clang/lib/Interpreter/IncrementalParser.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 1ebef0e434b3d..774219d9fc9ab 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -175,11 +175,11 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
   // FIXME: We should de-allocate MostRecentTU
   for (Decl *D : MostRecentTU->decls()) {
 auto *ND = dyn_cast(D);
-if (!ND)
+if (!ND || ND->getDeclName().isEmpty()) 
   continue;
 // Check if we need to clean up the IdResolver chain.
-if (!ND->getDeclName().isEmpty() && ND->getDeclName().getFETokenInfo() &&
-!D->getLangOpts().ObjC && !D->getLangOpts().CPlusPlus)
+if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
+!D->getLangOpts().CPlusPlus)
   S.IdResolver.RemoveDecl(ND);
   }
 }

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-02-26 Thread Vassil Vassilev via cfe-commits


@@ -178,8 +178,8 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl 
*MostRecentTU) {
 if (!ND)
   continue;
 // Check if we need to clean up the IdResolver chain.
-if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
-!D->getLangOpts().CPlusPlus)
+if (!ND->getDeclName().isEmpty() && ND->getDeclName().getFETokenInfo() &&

vgvassilev wrote:

The `ND->getDeclName().isEmpty() ` needs to go in the `continue` clause.

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-02-26 Thread Anutosh Bhat via cfe-commits

anutosh491 wrote:

cc @vgvassilev 

https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)

2025-02-17 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 edited 
https://github.com/llvm/llvm-project/pull/127467
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits