Skip to content

release/22.x: [clang-repl] Use canonical types in QualTypeToString (#190528)#190546

Open
devajithvs wants to merge 1 commit intollvm:release/22.xfrom
devajithvs:pr.190528.backport
Open

release/22.x: [clang-repl] Use canonical types in QualTypeToString (#190528)#190546
devajithvs wants to merge 1 commit intollvm:release/22.xfrom
devajithvs:pr.190528.backport

Conversation

@devajithvs
Copy link
Copy Markdown
Contributor

Backport of: #190528

This would fix the assertions triggered by clang-repl following this suggestion: #186105 (comment)

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@accesssoftek.com>
(cherry picked from commit ba28604)
@devajithvs devajithvs self-assigned this Apr 5, 2026
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Apr 5, 2026
@devajithvs devajithvs requested review from hvdijk and vgvassilev April 5, 2026 18:26
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Apr 5, 2026

@llvm/pr-subscribers-clang

Author: Devajith (devajithvs)

Changes

Backport of: #190528

This would fix the assertions triggered by clang-repl following this suggestion: #186105 (comment)


Full diff: https://github.com/llvm/llvm-project/pull/190546.diff

3 Files Affected:

  • (modified) clang/lib/AST/QualTypeNames.cpp (-11)
  • (modified) clang/lib/Interpreter/InterpreterValuePrinter.cpp (+5-6)
  • (modified) clang/test/Interpreter/pretty-print.cpp (+16)
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

@devajithvs devajithvs added this to the LLVM 22.x Release milestone Apr 5, 2026
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Apr 5, 2026
@github-project-automation github-project-automation bot moved this from Needs Triage to Needs Merge in LLVM Release Status Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

Status: Needs Merge

Development

Successfully merging this pull request may close these issues.

3 participants