r205447 - DebugInfo: Include default template arguments in template type names

David Blaikie dblaikie at gmail.com
Wed Apr 2 11:21:09 PDT 2014


Author: dblaikie
Date: Wed Apr  2 13:21:09 2014
New Revision: 205447

URL: http://llvm.org/viewvc/llvm-project?rev=205447&view=rev
Log:
DebugInfo: Include default template arguments in template type names

This was committed 4 years ago in 108916 with insufficient testing to
explain why the "getTypeAsWritten" case was appropriate. Experience says
that it isn't - the presence or absence of an explicit instantiation
declaration was causing this code to generate either i<int> or i<int,
int>.

That didn't seem to be a useful distinction, and omitting the template
arguments was destructive to debuggers being able to associate the two
types across translation units or across compilers (GCC, reasonably,
never omitted the arguments).

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

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=205447&r1=205446&r2=205447&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Apr  2 13:21:09 2014
@@ -228,34 +228,20 @@ StringRef CGDebugInfo::getSelectorName(S
 /// getClassName - Get class name including template argument list.
 StringRef
 CGDebugInfo::getClassName(const RecordDecl *RD) {
-  const ClassTemplateSpecializationDecl *Spec
-    = dyn_cast<ClassTemplateSpecializationDecl>(RD);
-  if (!Spec)
+  // quick optimization to avoid having to intern strings that are already
+  // stored reliably elsewhere
+  if (!isa<ClassTemplateSpecializationDecl>(RD))
     return RD->getName();
 
-  const TemplateArgument *Args;
-  unsigned NumArgs;
-  if (TypeSourceInfo *TAW = Spec->getTypeAsWritten()) {
-    const TemplateSpecializationType *TST =
-      cast<TemplateSpecializationType>(TAW->getType());
-    Args = TST->getArgs();
-    NumArgs = TST->getNumArgs();
-  } else {
-    const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
-    Args = TemplateArgs.data();
-    NumArgs = TemplateArgs.size();
-  }
-  StringRef Name = RD->getIdentifier()->getName();
-  PrintingPolicy Policy(CGM.getLangOpts());
-  SmallString<128> TemplateArgList;
+  SmallString<128> Name;
   {
-    llvm::raw_svector_ostream OS(TemplateArgList);
-    TemplateSpecializationType::PrintTemplateArgumentList(OS, Args, NumArgs,
-                                                          Policy);
+    llvm::raw_svector_ostream OS(Name);
+    RD->getNameForDiagnostic(OS, CGM.getContext().getPrintingPolicy(),
+                             /*Qualified*/ false);
   }
 
   // Copy this name on the side and use its reference.
-  return internString(Name, TemplateArgList);
+  return internString(Name);
 }
 
 /// getOrCreateFile - Get the file debug info descriptor for the input location.

Modified: cfe/trunk/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp?rev=205447&r1=205446&r2=205447&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp Wed Apr  2 13:21:09 2014
@@ -84,3 +84,10 @@ template<> void i<int>::f();
 extern template class i<int>;
 i<int> ii;
 // CHECK: ; [ DW_TAG_structure_type ] [i<int>] {{.*}} [def]
+
+template <typename T1, typename T2 = T1>
+struct j {
+};
+extern template class j<int>;
+j<int> jj;
+// CHECK: ; [ DW_TAG_structure_type ] [j<int, int>]





More information about the cfe-commits mailing list