From a549c0d00486bf01cb485e343d778fe4a3649a43 Mon Sep 17 00:00:00 2001 From: Adrian McCarthy Date: Fri, 1 May 2020 15:51:02 -0700 Subject: [PATCH] Fix template class debug info for Visual Studio visualizers An earlier change eliminated spaces between the close brackets of nested template lists. Unfortunately that prevents the Windows debuggers from matching some types to their corresponding visualizers (e.g., std::map). This selects the SeparateTemplateClosers flag when generating CodeView. Note that we were already making formatting adjustments under similar circumstances for similar reasons. This wasn't caught by existing tests because they were using only -std=c++98. Differential Revision: https://reviews.llvm.org/D79274 --- clang/lib/CodeGen/CGDebugInfo.cpp | 7 +++++-- .../test/CodeGenCXX/debug-info-codeview-display-name.cpp | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index f92b21d..88ddb44 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -231,9 +231,12 @@ PrintingPolicy CGDebugInfo::getPrintingPolicy() const { // 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) + // like basic_string and vector, but we must have spaces between consecutive + // angle brackets that close nested template argument lists. + if (CGM.getCodeGenOpts().EmitCodeView) { PP.MSVCFormatting = true; + PP.SplitTemplateClosers = true; + } // Apply -fdebug-prefix-map. PP.Callbacks = &PrintCB; diff --git a/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp b/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp index ab3344b..15f625d 100644 --- a/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp +++ b/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp @@ -1,11 +1,19 @@ // RUN: %clang_cc1 -fblocks -debug-info-kind=limited -gcodeview -emit-llvm %s \ -// RUN: -o - -triple=x86_64-pc-win32 -std=c++98 | \ +// RUN: -o - -triple=x86_64-pc-win32 -Wno-new-returns-null -std=c++98 | \ // RUN: grep -E '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 | \ +// RUN: -o - -triple=x86_64-pc-win32 -Wno-new-returns-null -std=c++98 | \ // RUN: grep 'DISubprogram' | sed -e 's/.*name: "\([^"]*\)".*/"\1"/' | \ // RUN: FileCheck %s --check-prefix=CHECK --check-prefix=QUAL +// RUN: %clang_cc1 -fblocks -debug-info-kind=limited -gcodeview -emit-llvm %s \ +// RUN: -o - -triple=x86_64-pc-win32 -Wno-new-returns-null -std=c++11 | \ +// RUN: grep -E 'DISubprogram|DICompositeType' | sed -e 's/.*name: "\([^"]*\)".*/"\1"/' | \ +// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=UNQUAL +// RUN: %clang_cc1 -fblocks -debug-info-kind=limited -gcodeview -emit-llvm %s \ +// RUN: -o - -triple=x86_64-pc-win32 -Wno-new-returns-null | \ +// RUN: grep -E 'DISubprogram|DICompositeType' | sed -e 's/.*name: "\([^"]*\)".*/"\1"/' | \ +// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=UNQUAL void freefunc() { } // CHECK-DAG: "freefunc" @@ -94,5 +102,7 @@ template void fn_tmpl(); template struct ClassTemplate { A a; B b; C c; }; ClassTemplate > f; -// This will only show up in normal debug builds. +// This will only show up in normal debug builds. The space in `> >` is +// important for compatibility with Windows debuggers, so it should always be +// there when generating CodeView. // UNQUAL-DAG: "ClassTemplate >" -- 2.7.4