release/22.x: [clang-repl] Use canonical types in QualTypeToString (#190528)#190546
Open
devajithvs wants to merge 1 commit intollvm:release/22.xfrom
Open
release/22.x: [clang-repl] Use canonical types in QualTypeToString (#190528)#190546devajithvs wants to merge 1 commit intollvm:release/22.xfrom
devajithvs wants to merge 1 commit intollvm:release/22.xfrom
Conversation
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)
Member
|
@llvm/pr-subscribers-clang Author: Devajith (devajithvs) ChangesBackport 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:
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
|
hvdijk
approved these changes
Apr 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of: #190528
This would fix the assertions triggered by clang-repl following this suggestion: #186105 (comment)