-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lldb][ClangASTImporter] Don't ASTImport LambdaExpr nodes #154962
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) ChangesWorks around #149477 Full diff: https://github.com/llvm/llvm-project/pull/154962.diff 2 Files Affected:
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
index 08e2d0f1b4011..92094c01e2a54 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -1048,6 +1048,16 @@ ClangASTImporter::MapCompleter::~MapCompleter() = default;
llvm::Expected<Decl *>
ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl *From) {
+ // FIXME: The Minimal import mode of clang::ASTImporter does not correctly
+ // import Lambda definitions. Work around this for now by not importing
+ // lambdas at all. This is most likely encountered when importing decls from
+ // the `std` module (not from debug-info), where lambdas can be defined in
+ // inline function bodies. Those will be imported by LLDB.
+ if (const auto *CXX = llvm::dyn_cast<clang::CXXRecordDecl>(From))
+ if (CXX->isLambda())
+ return llvm::make_error<ASTImportError>(
+ ASTImportError::UnsupportedConstruct);
+
if (m_std_handler) {
std::optional<Decl *> D = m_std_handler->Import(From);
if (D) {
diff --git a/lldb/test/Shell/Expr/TestLambdaExprImport.test b/lldb/test/Shell/Expr/TestLambdaExprImport.test
new file mode 100644
index 0000000000000..c57ce06453fe2
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestLambdaExprImport.test
@@ -0,0 +1,26 @@
+# Test that we can successfully ASTImport clang::LambdaExpr nodes.
+# Currently this is not supported in MinimalImport mode (which LLDB
+# uses always).
+
+# RUN: split-file %s %t
+# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.out
+# RUN: %lldb -o "settings set interpreter.stop-command-source-on-error false" \
+# RUN: -x -b -s %t/commands.input %t.out 2>&1 \
+# RUN: | FileCheck %s
+
+#--- main.cpp
+
+int main() {
+ __builtin_debugtrap();
+}
+
+#--- commands.input
+
+run
+expression --top-level -- void method(int x) { [x=x] { ; }; }
+target dump typesystem
+
+# CHECK: expression
+# CHECK: target dump typesystem
+# CHECK-NOT: FunctionDecl
+# CHECK-NOT: LambdaExpr
|
adrian-prantl
approved these changes
Aug 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fit unbreaks the test suite, let's do this for now.
tru
pushed a commit
to llvmbot/llvm-project
that referenced
this pull request
Sep 8, 2025
This patch works around an assertion that we hit in the `LambdaExpr` constructor when we call it from `ASTNodeImporter::VisitLambdaExpr` (see llvm#149477). The lambda that we imported doesn't have the `NumCaptures` field accurately set to the one on the source decl. This is because in `MinimalImport` mode, we skip importing of lambda definitions: https://github.com/llvm/llvm-project/blob/e21b0dd81928a3266df0e3ede008fb7a6676ff95/clang/lib/AST/ASTImporter.cpp#L2499 In practice we have seen this assertion occur in our `import-std-module` test-suite when libc++ headers decide to use lambdas inside inline function bodies (the latest failure being caused by llvm#144602). To avoid running into this whenever libc++ decides to use lambdas in headers, this patch skips `ASTImport` of lambdas alltogether. Ideally this would bubble up to the user or log as an error, but we swallow the `ASTImportError`s currently. The only way this codepath is hit is when lambdas are used inside functions in defined in the expression evaluator, or when importing AST nodes from Clang modules. Both of these are very niche use-cases (for now), so a workaround seemed appropriate. (cherry picked from commit 0bbb794)
Michael137
added a commit
to swiftlang/llvm-project
that referenced
this pull request
Sep 23, 2025
This patch works around an assertion that we hit in the `LambdaExpr` constructor when we call it from `ASTNodeImporter::VisitLambdaExpr` (see llvm#149477). The lambda that we imported doesn't have the `NumCaptures` field accurately set to the one on the source decl. This is because in `MinimalImport` mode, we skip importing of lambda definitions: https://github.com/llvm/llvm-project/blob/e21b0dd81928a3266df0e3ede008fb7a6676ff95/clang/lib/AST/ASTImporter.cpp#L2499 In practice we have seen this assertion occur in our `import-std-module` test-suite when libc++ headers decide to use lambdas inside inline function bodies (the latest failure being caused by llvm#144602). To avoid running into this whenever libc++ decides to use lambdas in headers, this patch skips `ASTImport` of lambdas alltogether. Ideally this would bubble up to the user or log as an error, but we swallow the `ASTImportError`s currently. The only way this codepath is hit is when lambdas are used inside functions in defined in the expression evaluator, or when importing AST nodes from Clang modules. Both of these are very niche use-cases (for now), so a workaround seemed appropriate. (cherry picked from commit 0bbb794)
adrian-prantl
added a commit
to swiftlang/llvm-project
that referenced
this pull request
Sep 29, 2025
[lldb][ClangASTImporter] Don't ASTImport LambdaExpr nodes (llvm#154962)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch works around an assertion that we hit in the
LambdaExpr
constructor when we call it fromASTNodeImporter::VisitLambdaExpr
(see #149477). The lambda that we imported doesn't have theNumCaptures
field accurately set to the one on the source decl. This is because inMinimalImport
mode, we skip importing of lambda definitions:llvm-project/clang/lib/AST/ASTImporter.cpp
Line 2499 in e21b0dd
In practice we have seen this assertion occur in our
import-std-module
test-suite when libc++ headers decide to use lambdas inside inline function bodies (the latest failure being caused by #144602).To avoid running into this whenever libc++ decides to use lambdas in headers, this patch skips
ASTImport
of lambdas alltogether. Ideally this would bubble up to the user or log as an error, but we swallow theASTImportError
s currently. The only way this codepath is hit is when lambdas are used inside functions in defined in the expression evaluator, or when importing AST nodes from Clang modules. Both of these are very niche use-cases (for now), so a workaround seemed appropriate.