Skip to content

Commit 3cf280c

Browse files
authored
Emit nested unused enum types with -fno-eliminate-unused-debug-types (#137818)
Unused types are retained in the debug info when -fno-eliminate-unused-debug-types is specified. However, unused nested enums were not being emitted even with this option. This patch fixes the missing emission of unused nested enums with -fno-eliminate-unused-debug-types
1 parent f4b80b9 commit 3cf280c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7119,7 +7119,7 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
71197119
}
71207120
// Emit any static data members, they may be definitions.
71217121
for (auto *I : CRD->decls())
7122-
if (isa<VarDecl>(I) || isa<CXXRecordDecl>(I))
7122+
if (isa<VarDecl>(I) || isa<CXXRecordDecl>(I) || isa<EnumDecl>(I))
71237123
EmitTopLevelDecl(I);
71247124
break;
71257125
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %clang_cc1 -debug-info-kind=unused-types -emit-llvm -o - %s | FileCheck %s
2+
// RUN: %clang_cc1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck --check-prefix=NOUNUSEDTYPE %s
3+
4+
struct Type {
5+
enum { Unused };
6+
int value = 0;
7+
};
8+
int main() {
9+
Type t;
10+
return t.value;
11+
}
12+
13+
// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type
14+
// CHECK-SAME: scope: ![[STRUCT:[0-9]+]]
15+
// CHECK-SAME: elements: ![[ELEMENTS:[0-9]+]]
16+
17+
// CHECK: ![[STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Type"
18+
19+
// CHECK: ![[ELEMENTS]] = !{![[ENUMERATOR:[0-9]+]]}
20+
// CHECK: ![[ENUMERATOR]] = !DIEnumerator(name: "Unused", value: 0
21+
22+
23+
// NOUNUSEDTYPE-NOT: !DIEnumerator(name: "Unused"

0 commit comments

Comments
 (0)