[cfe-commits] r88808 - in /cfe/trunk: lib/CodeGen/CGDebugInfo.cpp test/CodeGenCXX/debug-info.cpp

Anders Carlsson andersca at mac.com
Sat Nov 14 13:08:12 PST 2009


Author: andersca
Date: Sat Nov 14 15:08:12 2009
New Revision: 88808

URL: http://llvm.org/viewvc/llvm-project?rev=88808&view=rev
Log:
Canonicalize the type before trying to create a debug type.

Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/test/CodeGenCXX/debug-info.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=88808&r1=88807&r2=88808&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Sat Nov 14 15:08:12 2009
@@ -795,6 +795,29 @@
                                Ty, Ty->getPointeeType(), Unit);
 }
 
+static QualType CanonicalizeTypeForDebugInfo(QualType T) {
+  switch (T->getTypeClass()) {
+  default:
+    return T;
+  case Type::TemplateSpecialization:
+    return cast<TemplateSpecializationType>(T)->desugar();
+  case Type::TypeOfExpr: {
+    TypeOfExprType *Ty = cast<TypeOfExprType>(T);
+    return CanonicalizeTypeForDebugInfo(Ty->getUnderlyingExpr()->getType());
+  }
+  case Type::TypeOf:
+    return cast<TypeOfType>(T)->getUnderlyingType();
+  case Type::Decltype:
+    return cast<DecltypeType>(T)->getUnderlyingType();
+  case Type::QualifiedName:
+    return cast<QualifiedNameType>(T)->getNamedType();
+  case Type::SubstTemplateTypeParm:
+    return cast<SubstTemplateTypeParmType>(T)->getReplacementType();
+  case Type::Elaborated:
+    return cast<ElaboratedType>(T)->getUnderlyingType();
+  }
+}
+
 /// getOrCreateType - Get the type from the cache or create a new
 /// one if necessary.
 llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty,
@@ -802,6 +825,9 @@
   if (Ty.isNull())
     return llvm::DIType();
 
+  // Canonicalize the type.
+  Ty = CanonicalizeTypeForDebugInfo(Ty);
+  
   // Check for existing entry.
   std::map<void *, llvm::WeakVH>::iterator it =
     TypeCache.find(Ty.getAsOpaquePtr());
@@ -859,36 +885,10 @@
   case Type::FunctionProto:
   case Type::FunctionNoProto:
     return CreateType(cast<FunctionType>(Ty), Unit);
-  case Type::Elaborated:
-    return getOrCreateType(cast<ElaboratedType>(Ty)->getUnderlyingType(),
-                           Unit);
-
   case Type::ConstantArray:
   case Type::VariableArray:
   case Type::IncompleteArray:
     return CreateType(cast<ArrayType>(Ty), Unit);
-  case Type::TypeOfExpr:
-    return getOrCreateType(cast<TypeOfExprType>(Ty)->getUnderlyingExpr()
-                           ->getType(), Unit);
-  case Type::TypeOf:
-    return getOrCreateType(cast<TypeOfType>(Ty)->getUnderlyingType(), Unit);
-  case Type::Decltype:
-    return getOrCreateType(cast<DecltypeType>(Ty)->getUnderlyingType(), Unit);
-
-  case Type::QualifiedName: {
-    const QualifiedNameType *T = cast<QualifiedNameType>(Ty);
-    return CreateTypeNode(T->getNamedType(), Unit);
-  }
-
-  case Type::SubstTemplateTypeParm: {
-    const SubstTemplateTypeParmType *T = cast<SubstTemplateTypeParmType>(Ty);
-    return CreateTypeNode(T->getReplacementType(), Unit);
-  }
-
-  case Type::TemplateSpecialization: {
-    const TemplateSpecializationType *T = cast<TemplateSpecializationType>(Ty);
-    return CreateTypeNode(T->desugar(), Unit);
-  }
 
   case Type::LValueReference:
     return CreateType(cast<LValueReferenceType>(Ty), Unit);

Modified: cfe/trunk/test/CodeGenCXX/debug-info.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info.cpp?rev=88808&r1=88807&r2=88808&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info.cpp Sat Nov 14 15:08:12 2009
@@ -6,3 +6,8 @@
 void f(Identity<int>::Type a) {}
 void f(Identity<int> a) {}
 void f(int& a) { }
+
+template<typename T> struct A {
+  A<T> *next;
+};
+void f(A<int>) { }





More information about the cfe-commits mailing list