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

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 4 13:57:01 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL370981: [DebugInfo] Emit DW_TAG_enumeration_type for referenced global enumerator. (authored by yuanfang, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67141?vs=218769&id=218786#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67141/new/

https://reviews.llvm.org/D67141

Files:
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/test/CodeGen/enum2.c


Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -4438,19 +4438,27 @@
   StringRef Name = VD->getName();
   llvm::DIType *Ty = getOrCreateType(VD->getType(), Unit);
 
-  // Do not use global variables for enums, unless in 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 CodeView, emit enums as global variables, unless they are defined
-    // inside a class. We do this because MSVC doesn't emit S_CONSTANTs for
-    // enums in classes, and because it is difficult to attach this scope
-    // information to the global variable.
-    if (!CGM.getCodeGenOpts().EmitCodeView ||
-        isa<RecordDecl>(ED->getDeclContext()))
+    if (CGM.getCodeGenOpts().EmitCodeView) {
+      // 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
+      // enums in classes, and because it is difficult to attach this scope
+      // information to the global variable.
+      if (isa<RecordDecl>(ED->getDeclContext()))
+        return;
+    } else {
+      // If not CodeView, emit DW_TAG_enumeration_type if necessary. For
+      // example: for "enum { ZERO };", a DW_TAG_enumeration_type is created the
+      // first time `ZERO` is referenced in a function.
+      llvm::DIType *EDTy =
+          getOrCreateType(QualType(ED->getTypeForDecl(), 0), Unit);
+      assert (EDTy->getTag() == llvm::dwarf::DW_TAG_enumeration_type);
+      (void)EDTy;
       return;
+    }
   }
 
   llvm::DIScope *DContext = nullptr;
Index: cfe/trunk/test/CodeGen/enum2.c
===================================================================
--- cfe/trunk/test/CodeGen/enum2.c
+++ cfe/trunk/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)


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


More information about the cfe-commits mailing list