Skip to content

Commit c45eced

Browse files
committed
[lldb][ClangASTImporter] Don't ASTImport LambdaExpr nodes (llvm#154962)
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)
1 parent 66efdf7 commit c45eced

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,16 @@ ClangASTImporter::MapCompleter::~MapCompleter() = default;
10601060

10611061
llvm::Expected<Decl *>
10621062
ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl *From) {
1063+
// FIXME: The Minimal import mode of clang::ASTImporter does not correctly
1064+
// import Lambda definitions. Work around this for now by not importing
1065+
// lambdas at all. This is most likely encountered when importing decls from
1066+
// the `std` module (not from debug-info), where lambdas can be defined in
1067+
// inline function bodies. Those will be imported by LLDB.
1068+
if (const auto *CXX = llvm::dyn_cast<clang::CXXRecordDecl>(From))
1069+
if (CXX->isLambda())
1070+
return llvm::make_error<ASTImportError>(
1071+
ASTImportError::UnsupportedConstruct);
1072+
10631073
if (m_std_handler) {
10641074
std::optional<Decl *> D = m_std_handler->Import(From);
10651075
if (D) {
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
from lldbsuite.test import lldbinline
22
from lldbsuite.test import decorators
33

4-
lldbinline.MakeInlineTest(__file__, globals())
4+
lldbinline.MakeInlineTest(
5+
__file__,
6+
globals(),
7+
[
8+
decorators.expectedFailureAll(
9+
bugnumber="https://github.com/llvm/llvm-project/issues/149477"
10+
)
11+
],
12+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Test that we can successfully ASTImport clang::LambdaExpr nodes.
2+
# Currently this is not supported in MinimalImport mode (which LLDB
3+
# uses always).
4+
5+
# RUN: split-file %s %t
6+
# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.out
7+
# RUN: %lldb -o "settings set interpreter.stop-command-source-on-error false" \
8+
# RUN: -x -b -s %t/commands.input %t.out 2>&1 \
9+
# RUN: | FileCheck %s
10+
11+
#--- main.cpp
12+
13+
int main() {
14+
__builtin_debugtrap();
15+
}
16+
17+
#--- commands.input
18+
19+
run
20+
expression --top-level -- void method(int x) { [x=x] { ; }; }
21+
target dump typesystem
22+
23+
# CHECK: expression
24+
# CHECK: target dump typesystem
25+
# CHECK-NOT: FunctionDecl
26+
# CHECK-NOT: LambdaExpr

0 commit comments

Comments
 (0)