Handle qualified constants that are directly folded by FE.
authorDevang Patel <dpatel@apple.com>
Mon, 23 Aug 2010 18:25:56 +0000 (18:25 +0000)
committerDevang Patel <dpatel@apple.com>
Mon, 23 Aug 2010 18:25:56 +0000 (18:25 +0000)
PR 7920.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111820 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/DebugInfo.h
lib/Analysis/DebugInfo.cpp
lib/CodeGen/AsmPrinter/DwarfDebug.cpp

index 51bede091c1fb85075936d28371c239eea8cc0a7..2d1418da64d8f3c3432b5b00dccd107ba22f5ed6 100644 (file)
@@ -290,6 +290,9 @@ namespace llvm {
 
     unsigned getEncoding() const { return getUnsignedField(9); }
 
+    /// Verify - Verify that a basic type descriptor is well formed.
+    bool Verify() const;
+
     /// print - print basic type.
     void print(raw_ostream &OS) const;
 
@@ -313,6 +316,9 @@ namespace llvm {
     /// return base type size.
     uint64_t getOriginalTypeSize() const;
 
+    /// Verify - Verify that a derived type descriptor is well formed.
+    bool Verify() const;
+
     /// print - print derived type.
     void print(raw_ostream &OS) const;
 
index 0bd7904060a18836d71470e1750b426a8927a112..c38002842917909d3fc8d50064a5290e0abb82d6 100644 (file)
@@ -303,6 +303,16 @@ bool DIType::Verify() const {
   return true;
 }
 
+/// Verify - Verify that a basic type descriptor is well formed.
+bool DIBasicType::Verify() const {
+  return isBasicType();
+}
+
+/// Verify - Verify that a derived type descriptor is well formed.
+bool DIDerivedType::Verify() const {
+  return isDerivedType();
+}
+
 /// Verify - Verify that a composite type descriptor is well formed.
 bool DICompositeType::Verify() const {
   if (!DbgNode)
index e236c1b227e84a2ec2776f6a410660d28b631247..408549aa703449d24fdf121c24ca27dd91fb4104 100644 (file)
@@ -1861,6 +1861,21 @@ CompileUnit *DwarfDebug::getCompileUnit(const MDNode *N) const {
   return I->second;
 }
 
+/// isUnsignedDIType - Return true if type encoding is unsigned.
+static bool isUnsignedDIType(DIType Ty) {
+  DIDerivedType DTy(Ty);
+  if (DTy.Verify())
+    return isUnsignedDIType(DTy.getTypeDerivedFrom());
+
+  DIBasicType BTy(Ty);
+  if (BTy.Verify()) {
+    unsigned Encoding = BTy.getEncoding();
+    if (Encoding == dwarf::DW_ATE_unsigned ||
+        Encoding == dwarf::DW_ATE_unsigned_char)
+      return true;
+  }
+  return false;
+}
 
 /// constructGlobalVariableDIE - Construct global variable DIE.
 void DwarfDebug::constructGlobalVariableDIE(const MDNode *N) {
@@ -1930,17 +1945,12 @@ void DwarfDebug::constructGlobalVariableDIE(const MDNode *N) {
     } 
   } else if (Constant *C = GV.getConstant()) {
     if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) {
-      DIBasicType BTy(GTy);
-      if (BTy.Verify()) {
-        unsigned Encoding = BTy.getEncoding();
-        if (Encoding == dwarf::DW_ATE_unsigned ||
-            Encoding == dwarf::DW_ATE_unsigned_char)
+      if (isUnsignedDIType(GTy))
           addUInt(VariableDIE, dwarf::DW_AT_const_value, dwarf::DW_FORM_udata,
                   CI->getZExtValue());
         else
           addSInt(VariableDIE, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata,
                  CI->getSExtValue());
-      }
     }
   }
   return;