Skip to content

Commit d1dfc9b

Browse files
committed
[lldb] Don't emit artificial constructor declarations as global functions
Summary: 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. Reviewers: aprantl, vsk, shafik Reviewed By: aprantl Subscribers: jingham, shafik, labath, JDevlieghere, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68130 git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@375151 91177308-0d34-0410-b5e6-96231b3b80d8 apple-llvm-split-commit: d9a834724538e2f96172602c9fef3bbae8f0c6c1 apple-llvm-split-dir: lldb/
1 parent b09b3a7 commit d1dfc9b

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/TestCallOverriddenMethod.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,11 @@ def test(self):
4646
# Test call to overridden method in derived class (this will fail if the
4747
# overrides table is not correctly set up, as Derived::foo will be assigned
4848
# a vtable entry that does not exist in the compiled program).
49-
self.expect("expr d.foo()")
49+
self.expect("expr d.foo()", substrs=["2"])
50+
51+
# Test calling the base class.
52+
self.expect("expr realbase.foo()", substrs=["1"])
53+
54+
# Test with locally constructed instances.
55+
self.expect("expr Base().foo()", substrs=["1"])
56+
self.expect("expr Derived().foo()", substrs=["2"])

lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class Derived : public Base {
1010
};
1111

1212
int main() {
13+
Base realbase;
14+
realbase.foo();
1315
Derived d;
1416
Base *b = &d;
1517
return 0; // Set breakpoint here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from lldbsuite.test import lldbinline
2+
from lldbsuite.test import decorators
3+
4+
lldbinline.MakeInlineTest(__file__, globals(), None)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct Foo {
2+
// Triggers that we emit an artificial constructor for Foo.
3+
virtual ~Foo() = default;
4+
};
5+
6+
int main() {
7+
Foo f;
8+
// Try to construct foo in our expression.
9+
return 0; //%self.expect("expr Foo()", substrs=["(Foo) $0 = {}"])
10+
}

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1398,8 +1398,11 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
13981398
is_attr_used, attrs.is_artificial);
13991399

14001400
type_handled = cxx_method_decl != NULL;
1401+
// Artificial methods are always handled even when don't
1402+
// create a new declaration for them.
1403+
type_handled |= attrs.is_artificial;
14011404

1402-
if (type_handled) {
1405+
if (cxx_method_decl) {
14031406
LinkDeclContextToDIE(
14041407
ClangASTContext::GetAsDeclContext(cxx_method_decl),
14051408
die);

0 commit comments

Comments
 (0)