-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Emit nested unused enum types with -fno-eliminate-unused-debug-types #137818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-clang-codegen Author: ykhatav (ykhatav) ChangesUnused types are retained in the debug info when -fno-eliminate-unused-debug-types is specified. Full diff: https://github.com/llvm/llvm-project/pull/137818.diff 2 Files Affected:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index e917f3c42da06..d63829010b3de 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -7105,7 +7105,7 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
}
// Emit any static data members, they may be definitions.
for (auto *I : CRD->decls())
- if (isa<VarDecl>(I) || isa<CXXRecordDecl>(I))
+ if (isa<VarDecl>(I) || isa<CXXRecordDecl>(I) || isa<EnumDecl>(I))
EmitTopLevelDecl(I);
break;
}
diff --git a/clang/test/CodeGen/unused_nested_enump.cpp b/clang/test/CodeGen/unused_nested_enump.cpp
new file mode 100644
index 0000000000000..7689b5bd7561b
--- /dev/null
+++ b/clang/test/CodeGen/unused_nested_enump.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -debug-info-kind=unused-types -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck --check-prefix=NOUNUSEDTYPE %s
+
+struct Type {
+ enum { Unused };
+ int value = 0;
+};
+int main() {
+ Type t;
+ return t.value;
+}
+
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type
+// CHECK-SAME: scope: ![[STRUCT:[0-9]+]]
+// CHECK-SAME: elements: ![[ELEMENTS:[0-9]+]]
+
+// CHECK: ![[STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Type"
+
+// CHECK: ![[ELEMENTS]] = !{![[ENUMERATOR:[0-9]+]]}
+// CHECK: ![[ENUMERATOR]] = !DIEnumerator(name: "Unused", value: 0
+
+
+// NOUNUSEDTYPE-NOT: !DIEnumerator(name: "Unused"
|
@llvm/pr-subscribers-clang Author: ykhatav (ykhatav) ChangesUnused types are retained in the debug info when -fno-eliminate-unused-debug-types is specified. Full diff: https://github.com/llvm/llvm-project/pull/137818.diff 2 Files Affected:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index e917f3c42da06..d63829010b3de 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -7105,7 +7105,7 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
}
// Emit any static data members, they may be definitions.
for (auto *I : CRD->decls())
- if (isa<VarDecl>(I) || isa<CXXRecordDecl>(I))
+ if (isa<VarDecl>(I) || isa<CXXRecordDecl>(I) || isa<EnumDecl>(I))
EmitTopLevelDecl(I);
break;
}
diff --git a/clang/test/CodeGen/unused_nested_enump.cpp b/clang/test/CodeGen/unused_nested_enump.cpp
new file mode 100644
index 0000000000000..7689b5bd7561b
--- /dev/null
+++ b/clang/test/CodeGen/unused_nested_enump.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -debug-info-kind=unused-types -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck --check-prefix=NOUNUSEDTYPE %s
+
+struct Type {
+ enum { Unused };
+ int value = 0;
+};
+int main() {
+ Type t;
+ return t.value;
+}
+
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type
+// CHECK-SAME: scope: ![[STRUCT:[0-9]+]]
+// CHECK-SAME: elements: ![[ELEMENTS:[0-9]+]]
+
+// CHECK: ![[STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Type"
+
+// CHECK: ![[ELEMENTS]] = !{![[ENUMERATOR:[0-9]+]]}
+// CHECK: ![[ENUMERATOR]] = !DIEnumerator(name: "Unused", value: 0
+
+
+// NOUNUSEDTYPE-NOT: !DIEnumerator(name: "Unused"
|
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