[clang] [clang][msvc] Fix crash when mangling concept template arguments (PR #192951)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 20 05:16:40 PDT 2026
https://github.com/xiongzile updated https://github.com/llvm/llvm-project/pull/192951
>From ee987e9b32f4b69b60d2b7f0c411e2fed1c3d7a1 Mon Sep 17 00:00:00 2001
From: Zile Xiong <xiongzile at bytedance.com>
Date: Mon, 20 Apr 2026 19:34:28 +0800
Subject: [PATCH] [clang][MicrosoftMangle] Fix crash on concept
template-template arguments
Refs https://github.com/llvm/llvm-project/issues/192817
Clang crashes in the Microsoft mangler when a concept is used as a
template template argument. This happens because `ConceptDecl` does not
provide a `getTemplatedDecl()`.
MSVC rejects this construct, so treat it as unsupported instead of
crashing, using `Error(...)` and returning gracefully.
---
clang/lib/AST/MicrosoftMangle.cpp | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index 20c52969d7024..5e2d210d8be44 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -1907,15 +1907,26 @@ void MicrosoftCXXNameMangler::mangleTemplateArg(const TemplateDecl *TD,
break;
}
case TemplateArgument::Template: {
- const NamedDecl *ND =
- TA.getAsTemplate().getAsTemplateDecl()->getTemplatedDecl();
- if (const auto *TD = dyn_cast<TagDecl>(ND)) {
- mangleType(TD);
- } else if (isa<TypeAliasDecl>(ND)) {
- Out << "$$Y";
- mangleName(ND);
+ const TemplateDecl *TD = TA.getAsTemplate().getAsTemplateDecl();
+ if (isa<ConceptDecl>(TD)) {
+ // MSVC does not support concepts in template-template-parameter position,
+ // so there is no established mangling for this case under the Microsoft ABI.
+ Error("template argument (concept template-template arguments are not "
+ "supported by the Microsoft ABI)");
+ return;
+ } else if (const auto *ND = TD->getTemplatedDecl()) {
+ if (const auto *Tag = dyn_cast<TagDecl>(ND)) {
+ mangleType(Tag);
+ } else if (isa<TypeAliasDecl>(ND)) {
+ Out << "$$Y";
+ mangleName(ND);
+ } else {
+ Error("template argument (unsupported template template NamedDecl)");
+ return;
+ }
} else {
- llvm_unreachable("unexpected template template NamedDecl!");
+ Error("template argument (template decl without templated declaration)");
+ return;
}
break;
}
More information about the cfe-commits
mailing list