Skip to content

Commit 389f67b

Browse files
committed
DebugInfo: Don't simplify names referencing local enums
Due to the way type units work, this would lead to a declaration in a type unit of a local type in a CU - which is ambiguous. Rather than trying to resolve that relative to the CU that references the type unit, let's just not try to simplify these names. Longer term this should be fixed by not putting the template instantiation in a type unit to begin with - since it references an internal linkage type, it can't legitimately be duplicated/in more than one translation unit, so skip the type unit overhead. (but the right fix for that is to move type unit management into a DICompositeType flag (dropping the "identifier" field is not a perfect solution since it breaks LLVM IR linking decl/def merging during IR linking))
1 parent 01b56b8 commit 389f67b

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5040,6 +5040,10 @@ struct ReconstitutableType : public RecursiveASTVisitor<ReconstitutableType> {
50405040
Reconstitutable = false;
50415041
return false;
50425042
}
5043+
if (!ED->isExternallyVisible()) {
5044+
Reconstitutable = false;
5045+
return false;
5046+
}
50435047
}
50445048
return true;
50455049
}

clang/test/CodeGenCXX/debug-info-simple-template-names.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ struct t2 {
1616
};
1717
template <template <typename...> class T>
1818
void f3() {}
19+
namespace {
20+
enum LocalEnum { LocalEnum1 };
21+
}
22+
template<typename T, T ... ts>
23+
struct t3 { };
24+
struct t4 {
25+
t3<LocalEnum, LocalEnum1> m1;
26+
};
27+
28+
t4 v1;
29+
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "t3<(anonymous namespace)::LocalEnum, (anonymous namespace)::LocalEnum1>"
1930
void f() {
2031
// Basic examples of simplifiable/rebuildable names
2132
f1<>();

cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ template<unsigned N>
5353
struct t4 { };
5454
namespace {
5555
struct t5 { };
56+
enum LocalEnum { LocalEnum1 };
5657
}
5758
template<typename ...T1, typename T2 = int>
5859
void f5() { }
@@ -167,6 +168,14 @@ template<typename T>
167168
void operator_not_really() {
168169
}
169170

171+
template<typename T, T ...A>
172+
struct t11 {
173+
};
174+
175+
struct t12 {
176+
t11<LocalEnum, LocalEnum1> v1;
177+
};
178+
170179
int main() {
171180
struct { } A;
172181
auto L = []{};
@@ -198,6 +207,7 @@ int main() {
198207
f3<ns::EnumerationClass, ns::EnumerationClass::Enumerator3, (ns::EnumerationClass)2>();
199208
f3<ns::EnumerationSmall, ns::kNeg>();
200209
f3<decltype(ns::AnonEnum1), ns::AnonEnum3, (decltype(ns::AnonEnum1))2>();
210+
f3<LocalEnum, LocalEnum1>();
201211
f3<int*, &i>();
202212
f3<int*, nullptr>();
203213
t4<3> v2;
@@ -305,6 +315,7 @@ int main() {
305315
f1<void(t8, decltype(A))>();
306316
f1<void(t8)>();
307317
operator_not_really<int>();
318+
t12 v4;
308319
}
309320
void t8::mem() {
310321
struct t7 { };

0 commit comments

Comments
 (0)