From: David Blaikie Date: Wed, 2 Apr 2014 18:21:09 +0000 (+0000) Subject: DebugInfo: Include default template arguments in template type names X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a423c1ba2fc8e912e638854851733bc9a9148520;p=clang 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 or i. 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). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205447 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index df6a3ead64..0e94b51817 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -228,34 +228,20 @@ StringRef CGDebugInfo::getSelectorName(Selector S) { /// getClassName - Get class name including template argument list. StringRef CGDebugInfo::getClassName(const RecordDecl *RD) { - const ClassTemplateSpecializationDecl *Spec - = dyn_cast(RD); - if (!Spec) + // quick optimization to avoid having to intern strings that are already + // stored reliably elsewhere + if (!isa(RD)) return RD->getName(); - const TemplateArgument *Args; - unsigned NumArgs; - if (TypeSourceInfo *TAW = Spec->getTypeAsWritten()) { - const TemplateSpecializationType *TST = - cast(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. diff --git a/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp b/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp index 9012ad6bcb..506c0d5357 100644 --- a/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp +++ b/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp @@ -84,3 +84,10 @@ template<> void i::f(); extern template class i; i ii; // CHECK: ; [ DW_TAG_structure_type ] [i] {{.*}} [def] + +template +struct j { +}; +extern template class j; +j jj; +// CHECK: ; [ DW_TAG_structure_type ] [j]