Emit debug info for enum constants.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111852 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
index 6b79b3e..6f06ed2 100644
--- a/lib/CodeGen/CGDebugInfo.cpp
+++ b/lib/CodeGen/CGDebugInfo.cpp
@@ -1097,39 +1097,8 @@
llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty,
llvm::DIFile Unit) {
- EnumDecl *ED = Ty->getDecl();
+ return CreateEnumType(Ty->getDecl(), Unit);
- llvm::SmallVector<llvm::DIDescriptor, 32> Enumerators;
-
- // Create DIEnumerator elements for each enumerator.
- for (EnumDecl::enumerator_iterator
- Enum = ED->enumerator_begin(), EnumEnd = ED->enumerator_end();
- Enum != EnumEnd; ++Enum) {
- Enumerators.push_back(DebugFactory.CreateEnumerator(Enum->getName(),
- Enum->getInitVal().getZExtValue()));
- }
-
- // Return a CompositeType for the enum itself.
- llvm::DIArray EltArray =
- DebugFactory.GetOrCreateArray(Enumerators.data(), Enumerators.size());
-
- llvm::DIFile DefUnit = getOrCreateFile(ED->getLocation());
- unsigned Line = getLineNumber(ED->getLocation());
-
- // Size and align of the type.
- uint64_t Size = 0;
- unsigned Align = 0;
- if (!Ty->isIncompleteType()) {
- Size = CGM.getContext().getTypeSize(Ty);
- Align = CGM.getContext().getTypeAlign(Ty);
- }
-
- llvm::DIType DbgTy =
- DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_enumeration_type,
- Unit, ED->getName(), DefUnit, Line,
- Size, Align, 0, 0,
- llvm::DIType(), EltArray);
- return DbgTy;
}
llvm::DIType CGDebugInfo::CreateType(const TagType *Ty,
@@ -1256,6 +1225,36 @@
0, 0, 0, llvm::DIType(), Elements);
}
+/// CreateEnumType - get enumeration type.
+llvm::DIType CGDebugInfo::CreateEnumType(const EnumDecl *ED, llvm::DIFile Unit){
+ llvm::SmallVector<llvm::DIDescriptor, 32> Enumerators;
+
+ // Create DIEnumerator elements for each enumerator.
+ for (EnumDecl::enumerator_iterator
+ Enum = ED->enumerator_begin(), EnumEnd = ED->enumerator_end();
+ Enum != EnumEnd; ++Enum) {
+ Enumerators.push_back(DebugFactory.CreateEnumerator(Enum->getName(),
+ Enum->getInitVal().getZExtValue()));
+ }
+
+ // Return a CompositeType for the enum itself.
+ llvm::DIArray EltArray =
+ DebugFactory.GetOrCreateArray(Enumerators.data(), Enumerators.size());
+
+ llvm::DIFile DefUnit = getOrCreateFile(ED->getLocation());
+ unsigned Line = getLineNumber(ED->getLocation());
+ uint64_t Size = 0;
+ if (!ED->getTypeForDecl()->isIncompleteType())
+ CGM.getContext().getTypeSize(ED->getTypeForDecl());
+
+ llvm::DIType DbgTy =
+ DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_enumeration_type,
+ Unit, ED->getName(), DefUnit, Line,
+ Size, 0, 0, 0,
+ llvm::DIType(), EltArray);
+ return DbgTy;
+}
+
static QualType UnwrapTypeForDebugInfo(QualType T) {
do {
QualType LastT = T;
@@ -1828,6 +1827,10 @@
llvm::DIFile Unit = getOrCreateFile(VD->getLocation());
llvm::StringRef Name = VD->getName();
llvm::DIType Ty = getOrCreateType(VD->getType(), Unit);
+ if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(VD)) {
+ if (const EnumDecl *ED = dyn_cast<EnumDecl>(ECD->getDeclContext()))
+ Ty = CreateEnumType(ED, Unit);
+ }
// Do not use DIGlobalVariable for enums.
if (Ty.getTag() == llvm::dwarf::DW_TAG_enumeration_type)
return;
diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h
index 0443dc3..2d8efce 100644
--- a/lib/CodeGen/CGDebugInfo.h
+++ b/lib/CodeGen/CGDebugInfo.h
@@ -92,6 +92,7 @@
llvm::DIType CreateType(const ArrayType *Ty, llvm::DIFile F);
llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DIFile F);
llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DIFile F);
+ llvm::DIType CreateEnumType(const EnumDecl *ED, llvm::DIFile Unit);
llvm::DIType getOrCreateMethodType(const CXXMethodDecl *Method,
llvm::DIFile F);
llvm::DIType getOrCreateVTablePtrType(llvm::DIFile F);
diff --git a/test/CodeGen/debug-info-enum.c b/test/CodeGen/debug-info-enum.c
new file mode 100644
index 0000000..b4a1ce0
--- /dev/null
+++ b/test/CodeGen/debug-info-enum.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm -g %s -o %t
+// RUN: grep DW_TAG_enumeration_type %t
+// Radar 8195980
+
+enum vtag {
+ VT_ONE
+};
+
+int foo(int i) {
+ return i == VT_ONE;
+}