[Lldb-commits] [lldb] 09f608f - [lldb][ClangExpression] Remove storage-class check when creating AsmLabel

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 22 05:28:04 PDT 2022


Author: Michael Buch
Date: 2022-08-22T13:22:20+01:00
New Revision: 09f608fda51ca9dd2d88c2985bad1cfc1e36251e

URL: https://github.com/llvm/llvm-project/commit/09f608fda51ca9dd2d88c2985bad1cfc1e36251e
DIFF: https://github.com/llvm/llvm-project/commit/09f608fda51ca9dd2d88c2985bad1cfc1e36251e.diff

LOG: [lldb][ClangExpression] Remove storage-class check when creating AsmLabel

This check was put in place to prevent static functions
from translation units outside the one that the current
expression is evaluated from taking precedence over functions
in the global namespace. However, this is really a different
bug. LLDB lumps functions from all CUs into a single AST and
ends up picking the file-static even when C++ context rules
wouldn't allow that to happen.

This patch removes the check so we apply the AsmLabel to all
FunctionDecls we create from DWARF if we have a linkage name
available. This makes the code-path easier to reason about and
allows calling static functions in contexts where we previously
would've chosen the wrong function.

We also flip the XFAILs in the API test to reflect what effect
this change has.

**Testing**

* Fixed API tests and added XFAIL

Differential Revision: https://reviews.llvm.org/D132231

Added: 
    

Modified: 
    lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
    lldb/test/API/lang/cpp/namespace/TestNamespaceLookup.py

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index fda68f289a397..9fe9b2e25a2f8 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1258,7 +1258,7 @@ TypeSP DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,
           // example is generating calls to ABI-tagged template functions.
           // This is done separately for member functions in
           // AddMethodToCXXRecordType.
-          if (attrs.mangled_name && attrs.storage == clang::SC_Extern)
+          if (attrs.mangled_name)
             function_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(
                 m_ast.getASTContext(), attrs.mangled_name, /*literal=*/false));
 

diff  --git a/lldb/test/API/lang/cpp/namespace/TestNamespaceLookup.py b/lldb/test/API/lang/cpp/namespace/TestNamespaceLookup.py
index cf33919855d8c..789b33c87256e 100644
--- a/lldb/test/API/lang/cpp/namespace/TestNamespaceLookup.py
+++ b/lldb/test/API/lang/cpp/namespace/TestNamespaceLookup.py
@@ -36,6 +36,55 @@ def runToBkpt(self, command):
                     substrs=['stopped',
                              'stop reason = breakpoint'])
 
+    @skipIfWindows # This is flakey on Windows: llvm.org/pr38373
+    @expectedFailure("CU-local objects incorrectly scoped")
+    def test_scope_lookup_with_run_command_globals(self):
+        """Test scope lookup of functions in lldb."""
+        self.build()
+
+        lldbutil.run_to_source_breakpoint(
+                self,
+                self.line_break_global_scope,
+                lldb.SBFileSpec("ns.cpp"))
+
+        lldbutil.run_break_set_by_file_and_line(
+            self,
+            "ns3.cpp",
+            self.line_break_before_using_directive,
+            num_expected_locations=1,
+            loc_exact=False)
+
+        # Run to BP_global_scope at file scope
+        self.runToBkpt("run")
+
+        # FIXME: LLDB does not correctly scope CU-local objects.
+        # LLDB currently lumps functions from all files into
+        # a single AST and depending on the order with which
+        # functions are considered, LLDB can incorrectly call
+        # the static local ns.cpp::func() instead of the expected
+        # ::func()
+
+        # Evaluate func() - should call ::func()
+        self.expect_expr("func()", expect_type="int", expect_value="1")
+
+        # Evaluate ::func() - should call A::func()
+        self.expect_expr("::func()", result_type="int", result_value="1")
+
+        # Continue to BP_before_using_directive at file scope
+        self.runToBkpt("continue")
+
+        # Evaluate func() - should call ::func()
+        self.expect_expr("func()", result_type="int", result_value="1")
+
+        # Evaluate ::func() - should call ::func()
+        self.expect_expr("::func()", result_type="int", result_value="1")
+
+        # Continue to BP_after_using_directive at file scope
+        self.runToBkpt("continue")
+
+        # Evaluate ::func() - should call ::func()
+        self.expect_expr("::func()", result_type="int", result_value="1")
+
     @skipIfWindows # This is flakey on Windows: llvm.org/pr38373
     def test_scope_lookup_with_run_command(self):
         """Test scope lookup of functions in lldb."""
@@ -66,6 +115,12 @@ def test_scope_lookup_with_run_command(self):
             self.line_break_nested_ns_scope_after_using,
             num_expected_locations=1,
             loc_exact=False)
+        lldbutil.run_break_set_by_file_and_line(
+            self,
+            "ns2.cpp",
+            self.line_break_file_scope,
+            num_expected_locations=1,
+            loc_exact=False)
         lldbutil.run_break_set_by_file_and_line(
             self,
             "ns3.cpp",
@@ -81,17 +136,18 @@ def test_scope_lookup_with_run_command(self):
 
         # Run to BP_global_scope at global scope
         self.runToBkpt("run")
-        # Evaluate func() - should call ::func()
-        self.expect_expr("func()", result_type="int", result_value="1")
+
         # Evaluate A::B::func() - should call A::B::func()
         self.expect_expr("A::B::func()", result_type="int", result_value="4")
         # Evaluate func(10) - should call ::func(int)
         self.expect_expr("func(10)", result_type="int", result_value="11")
-        # Evaluate ::func() - should call A::func()
-        self.expect_expr("::func()", result_type="int", result_value="1")
         # Evaluate A::foo() - should call A::foo()
         self.expect_expr("A::foo()", result_type="int", result_value="42")
 
+        # Continue to BP_file_scope at file scope
+        self.runToBkpt("continue")
+        self.expect_expr("func()", result_type="int", result_value="2")
+
         # Continue to BP_ns_scope at ns scope
         self.runToBkpt("continue")
         # Evaluate func(10) - should call A::func(int)
@@ -124,16 +180,12 @@ def test_scope_lookup_with_run_command(self):
         # Continue to BP_before_using_directive at global scope before using
         # declaration
         self.runToBkpt("continue")
-        # Evaluate ::func() - should call ::func()
-        self.expect_expr("::func()", result_type="int", result_value="1")
         # Evaluate B::func() - should call B::func()
         self.expect_expr("B::func()", result_type="int", result_value="4")
 
         # Continue to BP_after_using_directive at global scope after using
         # declaration
         self.runToBkpt("continue")
-        # Evaluate ::func() - should call ::func()
-        self.expect_expr("::func()", result_type="int", result_value="1")
         # Evaluate B::func() - should call B::func()
         self.expect_expr("B::func()", result_type="int", result_value="4")
 
@@ -174,46 +226,6 @@ def test_function_scope_lookup_with_run_command(self):
         # before functions.
         self.expect_expr("foo()", result_type="int", result_value="42")
 
-    @expectedFailure("lldb file scope lookup bugs")
-    @skipIfWindows # This is flakey on Windows: llvm.org/pr38373
-    def test_file_scope_lookup_with_run_command(self):
-        """Test file scope lookup in lldb."""
-        self.build()
-        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
-
-        lldbutil.run_break_set_by_file_and_line(
-            self,
-            "ns2.cpp",
-            self.line_break_file_scope,
-            num_expected_locations=1,
-            loc_exact=False)
-
-        # Run to BP_file_scope at file scope
-        self.runToBkpt("run")
-        # Evaluate func() - should call static ns2.cpp:func()
-        # FIXME: This test fails because lldb doesn't know about file scopes so
-        # finds the global ::func().
-        self.expect_expr("func()", result_type="int", result_value="2")
-
-    @skipIfWindows # This is flakey on Windows: llvm.org/pr38373
-    def test_scope_lookup_before_using_with_run_command(self):
-        """Test scope lookup before using in lldb."""
-        self.build()
-        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
-
-        lldbutil.run_break_set_by_file_and_line(
-            self,
-            "ns3.cpp",
-            self.line_break_before_using_directive,
-            num_expected_locations=1,
-            loc_exact=False)
-
-        # Run to BP_before_using_directive at global scope before using
-        # declaration
-        self.runToBkpt("run")
-        # Evaluate func() - should call ::func()
-        self.expect_expr("func()", result_type="int", result_value="1")
-
     # NOTE: this test may fail on older systems that don't emit import
     # entries in DWARF - may need to add checks for compiler versions here.
     @skipIf(


        


More information about the lldb-commits mailing list