https://github.com/anutosh491 updated https://github.com/llvm/llvm-project/pull/127467
>From bd1b0b2a14afeb73755db3a7deb6bffd4f50778c Mon Sep 17 00:00:00 2001 From: anutosh491 <andersonbhat...@gmail.com> 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<NamedDecl>(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 <andersonbhat...@gmail.com> 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 <andersonbhat...@gmail.com> 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 <andersonbhat...@gmail.com> 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 cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits