[Lldb-commits] [PATCH] D68130: [lldb] Don't emit artificial constructor declarations as global functions

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 27 05:07:54 PDT 2019


teemperor created this revision.
teemperor added reviewers: aprantl, vsk.
Herald added subscribers: lldb-commits, JDevlieghere.
Herald added a project: LLDB.

When we have a artificial constructor DIE, we currently create from that a global function with the name of that class.
That ends up causing a bunch of funny errors such as "must use 'struct' tag to refer to type 'Foo' in this scope" when
doing `Foo f`. Also causes that constructing a class via `Foo()` actually just calls that global function.

The fix is that when we have an artificial method decl, we always treat it as handled even if we don't create a CXXMethodDecl
for it (which we never do for artificial methods at the moment).

Fixes rdar://55757491 and probably some other radars.

Note that on non-macOS systems, calling functions etc. on temporary constructed objects like `Foo()` doesn't seem to work,
so that's why that one test only runs on Darwin. The generic test works on all platforms, so we still test this patch there.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D68130

Files:
  lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/TestCallOverriddenMethod.py
  lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/main.cpp
  lldb/packages/Python/lldbsuite/test/commands/expression/ignore-artificial-constructors/TestIgnoreArtificialConstructors.py
  lldb/packages/Python/lldbsuite/test/commands/expression/ignore-artificial-constructors/main.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp


Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1398,8 +1398,11 @@
                               is_attr_used, attrs.is_artificial);
 
                       type_handled = cxx_method_decl != NULL;
+                      // Artificial methods are always handled even when don't
+                      // create a new declaration for them.
+                      type_handled |= attrs.is_artificial;
 
-                      if (type_handled) {
+                      if (cxx_method_decl) {
                         LinkDeclContextToDIE(
                             ClangASTContext::GetAsDeclContext(cxx_method_decl),
                             die);
Index: lldb/packages/Python/lldbsuite/test/commands/expression/ignore-artificial-constructors/main.cpp
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/commands/expression/ignore-artificial-constructors/main.cpp
@@ -0,0 +1,8 @@
+struct Foo {
+  virtual ~Foo() = default;
+};
+
+int main() {
+  Foo f;
+  return 0; //%self.expect("expr Foo()", substrs=["(Foo) $0 = {}"])
+}
Index: lldb/packages/Python/lldbsuite/test/commands/expression/ignore-artificial-constructors/TestIgnoreArtificialConstructors.py
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/commands/expression/ignore-artificial-constructors/TestIgnoreArtificialConstructors.py
@@ -0,0 +1,4 @@
+from lldbsuite.test import lldbinline
+from lldbsuite.test import decorators
+
+lldbinline.MakeInlineTest(__file__, globals(), None)
Index: lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/main.cpp
===================================================================
--- lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/main.cpp
+++ lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/main.cpp
@@ -11,6 +11,7 @@
 
 int main() {
   Base realbase;
+  realbase.foo();
   Derived d;
   Base *b = &d;
   return 0; // Set breakpoint here
Index: lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/TestCallOverriddenMethod.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/TestCallOverriddenMethod.py
+++ lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/TestCallOverriddenMethod.py
@@ -49,3 +49,19 @@
 
         # Test calling the base class.
         self.expect("expr realbase.foo()", substrs=["1"])
+
+
+    @skipUnlessDarwin
+    def test_calling_temporaries(self):
+        """Test calls to overridden methods on locals"""
+        self.build()
+
+        # Set breakpoint in main and run exe
+        self.runCmd("file " + self.getBuildArtifact("a.out"),
+                    CURRENT_EXECUTABLE_SET)
+        lldbutil.run_break_set_by_file_and_line(
+            self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)
+
+        self.runCmd("run", RUN_SUCCEEDED)
+        self.expect("expr Base().foo()", substrs=["1"])
+        self.expect("expr Derived().foo()", substrs=["2"])


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68130.222131.patch
Type: text/x-patch
Size: 3421 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190927/550e5fb4/attachment.bin>


More information about the lldb-commits mailing list