Skip to content

Commit 6e734dc

Browse files
committed
[clang] ItaniumMangle: fix mangling for unresolved types
This fixes a regression introduced here: #132748 which was originally reported here: #132748 (comment) Some time in the clang-20 time frame, we had removed subst* nodes produced from template type alias instantiation. This ended up accidentally fixing an issue where the result from an alias template substitution is mistaken for the susbtitution of an outer non-alias template, incorrectly applying the unresolved-type production to it. This fixes it by ignoring subst* nodes produced from type aliases. Though builtin templates currently don't place subst* nodes, if we ever decide to place them, this fix should cover them as well. No release notes since this regression was never released.
1 parent 3954d25 commit 6e734dc

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2511,7 +2511,6 @@ bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
25112511
case Type::PackIndexing:
25122512
case Type::TemplateTypeParm:
25132513
case Type::UnaryTransform:
2514-
case Type::SubstTemplateTypeParm:
25152514
unresolvedType:
25162515
// Some callers want a prefix before the mangled type.
25172516
Out << Prefix;
@@ -2524,6 +2523,16 @@ bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
25242523
// so we return directly.
25252524
return true;
25262525

2526+
case Type::SubstTemplateTypeParm: {
2527+
auto *ST = cast<SubstTemplateTypeParmType>(Ty);
2528+
// If this was replaced from a type alias, this is not substituted
2529+
// from an outer template parameter, so it's not an unresolved-type.
2530+
if (auto *TD = dyn_cast<TemplateDecl>(ST->getAssociatedDecl());
2531+
TD && TD->isTypeAlias())
2532+
return mangleUnresolvedTypeOrSimpleId(ST->getReplacementType(), Prefix);
2533+
goto unresolvedType;
2534+
}
2535+
25272536
case Type::Typedef:
25282537
mangleSourceNameWithAbiTags(cast<TypedefType>(Ty)->getDecl());
25292538
break;

clang/test/CodeGenCXX/mangle.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,3 +1220,30 @@ namespace test61 {
12201220
// CHECK-LABEL: @_ZN6test611fINS_1XEEEvNT_1Y1aENS3_1bE
12211221
template void f<X>(int, int);
12221222
}
1223+
1224+
namespace test62 {
1225+
template <class> struct integral_constant {
1226+
static const int value = true;
1227+
};
1228+
template <int> struct _OrImpl {};
1229+
template <class _Args> using _Or = _OrImpl<_Args::value>;
1230+
template <class _Up>
1231+
void f(_Or<integral_constant<_Up>>) {}
1232+
// CHECK-LABEL: @_ZN6test621fIiEEvNS_7_OrImplIXsr17integral_constantIT_EE5valueEEE
1233+
template void f<int>(_OrImpl<1>);
1234+
} // namespace test62
1235+
1236+
namespace test63 {
1237+
namespace {
1238+
template <class, class> struct integral_constant {
1239+
static const int value = true;
1240+
};
1241+
template <class, class> struct _And {};
1242+
template <int> struct _OrImpl {};
1243+
template <class _First> using _Or = _OrImpl<_First::value>;
1244+
template <class _Up>
1245+
void f(_And<integral_constant<int, void>, _Or<integral_constant<_Up, int>>>);
1246+
} // namespace
1247+
// CHECK-LABEL: @_ZN6test6312_GLOBAL__N_11fIiEEvNS0_4_AndINS0_17integral_constantIivEENS0_7_OrImplIXsr17integral_constantIT_iEE5valueEEEEE
1248+
void g() { f<int>({}); }
1249+
} // namespace test63

0 commit comments

Comments
 (0)