[cfe-commits] r111852 - in /cfe/trunk: lib/CodeGen/CGDebugInfo.cpp lib/CodeGen/CGDebugInfo.h test/CodeGen/debug-info-enum.c

Devang Patel dpatel at apple.com
Mon Aug 23 15:07:25 PDT 2010


Author: dpatel
Date: Mon Aug 23 17:07:25 2010
New Revision: 111852

URL: http://llvm.org/viewvc/llvm-project?rev=111852&view=rev
Log:
Emit debug info for enum constants.

Added:
    cfe/trunk/test/CodeGen/debug-info-enum.c
Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=111852&r1=111851&r2=111852&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Aug 23 17:07:25 2010
@@ -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;

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=111852&r1=111851&r2=111852&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Mon Aug 23 17:07:25 2010
@@ -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);

Added: cfe/trunk/test/CodeGen/debug-info-enum.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-enum.c?rev=111852&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/debug-info-enum.c (added)
+++ cfe/trunk/test/CodeGen/debug-info-enum.c Mon Aug 23 17:07:25 2010
@@ -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;
+}





More information about the cfe-commits mailing list