From d283fc4f9d07a5f3334fe682ccabfc16e8d2933b Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Tue, 26 May 2020 15:43:52 +0200 Subject: [PATCH] [DebugInfo] Use SplitTemplateClosers (foo >) in DWARF too Summary: D76801 caused some regressions in debuginfo compatibility by changing how certain functions were named. For CodeView we try to mirror MSVC exactly: this was fixed in a549c0d00486 For DWARF the situation is murkier. Per David Blaikie: > In general DWARF doesn't specify this at all. > [...] > This isn't the only naming divergence between GCC and Clang Nevertheless, including the space seems to provide better compatibility with GCC and GDB. E.g. cpexprs.cc in the GDB testsuite requires this formatting. And there was no particular desire to change the printing of names in debug info in the first place (just in diagnostics and other more user-facing text). Fixes PR46052 Reviewers: dblaikie, labath Subscribers: aprantl, cfe-commits, dyung Tags: #clang Differential Revision: https://reviews.llvm.org/D80554 --- clang/lib/CodeGen/CGDebugInfo.cpp | 4 ++++ .../debug-info-template-explicit-specialization.cpp | 2 +- clang/test/Modules/ExtDebugInfo.cpp | 6 +++--- clang/test/Modules/ModuleDebugInfo.cpp | 6 +++--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 4e0b6aa0dca6..31f8df243017 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -236,6 +236,10 @@ PrintingPolicy CGDebugInfo::getPrintingPolicy() const { if (CGM.getCodeGenOpts().EmitCodeView) { PP.MSVCFormatting = true; PP.SplitTemplateClosers = true; + } else { + // For DWARF, printing rules are underspecified. + // SplitTemplateClosers yields better interop with GCC and GDB (PR46052). + PP.SplitTemplateClosers = true; } // Apply -fdebug-prefix-map. diff --git a/clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp b/clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp index d97d82b76965..4e41c4092bf4 100644 --- a/clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp +++ b/clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp @@ -110,7 +110,7 @@ struct j_wrap { }; j_wrap> j_wrap_j; // CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "j" -// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "j_wrap>" +// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "j_wrap >" template struct k { diff --git a/clang/test/Modules/ExtDebugInfo.cpp b/clang/test/Modules/ExtDebugInfo.cpp index 6781810d592c..aff2953b4bb5 100644 --- a/clang/test/Modules/ExtDebugInfo.cpp +++ b/clang/test/Modules/ExtDebugInfo.cpp @@ -85,14 +85,14 @@ void foo() { // This type is not anchored in the module by an explicit template instantiation. // CHECK: !DICompositeType(tag: DW_TAG_class_type, -// CHECK-SAME: name: "Template>", +// CHECK-SAME: name: "Template >", // CHECK-SAME: scope: ![[NS]], // CHECK-SAME: elements: // CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIlNS_6traitsIlEEEE") // This type is anchored in the module by an explicit template instantiation. // CHECK: !DICompositeType(tag: DW_TAG_class_type, -// CHECK-SAME: name: "Template>", +// CHECK-SAME: name: "Template >", // CHECK-SAME: scope: ![[NS]], // CHECK-SAME: flags: DIFlagFwdDecl // CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIiNS_6traitsIiEEEE") @@ -103,7 +103,7 @@ void foo() { // This one isn't. // CHECK: !DICompositeType(tag: DW_TAG_class_type, -// CHECK-SAME: name: "Template>", +// CHECK-SAME: name: "Template >", // CHECK-SAME: scope: ![[NS]], // CHECK-SAME: elements: // CHECK-SAME: templateParams: diff --git a/clang/test/Modules/ModuleDebugInfo.cpp b/clang/test/Modules/ModuleDebugInfo.cpp index 26369c896058..e6e99ed4e537 100644 --- a/clang/test/Modules/ModuleDebugInfo.cpp +++ b/clang/test/Modules/ModuleDebugInfo.cpp @@ -65,7 +65,7 @@ // This type is anchored by an explicit template instantiation. // CHECK: !DICompositeType(tag: DW_TAG_class_type, -// CHECK-SAME: name: "Template>" +// CHECK-SAME: name: "Template >" // CHECK-SAME: elements: // CHECK-SAME: templateParams: // CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIiNS_6traitsIiEEEE") @@ -80,7 +80,7 @@ // CHECK-SAME: identifier: "_ZTSN8DebugCXX6traitsIfEE") // CHECK: !DICompositeType(tag: DW_TAG_class_type, -// CHECK-SAME: name: "Template>" +// CHECK-SAME: name: "Template >" // CHECK-SAME: elements: // CHECK-SAME: templateParams: // CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIlNS_6traitsIlEEEE") @@ -89,7 +89,7 @@ // no mangled name here yet. // CHECK: !DICompositeType(tag: DW_TAG_class_type, -// CHECK-SAME: name: "Template>" +// CHECK-SAME: name: "Template >" // CHECK-SAME: flags: DIFlagFwdDecl // CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIfNS_6traitsIfEEEE")