This is an archive of the discontinued LLVM Phabricator instance.

[clang] AST/Print: honor AlwaysIncludeTypeForTemplateArgument policy
ClosedPublic

Authored by mizvekov on May 29 2022, 4:27 PM.

Details

Summary

This redoes D103040 in a way that AlwaysIncludeTypeForTemplateArgument = false
policy is honored for printing template specialization types.
This can be seen for example when printing a canonicalized
dependent TemplateSpecializationType which has integral arguments.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Diff Detail

Event Timeline

mizvekov created this revision.May 29 2022, 4:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 29 2022, 4:27 PM
mizvekov updated this revision to Diff 432974.May 30 2022, 12:45 PM
mizvekov retitled this revision from WIP to [clang] AST/Print: honor AlwaysIncludeTypeForTemplateArgument policy.
mizvekov edited the summary of this revision. (Show Details)

.

mizvekov published this revision for review.May 30 2022, 1:20 PM
mizvekov added reviewers: rsmith, v.g.vassilev, reikdas.
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2022, 1:20 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

This patch fixes our test case which we intended to fix with:

From 17e94a6a2adc3eb8d5fcc532eb1f3e57cc59b0fd Mon Sep 17 00:00:00 2001
From: Vassil Vassilev <v.g.vassilev@gmail.com>
Date: Mon, 23 May 2022 21:36:43 +0000
Subject: [PATCH] Fix type printing to not include the suffix when not needed.

before:
root.exe -l -b -q -e 'TClass::GetClass("std::array<int,3>")->Print()'
OBJ: TClassarray<int,3UL>

after: root.exe -l -b -q -e 'TClass::GetClass("std::array<int,3>")->Print()'
OBJ: TClassarray<int,3>

To be upstreamed.
---
 interpreter/llvm/src/tools/clang/lib/AST/TypePrinter.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/interpreter/llvm/src/tools/clang/lib/AST/TypePrinter.cpp b/interpreter/llvm/src/tools/clang/lib/AST/TypePrinter.cpp
index 5de22f76f458..844a5be12836 100644
--- a/interpreter/llvm/src/tools/clang/lib/AST/TypePrinter.cpp
+++ b/interpreter/llvm/src/tools/clang/lib/AST/TypePrinter.cpp
@@ -1452,7 +1452,8 @@ void TypePrinter::printTemplateId(const TemplateSpecializationType *T,
     T->getTemplateName().print(OS, Policy);
   }
 
-  printTemplateArgumentList(OS, T->template_arguments(), Policy);
+  printTemplateArgumentList(OS, T->template_arguments(), Policy,
+                            TD->getTemplateParameters());
   spaceBeforePlaceHolder(OS);
 }

The proposed patch is better because it is more precise whereas my approach above has multiple test failures and may be impossible to upstream.

This LGTM, but I'd like to see what @rsmith thinks.

reikdas resigned from this revision.May 31 2022, 9:47 AM
v.g.vassilev accepted this revision.Jun 14 2022, 5:11 AM

Let's move forward with this and rely on eventual post-commit review.

This revision is now accepted and ready to land.Jun 14 2022, 5:11 AM