Skip to content

Commit fdc6aea

Browse files
committed
[lldb] Check Decl kind when completing -flimit-debug-info types
The search for the complete class definition can also produce entries which are not of the expected type. This can happen for instance when there is a function with the same name as the class we're looking up (which means that the class needs to be disambiguated with the struct/class tag in most contexts). Previously we were just picking the first Decl that the lookup returned, which later caused crashes or assertion failures if it was not of the correct type. This patch changes that to search for an entry of the correct type. Differential Revision: https://reviews.llvm.org/D85904
1 parent e6b1b61 commit fdc6aea

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -870,13 +870,14 @@ ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl *From) {
870870
return dn_or_err.takeError();
871871
DeclContext *dc = *dc_or_err;
872872
DeclContext::lookup_result lr = dc->lookup(*dn_or_err);
873-
if (lr.size()) {
874-
clang::Decl *lookup_found = lr.front();
875-
RegisterImportedDecl(From, lookup_found);
876-
m_decls_to_ignore.insert(lookup_found);
877-
return lookup_found;
878-
} else
879-
LLDB_LOG(log, "[ClangASTImporter] Complete definition not found");
873+
for (clang::Decl *candidate : lr) {
874+
if (candidate->getKind() == From->getKind()) {
875+
RegisterImportedDecl(From, candidate);
876+
m_decls_to_ignore.insert(candidate);
877+
return candidate;
878+
}
879+
}
880+
LLDB_LOG(log, "[ClangASTImporter] Complete definition not found");
880881
}
881882

882883
return ASTImporter::ImportImpl(From);

lldb/test/API/functionalities/limit-debug-info/TestLimitDebugInfo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ def test_one_and_two_debug(self):
6363
self.expect_expr("get_two().one().member", result_value="124")
6464
self.expect_expr("get_two().member", result_value="224")
6565

66+
self.expect_expr("shadowed_one.member", result_value="47")
67+
self.expect_expr("shadowed_one.one", result_value="142")
68+
6669
@skipIf(bugnumber="pr46284", debug_info="gmodules")
6770
@skipIfWindows # Clang emits type info even with -flimit-debug-info
6871
def test_two_debug(self):
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
#include "onetwo.h"
22

33
struct InheritsFromOne : One {
4-
constexpr InheritsFromOne() = default;
54
int member = 47;
65
} inherits_from_one;
76

87
struct InheritsFromTwo : Two {
9-
constexpr InheritsFromTwo() = default;
108
int member = 47;
119
} inherits_from_two;
1210

1311
struct OneAsMember {
14-
constexpr OneAsMember() = default;
1512
member::One one;
1613
int member = 47;
1714
} one_as_member;
1815

1916
struct TwoAsMember {
20-
constexpr TwoAsMember() = default;
2117
member::Two two;
2218
int member = 47;
2319
} two_as_member;
@@ -28,4 +24,9 @@ array::Two array_of_two[3];
2824
result::One get_one() { return result::One(124); }
2925
result::Two get_two() { return result::Two(224); }
3026

27+
// Note that there's also a function with the name func_shadow::One.
28+
struct ShadowedOne : func_shadow::One {
29+
int member = 47;
30+
} shadowed_one;
31+
3132
int main() { return get_one().member; }

lldb/test/API/functionalities/limit-debug-info/one.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ array::One::~One() = default;
66

77
result::One::One(int member) : member(member) {}
88
result::One::~One() = default;
9+
10+
void func_shadow::One(int) {}
11+
func_shadow::One::~One() = default;
12+
void func_shadow::One(float) {}

lldb/test/API/functionalities/limit-debug-info/onetwo.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,13 @@ struct Two {
5454
virtual ~Two();
5555
};
5656
} // namespace result
57+
58+
namespace func_shadow {
59+
void One(int);
60+
struct One {
61+
int one = 142;
62+
constexpr One() = default;
63+
virtual ~One();
64+
};
65+
void One(float);
66+
} // namespace func_shadow

0 commit comments

Comments
 (0)