From 5397d5d582f664cd9665b38886d90fbd9c076c02 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Fri, 6 Jun 2025 17:17:00 +0100 Subject: [PATCH] [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. (cherry picked from commit 30f524090542d07067234c292c15d4a4129b4aea) --- .../Clang/ClangModulesDeclVendor.cpp | 7 +++++++ .../decl-from-submodule/TestDeclFromSubmodule.py | 14 ++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp index 264437bc2e846..dafa3160d9987 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp @@ -379,6 +379,13 @@ bool ClangModulesDeclVendorImpl::AddModule(const SourceModule &module, } } + // If we didn't make the submodule visible here, Clang wouldn't allow LLDB to + // pick any of the decls in the submodules during C++ name lookup. + if (submodule) + m_compiler_instance->makeModuleVisible( + submodule, clang::Module::NameVisibilityKind::AllVisible, + /*ImportLoc=*/{}); + clang::Module *requested_module = DoGetModule(clang_path, true); if (requested_module != nullptr) { diff --git a/lldb/test/API/lang/cpp/decl-from-submodule/TestDeclFromSubmodule.py b/lldb/test/API/lang/cpp/decl-from-submodule/TestDeclFromSubmodule.py index f200e51c7f794..d044ad46637fe 100644 --- a/lldb/test/API/lang/cpp/decl-from-submodule/TestDeclFromSubmodule.py +++ b/lldb/test/API/lang/cpp/decl-from-submodule/TestDeclFromSubmodule.py @@ -11,17 +11,11 @@ class DeclFromSubmoduleTestCase(TestBase): # Requires DWARF debug info which is not retained when linking with link.exe. @skipIfWindows + # Lookup for decls in submodules fails in Linux + @expectedFailureAll(oslist=["linux"]) def test_expr(self): self.build() lldbutil.run_to_source_breakpoint(self, "return 0", lldb.SBFileSpec("main.cpp")) - # FIXME: LLDB finds the decl for 'func' in the submodules correctly and hands it to Clang - # but Sema rejects using the decl during name lookup because it is not marked "Visible". - # However, this assertions still ensures that we at least don't fail to compile the - # submodule (which would cause other errors to appear before the expression error, hence - # we use "startstr"). - self.expect( - "expr func(1, 2)", - error=True, - startstr="error: :1:1: 'func' has unknown return type", - ) + self.expect_expr("func(1, 2)", result_type="int", result_value="3") + self.expect_expr("func(1)", result_type="int", result_value="1")