[PATCH] D67141: [DebugInfo] Emit DW_TAG_enumeration_type for referenced global enumerator.

Yuanfang Chen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 3 21:30:09 PDT 2019


ychen created this revision.
ychen added reviewers: akhuang, rnk, probinson.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This essentially reverts changes from r361400.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67141

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/enum2.c


Index: clang/test/CodeGen/enum2.c
===================================================================
--- clang/test/CodeGen/enum2.c
+++ clang/test/CodeGen/enum2.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple i386-unknown-unknown %s -debug-info-kind=limited -emit-llvm -o /dev/null
+// RUN: %clang_cc1 -triple i386-unknown-unknown %s -debug-info-kind=limited -emit-llvm -o - | FileCheck %s
+
 int v;
 enum e { MAX };
 
@@ -6,3 +7,9 @@
 {
   v = MAX;
 }
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
+// CHECK-SAME: baseType: ![[LONG:[0-9]+]]
+// CHECK-SAME: elements: ![[ELTS:[0-9]+]]
+// CHECK: ![[LONG]] = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
+// CHECK: ![[ELTS]] = !{![[MAX:[0-9]+]]}
+// CHECK: ![[MAX]] = !DIEnumerator(name: "MAX", value: 0, isUnsigned: true)
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4438,11 +4438,19 @@
   StringRef Name = VD->getName();
   llvm::DIType *Ty = getOrCreateType(VD->getType(), Unit);
 
-  // Do not use global variables for enums, unless in CodeView.
+  // Use global variables for enums in CodeView, use DW_TAG_enumeration_type for
+  // enums for non-CodeView.
   if (const auto *ECD = dyn_cast<EnumConstantDecl>(VD)) {
     const auto *ED = cast<EnumDecl>(ECD->getDeclContext());
     assert(isa<EnumType>(ED->getTypeForDecl()) && "Enum without EnumType?");
-    (void)ED;
+
+    // If not CodeView, emit DW_TAG_enumeration_type if necessary.
+    if (!CGM.getCodeGenOpts().EmitCodeView) {
+      llvm::DIType *EDTy =
+          getOrCreateType(QualType(ED->getTypeForDecl(), 0), Unit);
+      if (EDTy->getTag() == llvm::dwarf::DW_TAG_enumeration_type)
+        return;
+    }
 
     // If CodeView, emit enums as global variables, unless they are defined
     // inside a class. We do this because MSVC doesn't emit S_CONSTANTs for


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67141.218587.patch
Type: text/x-patch
Size: 1967 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190904/82b21d2d/attachment.bin>


More information about the cfe-commits mailing list