Skip to content

Commit 48c6fad

Browse files
author
Yuanfang Chen
committed
[DebugInfo] Emit DW_TAG_enumeration_type for referenced global enumerator.
This essentially reverts changes from r361400 while keeping behavior for CodeView. Reviewers: akhuang, rnk, probinson Reviewed by: rnk Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67141 llvm-svn: 370981
1 parent 2df41a8 commit 48c6fad

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4438,19 +4438,27 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {
44384438
StringRef Name = VD->getName();
44394439
llvm::DIType *Ty = getOrCreateType(VD->getType(), Unit);
44404440

4441-
// Do not use global variables for enums, unless in CodeView.
44424441
if (const auto *ECD = dyn_cast<EnumConstantDecl>(VD)) {
44434442
const auto *ED = cast<EnumDecl>(ECD->getDeclContext());
44444443
assert(isa<EnumType>(ED->getTypeForDecl()) && "Enum without EnumType?");
4445-
(void)ED;
4446-
4447-
// If CodeView, emit enums as global variables, unless they are defined
4448-
// inside a class. We do this because MSVC doesn't emit S_CONSTANTs for
4449-
// enums in classes, and because it is difficult to attach this scope
4450-
// information to the global variable.
4451-
if (!CGM.getCodeGenOpts().EmitCodeView ||
4452-
isa<RecordDecl>(ED->getDeclContext()))
4444+
4445+
if (CGM.getCodeGenOpts().EmitCodeView) {
4446+
// If CodeView, emit enums as global variables, unless they are defined
4447+
// inside a class. We do this because MSVC doesn't emit S_CONSTANTs for
4448+
// enums in classes, and because it is difficult to attach this scope
4449+
// information to the global variable.
4450+
if (isa<RecordDecl>(ED->getDeclContext()))
4451+
return;
4452+
} else {
4453+
// If not CodeView, emit DW_TAG_enumeration_type if necessary. For
4454+
// example: for "enum { ZERO };", a DW_TAG_enumeration_type is created the
4455+
// first time `ZERO` is referenced in a function.
4456+
llvm::DIType *EDTy =
4457+
getOrCreateType(QualType(ED->getTypeForDecl(), 0), Unit);
4458+
assert (EDTy->getTag() == llvm::dwarf::DW_TAG_enumeration_type);
4459+
(void)EDTy;
44534460
return;
4461+
}
44544462
}
44554463

44564464
llvm::DIScope *DContext = nullptr;

clang/test/CodeGen/enum2.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
// RUN: %clang_cc1 -triple i386-unknown-unknown %s -debug-info-kind=limited -emit-llvm -o /dev/null
1+
// RUN: %clang_cc1 -triple i386-unknown-unknown %s -debug-info-kind=limited -emit-llvm -o - | FileCheck %s
2+
23
int v;
34
enum e { MAX };
45

56
void foo (void)
67
{
78
v = MAX;
89
}
10+
// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
11+
// CHECK-SAME: baseType: ![[LONG:[0-9]+]]
12+
// CHECK-SAME: elements: ![[ELTS:[0-9]+]]
13+
// CHECK: ![[LONG]] = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
14+
// CHECK: ![[ELTS]] = !{![[MAX:[0-9]+]]}
15+
// CHECK: ![[MAX]] = !DIEnumerator(name: "MAX", value: 0, isUnsigned: true)

0 commit comments

Comments
 (0)