Skip to content

Commit b8decc9

Browse files
committed
[lldb/DWARF] Unique enums parsed from declarations
This is a regression from llvm#96484 caught by @ZequanWu. Note that we will still create separate enum types for types parsed from two definitions. This is different from how we handle classes, but it is not a regression. I'm also adding the DieToType check to the class type parsing code, although in this case, the type uniqueness should be enforced by the UniqueDWARFASTType map.
1 parent 8681bb8 commit b8decc9

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,13 @@ TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
870870
}
871871
}
872872
if (def_die) {
873+
if (auto [it, inserted] = dwarf->GetDIEToType().try_emplace(
874+
def_die.GetDIE(), DIE_IS_BEING_PARSED);
875+
!inserted) {
876+
if (it->getSecond() == nullptr || it->getSecond() == DIE_IS_BEING_PARSED)
877+
return nullptr;
878+
return it->getSecond()->shared_from_this();
879+
}
873880
attrs = ParsedDWARFTypeAttributes(def_die);
874881
} else {
875882
// No definition found. Proceed with the declaration die. We can use it to
@@ -1798,6 +1805,13 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
17981805
}
17991806

18001807
if (def_die) {
1808+
if (auto [it, inserted] = dwarf->GetDIEToType().try_emplace(
1809+
def_die.GetDIE(), DIE_IS_BEING_PARSED);
1810+
!inserted) {
1811+
if (it->getSecond() == nullptr || it->getSecond() == DIE_IS_BEING_PARSED)
1812+
return nullptr;
1813+
return it->getSecond()->shared_from_this();
1814+
}
18011815
attrs = ParsedDWARFTypeAttributes(def_die);
18021816
} else {
18031817
// No definition found. Proceed with the declaration die. We can use it to
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %clangxx_host -gdwarf -c -o %t_a.o %s -DFILE_A
2+
// RUN: %clangxx_host -gdwarf -c -o %t_b.o %s -DFILE_B
3+
// RUN: %clangxx_host -o %t %t_a.o %t_b.o
4+
// RUN: %lldb %t \
5+
// RUN: -o "target variable my_enum my_enum_ref" -o "image dump ast" \
6+
// RUN: -o exit | FileCheck %s
7+
8+
9+
// CHECK: (lldb) target variable
10+
// CHECK: (MyEnum) my_enum = MyEnum_A
11+
// CHECK: (MyEnum &) my_enum_ref =
12+
// CHECK-SAME: &::my_enum_ref = MyEnum_A
13+
14+
// CHECK: (lldb) image dump ast
15+
// CHECK: EnumDecl {{.*}} MyEnum
16+
// CHECK-NEXT: EnumConstantDecl {{.*}} MyEnum_A 'MyEnum'
17+
// CHECK-NOT: MyEnum
18+
19+
enum MyEnum : int;
20+
21+
extern MyEnum my_enum;
22+
23+
#ifdef FILE_A
24+
enum MyEnum : int { MyEnum_A };
25+
26+
MyEnum my_enum = MyEnum_A;
27+
28+
int main() {}
29+
#endif
30+
#ifdef FILE_B
31+
MyEnum &my_enum_ref = my_enum;
32+
#endif

0 commit comments

Comments
 (0)