Author: rnk Date: Mon Aug 7 18:33:53 2017 New Revision: 310331 URL: http://llvm.org/viewvc/llvm-project?rev=310331&view=rev Log: [codeview] Fix class name formatting
In particular, removes spaces between template arguments of class templates to better match VS type visualizers. Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/lib/CodeGen/CGDebugInfo.h cfe/trunk/test/CodeGenCXX/debug-info-codeview-display-name.cpp Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=310331&r1=310330&r2=310331&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Aug 7 18:33:53 2017 @@ -218,6 +218,19 @@ llvm::DIScope *CGDebugInfo::getContextDe return Default; } +PrintingPolicy CGDebugInfo::getPrintingPolicy() const { + PrintingPolicy PP = CGM.getContext().getPrintingPolicy(); + + // If we're emitting codeview, it's important to try to match MSVC's naming so + // that visualizers written for MSVC will trigger for our class names. In + // particular, we can't have spaces between arguments of standard templates + // like basic_string and vector. + if (CGM.getCodeGenOpts().EmitCodeView) + PP.MSVCFormatting = true; + + return PP; +} + StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) { assert(FD && "Invalid FunctionDecl!"); IdentifierInfo *FII = FD->getIdentifier(); @@ -238,18 +251,16 @@ StringRef CGDebugInfo::getFunctionName(c SmallString<128> NS; llvm::raw_svector_ostream OS(NS); - PrintingPolicy Policy(CGM.getLangOpts()); - Policy.MSVCFormatting = CGM.getCodeGenOpts().EmitCodeView; if (!UseQualifiedName) FD->printName(OS); else - FD->printQualifiedName(OS, Policy); + FD->printQualifiedName(OS, getPrintingPolicy()); // Add any template specialization args. if (Info) { const TemplateArgumentList *TArgs = Info->TemplateArguments; TemplateSpecializationType::PrintTemplateArgumentList(OS, TArgs->asArray(), - Policy); + getPrintingPolicy()); } // Copy this name on the side and use its reference. @@ -296,7 +307,7 @@ StringRef CGDebugInfo::getClassName(cons if (isa<ClassTemplateSpecializationDecl>(RD)) { SmallString<128> Name; llvm::raw_svector_ostream OS(Name); - RD->getNameForDiagnostic(OS, CGM.getContext().getPrintingPolicy(), + RD->getNameForDiagnostic(OS, getPrintingPolicy(), /*Qualified*/ false); // Copy this name on the side and use its reference. @@ -908,12 +919,11 @@ llvm::DIType *CGDebugInfo::CreateType(co SmallString<128> NS; llvm::raw_svector_ostream OS(NS); - Ty->getTemplateName().print(OS, CGM.getContext().getPrintingPolicy(), + Ty->getTemplateName().print(OS, getPrintingPolicy(), /*qualified*/ false); TemplateSpecializationType::PrintTemplateArgumentList( - OS, Ty->template_arguments(), - CGM.getContext().getPrintingPolicy()); + OS, Ty->template_arguments(), getPrintingPolicy()); auto *AliasDecl = cast<TypeAliasTemplateDecl>( Ty->getTemplateName().getAsTemplateDecl())->getTemplatedDecl(); Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=310331&r1=310330&r2=310331&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Mon Aug 7 18:33:53 2017 @@ -558,6 +558,9 @@ private: unsigned LineNo, StringRef LinkageName, llvm::GlobalVariable *Var, llvm::DIScope *DContext); + /// Get the printing policy for producing names for debug info. + PrintingPolicy getPrintingPolicy() const; + /// Get function name for the given FunctionDecl. If the name is /// constructed on demand (e.g., C++ destructor) then the name is /// stored on the side. Modified: cfe/trunk/test/CodeGenCXX/debug-info-codeview-display-name.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-codeview-display-name.cpp?rev=310331&r1=310330&r2=310331&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/debug-info-codeview-display-name.cpp (original) +++ cfe/trunk/test/CodeGenCXX/debug-info-codeview-display-name.cpp Mon Aug 7 18:33:53 2017 @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -fblocks -debug-info-kind=limited -gcodeview -emit-llvm %s \ // RUN: -o - -triple=x86_64-pc-win32 -std=c++98 | \ -// RUN: grep 'DISubprogram' | sed -e 's/.*name: "\([^"]*\)".*/"\1"/' | \ +// RUN: grep 'DISubprogram\|DICompositeType' | sed -e 's/.*name: "\([^"]*\)".*/"\1"/' | \ // RUN: FileCheck %s --check-prefix=CHECK --check-prefix=UNQUAL // RUN: %clang_cc1 -fblocks -debug-info-kind=line-tables-only -gcodeview -emit-llvm %s \ // RUN: -o - -triple=x86_64-pc-win32 -std=c++98 | \ @@ -91,3 +91,8 @@ void fn_tmpl() {} template void fn_tmpl<int, freefunc>(); // CHECK-DAG: "fn_tmpl<int,&freefunc>" + +template <typename A, typename B, typename C> struct ClassTemplate { A a; B b; C c; }; +ClassTemplate<char, short, ClassTemplate<int, int, int> > f; +// This will only show up in normal debug builds. +// UNQUAL-DAG: "ClassTemplate<char,short,ClassTemplate<int,int,int> >" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits