From: David Blaikie Date: Mon, 20 Sep 2021 03:34:45 +0000 (-0700) Subject: DebugInfo: Don't use preferred template names in debug info X-Git-Tag: upstream/15.0.7~30899 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2ff049b12ee3fb60581835a28bf9d0acc1723f23;p=platform%2Fupstream%2Fllvm.git DebugInfo: Don't use preferred template names in debug info Using the preferred name creates a mismatch between the textual name of a type and the DWARF tags describing the parameters as well as possible inconsistency between DWARF producers (like Clang and GCC, or older/newer Clang versions, etc). --- diff --git a/clang/include/clang/AST/PrettyPrinter.h b/clang/include/clang/AST/PrettyPrinter.h index 3baf2b2..8cab7f1 100644 --- a/clang/include/clang/AST/PrettyPrinter.h +++ b/clang/include/clang/AST/PrettyPrinter.h @@ -74,7 +74,8 @@ struct PrintingPolicy { MSWChar(LO.MicrosoftExt && !LO.WChar), IncludeNewlines(true), MSVCFormatting(false), ConstantsAsWritten(false), SuppressImplicitBase(false), FullyQualifiedName(false), - PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true) {} + PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true), + UsePreferredNames(true) {} /// Adjust this printing policy for cases where it's known that we're /// printing C++ code (for instance, if AST dumping reaches a C++-only @@ -272,6 +273,7 @@ struct PrintingPolicy { /// written. When a template argument is unnamed, printing it results in /// invalid C++ code. unsigned PrintInjectedClassNameWithArguments : 1; + unsigned UsePreferredNames : 1; /// Callbacks to use to allow the behavior of printing to be customized. const PrintingCallbacks *Callbacks = nullptr; diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index 749a3e2..3c7a6b8 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -1370,9 +1370,11 @@ void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) { void TypePrinter::printRecordBefore(const RecordType *T, raw_ostream &OS) { // Print the preferred name if we have one for this type. - for (const auto *PNA : T->getDecl()->specific_attrs()) { - if (declaresSameEntity(PNA->getTypedefType()->getAsCXXRecordDecl(), - T->getDecl())) { + if (Policy.UsePreferredNames) { + for (const auto *PNA : T->getDecl()->specific_attrs()) { + if (!declaresSameEntity(PNA->getTypedefType()->getAsCXXRecordDecl(), + T->getDecl())) + continue; // Find the outermost typedef or alias template. QualType T = PNA->getTypedefType(); while (true) { diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 8660e23..5889647 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -245,6 +245,7 @@ PrintingPolicy CGDebugInfo::getPrintingPolicy() const { PP.SuppressInlineNamespace = false; PP.PrintCanonicalTypes = true; + PP.UsePreferredNames = false; // Apply -fdebug-prefix-map. PP.Callbacks = &PrintCB; diff --git a/clang/test/CodeGenCXX/debug-info-template.cpp b/clang/test/CodeGenCXX/debug-info-template.cpp index 546fe01..ba25e21 100644 --- a/clang/test/CodeGenCXX/debug-info-template.cpp +++ b/clang/test/CodeGenCXX/debug-info-template.cpp @@ -258,3 +258,15 @@ template void f1(); // CHECK: ![[TEMP_TEMP_INL_ARGS]] = !{![[TEMP_TEMP_INL_ARGS_T:[0-9]*]]} // CHECK: ![[TEMP_TEMP_INL_ARGS_T]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, value: !"TemplateTemplateParamInlineNamespace::inl::t1") } // namespace TemplateTemplateParamInlineNamespace + +namespace NoPreferredNames { +template struct t1; +using t1i = t1; +template +struct __attribute__((__preferred_name__(t1i))) t1 {}; +template +void f1() {} +template void f1>(); +// CHECK: !DISubprogram(name: "f1 >", + +} // namespace NoPreferredNames