[llvm-branch-commits] [clang] release/22.x: [clang-repl] Use canonical types in QualTypeToString (#190528) (PR #190546)
Cullen Rhodes via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Apr 6 11:44:16 PDT 2026
https://github.com/c-rhodes updated https://github.com/llvm/llvm-project/pull/190546
>From 151b4a3bafdda376b3b37ab98077a6978c7f2322 Mon Sep 17 00:00:00 2001
From: Devajith <devajith.valaparambil.sreeramaswamy at cern.ch>
Date: Sun, 5 Apr 2026 18:09:39 +0200
Subject: [PATCH] [clang-repl] Use canonical types in QualTypeToString
(#190528)
Use the canonical type when generating type strings to ensure sugared
(e.g. `AutoType`, `DecltypeType`) are resolved before calling
getFullyQualifiedType.
This will revert a few commits that were added to fix these assertions.
---------
Co-authored-by: Harald van Dijk <hdijk at accesssoftek.com>
(cherry picked from commit ba286040c95ea7a15673d6a7f731dc090ffe1fde)
---
clang/lib/AST/QualTypeNames.cpp | 11 -----------
.../lib/Interpreter/InterpreterValuePrinter.cpp | 11 +++++------
clang/test/Interpreter/pretty-print.cpp | 16 ++++++++++++++++
3 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/clang/lib/AST/QualTypeNames.cpp b/clang/lib/AST/QualTypeNames.cpp
index 7cdee52acce3f..191841649a86f 100644
--- a/clang/lib/AST/QualTypeNames.cpp
+++ b/clang/lib/AST/QualTypeNames.cpp
@@ -369,17 +369,6 @@ NestedNameSpecifier createNestedNameSpecifier(const ASTContext &Ctx,
/// versions of any template parameters.
QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx,
bool WithGlobalNsPrefix) {
- // Use the underlying deduced type for AutoType
- if (const auto *AT = dyn_cast<AutoType>(QT.getTypePtr())) {
- if (AT->isDeduced()) {
- // Get the qualifiers.
- Qualifiers Quals = QT.getQualifiers();
- QT = AT->getDeducedType();
- // Add back the qualifiers.
- QT = Ctx.getQualifiedType(QT, Quals);
- }
- }
-
// In case of myType* we need to strip the pointer first, fully
// qualify and attach the pointer once again.
if (isa<PointerType>(QT.getTypePtr())) {
diff --git a/clang/lib/Interpreter/InterpreterValuePrinter.cpp b/clang/lib/Interpreter/InterpreterValuePrinter.cpp
index cfa50ee908bf8..1754e7812469a 100644
--- a/clang/lib/Interpreter/InterpreterValuePrinter.cpp
+++ b/clang/lib/Interpreter/InterpreterValuePrinter.cpp
@@ -78,7 +78,7 @@ static std::string QualTypeToString(ASTContext &Ctx, QualType QT) {
!NonRefTy->isMemberPointerType())
return Canon.getAsString(Ctx.getPrintingPolicy());
- if (const auto *TDTy = dyn_cast<TypedefType>(NonRefTy)) {
+ if (const auto *TDTy = dyn_cast<TypedefType>(Canon)) {
// FIXME: TemplateSpecializationType & SubstTemplateTypeParmType checks
// are predominately to get STL containers to print nicer and might be
// better handled in GetFullyQualifiedName.
@@ -87,13 +87,12 @@ static std::string QualTypeToString(ASTContext &Ctx, QualType QT) {
// std::vector<Type>::value_type is a SubstTemplateTypeParmType
//
QualType SSDesugar = TDTy->getLocallyUnqualifiedSingleStepDesugaredType();
- if (llvm::isa<SubstTemplateTypeParmType>(SSDesugar))
+ if (llvm::isa<SubstTemplateTypeParmType>(SSDesugar) ||
+ llvm::isa<TemplateSpecializationType>(SSDesugar))
return GetFullTypeName(Ctx, Canon);
- else if (llvm::isa<TemplateSpecializationType>(SSDesugar))
- return GetFullTypeName(Ctx, NonRefTy);
- return DeclTypeToString(NonRefTy, TDTy->getDecl());
+ return DeclTypeToString(Canon, TDTy->getDecl());
}
- return GetFullTypeName(Ctx, NonRefTy);
+ return GetFullTypeName(Ctx, Canon);
}
static std::string EnumToString(const Value &V) {
diff --git a/clang/test/Interpreter/pretty-print.cpp b/clang/test/Interpreter/pretty-print.cpp
index ef0ee8e233c28..204939eb3b523 100644
--- a/clang/test/Interpreter/pretty-print.cpp
+++ b/clang/test/Interpreter/pretty-print.cpp
@@ -73,6 +73,22 @@ auto y = Outer::Bar<int>(); y
const auto z = Outer::Foo(); z
// CHECK-NEXT: (const Outer::Foo &) @0x{{[0-9a-f]+}}
+// Check printing of DecltypeTypes (this used to assert)
+namespace N { struct D {}; }
+decltype(N::D()) decl1; decl1
+// CHECK-NEXT: (N::D &) @0x{{[0-9a-f]+}}
+
+// double-nested DecltypeType
+decltype(decl1) decl2; decl2
+// CHECK-NEXT: (N::D &) @0x{{[0-9a-f]+}}
+
+const decltype(N::D()) decl3; decl3
+// CHECK-NEXT: (const N::D &) @0x{{[0-9a-f]+}}
+
+// Check printing of UnaryTransformType (this used to assert)
+__remove_extent(N::D)* decl4; decl4
+// CHECK-NEXT: (N::D *)
+
// int i = 12;
// int &iref = i;
// iref
More information about the llvm-branch-commits
mailing list