Skip to content

Commit 6237c9f

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 llvm-svn: 375151
1 parent 5be7eb3 commit 6237c9f

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ def test(self):
4949

5050
# Test calling the base class.
5151
self.expect("expr realbase.foo()", substrs=["1"])
52+
53+
# Test with locally constructed instances.
54+
self.expect("expr Base().foo()", substrs=["1"])
55+
self.expect("expr Derived().foo()", substrs=["2"])

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Derived : public Base {
1111

1212
int main() {
1313
Base realbase;
14+
realbase.foo();
1415
Derived d;
1516
Base *b = &d;
1617
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)
Lines changed: 10 additions & 0 deletions
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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,11 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
10071007
is_attr_used, attrs.is_artificial);
10081008

10091009
type_handled = cxx_method_decl != NULL;
1010+
// Artificial methods are always handled even when don't
1011+
// create a new declaration for them.
1012+
type_handled |= attrs.is_artificial;
10101013

1011-
if (type_handled) {
1014+
if (cxx_method_decl) {
10121015
LinkDeclContextToDIE(
10131016
ClangASTContext::GetAsDeclContext(cxx_method_decl),
10141017
die);

0 commit comments

Comments
 (0)