[clang] [clang-repl] Fix error recovery while PTU cleanup (PR #127467)
Anutosh Bhat via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 10 23:24:36 PDT 2025
https://github.com/anutosh491 updated https://github.com/llvm/llvm-project/pull/127467
>From bd1b0b2a14afeb73755db3a7deb6bffd4f50778c Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
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<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 at +1 {{non-local lambda expression cannot have a capture-default}}
+auto capture = [&]() { return x * 2; };
+
+%quit
\ No newline at end of file
More information about the cfe-commits
mailing list