Skip to content

Commit 30f5240

Browse files
authored
[lldb][Modules] Make decls from submodules visible for name lookup (#143098)
This patch ensures we can find decls in submodules during expression evaluation. Previously, submodules would have all their decls marked as `Hidden`. When Clang asked LLDB for decls, it would see them in the submodule but `clang::Sema` would reject them because they weren't `Visible` (specifically, `getAcceptableDecl` would fail during `CppNameLookup`). Here we just mark the submodule as visible to work around this problem.
1 parent 1eb843b commit 30f5240

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@ bool ClangModulesDeclVendorImpl::AddModule(const SourceModule &module,
382382
}
383383
}
384384

385+
// If we didn't make the submodule visible here, Clang wouldn't allow LLDB to
386+
// pick any of the decls in the submodules during C++ name lookup.
387+
if (submodule)
388+
m_compiler_instance->makeModuleVisible(
389+
submodule, clang::Module::NameVisibilityKind::AllVisible,
390+
/*ImportLoc=*/{});
391+
385392
clang::Module *requested_module = DoGetModule(clang_path, true);
386393

387394
if (requested_module != nullptr) {

lldb/test/API/lang/cpp/decl-from-submodule/TestDeclFromSubmodule.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,11 @@
1111
class DeclFromSubmoduleTestCase(TestBase):
1212
# Requires DWARF debug info which is not retained when linking with link.exe.
1313
@skipIfWindows
14+
# Lookup for decls in submodules fails in Linux
15+
@expectedFailureAll(oslist=["linux"])
1416
def test_expr(self):
1517
self.build()
1618
lldbutil.run_to_source_breakpoint(self, "return 0", lldb.SBFileSpec("main.cpp"))
1719

18-
# FIXME: LLDB finds the decl for 'func' in the submodules correctly and hands it to Clang
19-
# but Sema rejects using the decl during name lookup because it is not marked "Visible".
20-
# However, this assertions still ensures that we at least don't fail to compile the
21-
# submodule (which would cause other errors to appear before the expression error, hence
22-
# we use "startstr").
23-
self.expect(
24-
"expr func(1, 2)",
25-
error=True,
26-
startstr="error: <user expression 0>:1:1: 'func' has unknown return type",
27-
)
20+
self.expect_expr("func(1, 2)", result_type="int", result_value="3")
21+
self.expect_expr("func(1)", result_type="int", result_value="1")

0 commit comments

Comments
 (0)