diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -203,7 +203,8 @@ void print(raw_ostream &Out, const ASTContext &Context, const PrintingPolicy &Policy, bool OmitTemplateKW = false) const; - static bool shouldIncludeTypeForArgument(const TemplateParameterList *TPL, + static bool shouldIncludeTypeForArgument(const PrintingPolicy &Policy, + const TemplateParameterList *TPL, unsigned Idx); }; diff --git a/clang/include/clang/AST/PrettyPrinter.h b/clang/include/clang/AST/PrettyPrinter.h --- a/clang/include/clang/AST/PrettyPrinter.h +++ b/clang/include/clang/AST/PrettyPrinter.h @@ -75,7 +75,7 @@ MSVCFormatting(false), ConstantsAsWritten(false), SuppressImplicitBase(false), FullyQualifiedName(false), PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true), - UsePreferredNames(true) {} + UsePreferredNames(true), UseIntegerTypeSuffixesAlways(false) {} /// 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 @@ -273,8 +273,15 @@ /// written. When a template argument is unnamed, printing it results in /// invalid C++ code. unsigned PrintInjectedClassNameWithArguments : 1; + + /// Whether to use C++ template preferred_name attributes when printing + /// templates. unsigned UsePreferredNames : 1; + /// Whether to use type suffixes (eg: 1U) on integral non-type template + /// parameters. + unsigned UseIntegerTypeSuffixesAlways : 1; + /// Callbacks to use to allow the behavior of printing to be customized. const PrintingCallbacks *Callbacks = nullptr; }; diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -1105,9 +1105,9 @@ if (TemplOverloaded || !Params) Args[I].print(Policy, Out, /*IncludeType*/ true); else - Args[I].print( - Policy, Out, - TemplateParameterList::shouldIncludeTypeForArgument(Params, I)); + Args[I].print(Policy, Out, + TemplateParameterList::shouldIncludeTypeForArgument( + Policy, Params, I)); } Out << ">"; } @@ -1124,7 +1124,8 @@ else Args[I].getArgument().print( Policy, Out, - TemplateParameterList::shouldIncludeTypeForArgument(Params, I)); + TemplateParameterList::shouldIncludeTypeForArgument(Policy, Params, + I)); } Out << ">"; } diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -202,8 +202,9 @@ } bool TemplateParameterList::shouldIncludeTypeForArgument( - const TemplateParameterList *TPL, unsigned Idx) { - if (!TPL || Idx >= TPL->size()) + const PrintingPolicy &Policy, const TemplateParameterList *TPL, + unsigned Idx) { + if (!TPL || Idx >= TPL->size() || Policy.UseIntegerTypeSuffixesAlways) return true; const NamedDecl *TemplParam = TPL->getParam(Idx); if (const auto *ParamValueDecl = diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -763,9 +763,9 @@ StringRef Param = Params->getParam(i)->getName(); if (Param.empty()) continue; TOut << Param << " = "; - Args.get(i).print( - Policy, TOut, - TemplateParameterList::shouldIncludeTypeForArgument(Params, i)); + Args.get(i).print(Policy, TOut, + TemplateParameterList::shouldIncludeTypeForArgument( + Policy, Params, i)); TOut << ", "; } } diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -2039,9 +2039,9 @@ if (!FirstArg) OS << Comma; // Tries to print the argument with location info if exists. - printArgument( - Arg, Policy, ArgOS, - TemplateParameterList::shouldIncludeTypeForArgument(TPL, ParmIndex)); + printArgument(Arg, Policy, ArgOS, + TemplateParameterList::shouldIncludeTypeForArgument( + Policy, TPL, ParmIndex)); } StringRef ArgString = ArgOS.str(); diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -247,6 +247,7 @@ PP.SuppressInlineNamespace = false; PP.PrintCanonicalTypes = true; PP.UsePreferredNames = false; + PP.UseIntegerTypeSuffixesAlways = true; // Apply -fdebug-prefix-map. PP.Callbacks = &PrintCB; diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -984,9 +984,9 @@ for (auto &Arg : Args.arguments()) { if (!First) OS << ", "; - Arg.getArgument().print( - PrintingPolicy, OS, - TemplateParameterList::shouldIncludeTypeForArgument(Params, I)); + Arg.getArgument().print(PrintingPolicy, OS, + TemplateParameterList::shouldIncludeTypeForArgument( + PrintingPolicy, Params, I)); First = false; I++; } diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -10917,9 +10917,9 @@ } Out << " = "; - Args[I].print( - getPrintingPolicy(), Out, - TemplateParameterList::shouldIncludeTypeForArgument(Params, I)); + Args[I].print(getPrintingPolicy(), Out, + TemplateParameterList::shouldIncludeTypeForArgument( + getPrintingPolicy(), Params, I)); } Out << ']'; diff --git a/clang/test/CodeGenCXX/debug-info-template.cpp b/clang/test/CodeGenCXX/debug-info-template.cpp --- a/clang/test/CodeGenCXX/debug-info-template.cpp +++ b/clang/test/CodeGenCXX/debug-info-template.cpp @@ -30,7 +30,7 @@ // CHECK: ![[TCNESTED]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "nested", // CHECK-SAME: scope: ![[TC:[0-9]+]], -// CHECK: ![[TC]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "TC" +// CHECK: ![[TC]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "TC" // CHECK-SAME: templateParams: [[TCARGS:![0-9]*]] TC // CHECK: [[EMPTY:![0-9]*]] = !{} diff --git a/clang/test/Modules/lsv-debuginfo.cpp b/clang/test/Modules/lsv-debuginfo.cpp --- a/clang/test/Modules/lsv-debuginfo.cpp +++ b/clang/test/Modules/lsv-debuginfo.cpp @@ -26,14 +26,14 @@ // CHECK: @__clang_ast = // This type isn't anchored anywhere, expect a full definition. -// CHECK: !DICompositeType({{.*}}, name: "AlignedCharArray<4, 16>", +// CHECK: !DICompositeType({{.*}}, name: "AlignedCharArray<4U, 16U>", // CHECK-SAME: elements: // C // CHECK: @__clang_ast = // Here, too. -// CHECK: !DICompositeType({{.*}}, name: "AlignedCharArray<4, 16>", +// CHECK: !DICompositeType({{.*}}, name: "AlignedCharArray<4U, 16U>", // CHECK-SAME: elements: #include diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp --- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp +++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp @@ -244,14 +244,14 @@ void bitset_test() { std::bitset<258> i_am_empty(0); - ComparePrettyPrintToChars(i_am_empty, "std::bitset<258>"); + ComparePrettyPrintToChars(i_am_empty, "std::bitset<258ul>"); std::bitset<0> very_empty; - ComparePrettyPrintToChars(very_empty, "std::bitset<0>"); + ComparePrettyPrintToChars(very_empty, "std::bitset<0ul>"); std::bitset<15> b_000001111111100(1020); ComparePrettyPrintToChars(b_000001111111100, - "std::bitset<15> = {[2] = 1, [3] = 1, [4] = 1, [5] = 1, [6] = 1, " + "std::bitset<15ul> = {[2] = 1, [3] = 1, [4] = 1, [5] = 1, [6] = 1, " "[7] = 1, [8] = 1, [9] = 1}"); std::bitset<258> b_0_129_132(0); @@ -259,7 +259,7 @@ b_0_129_132[129] = true; b_0_129_132[132] = true; ComparePrettyPrintToChars(b_0_129_132, - "std::bitset<258> = {[0] = 1, [129] = 1, [132] = 1}"); + "std::bitset<258ul> = {[0] = 1, [129] = 1, [132] = 1}"); } void list_test() {