From 9bd6b77ac66fddadc50ca99ca327f1b7f9b0d6e4 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 14 Apr 2020 23:35:35 -0700 Subject: [PATCH] Don't print `&` as part of reference template arguments. In passing, also generalize the mechanism used to allow Decl's printName functions to override qualified name printing. --- clang/lib/AST/Decl.cpp | 15 ++++++++++++--- clang/lib/AST/TemplateBase.cpp | 10 +++------- clang/test/CodeGenCXX/debug-info-template.cpp | 4 +--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 1eb8547..8d98e1f 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -1542,10 +1542,19 @@ void NamedDecl::printQualifiedName(raw_ostream &OS, return; } printNestedNameSpecifier(OS, P); - if (getDeclName() || isa(this)) + if (getDeclName()) OS << *this; - else - OS << "(anonymous)"; + else { + // Give the printName override a chance to pick a different name before we + // fall back to "(anonymous)". + SmallString<64> NameBuffer; + llvm::raw_svector_ostream NameOS(NameBuffer); + printName(NameOS); + if (NameBuffer.empty()) + OS << "(anonymous)"; + else + OS << NameBuffer; + } } void NamedDecl::printNestedNameSpecifier(raw_ostream &OS) const { diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp index c122213..6a3d2b3 100644 --- a/clang/lib/AST/TemplateBase.cpp +++ b/clang/lib/AST/TemplateBase.cpp @@ -352,13 +352,9 @@ void TemplateArgument::print(const PrintingPolicy &Policy, case Declaration: { NamedDecl *ND = getAsDecl(); - Out << '&'; - if (ND->getDeclName()) { - // FIXME: distinguish between pointer and reference args? - ND->printQualifiedName(Out); - } else { - Out << "(anonymous)"; - } + if (!getParamTypeForDecl()->isReferenceType()) + Out << '&'; + ND->printQualifiedName(Out); break; } diff --git a/clang/test/CodeGenCXX/debug-info-template.cpp b/clang/test/CodeGenCXX/debug-info-template.cpp index 4b330a0..a07222a 100644 --- a/clang/test/CodeGenCXX/debug-info-template.cpp +++ b/clang/test/CodeGenCXX/debug-info-template.cpp @@ -129,9 +129,7 @@ struct NN { // CHECK: [[NNV]] = distinct !DIGlobalVariable(name: "nn" // CHECK-SAME: type: ![[NNT:[0-9]+]] -// FIXME: these parameters should probably be rendered as 'glb' rather than -// '&glb', since they're references, not pointers. -// CHECK: ![[NNT]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "NN", +// CHECK: ![[NNT]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "NN", // CHECK-SAME: templateParams: [[NNARGS:![0-9]*]] // CHECK-SAME: identifier: // CHECK: [[NNARGS]] = !{[[NNARG1:![0-9]*]], [[NNARG2:![0-9]*]], [[NNARG3:![0-9]*]]} -- 2.7.4