[clang] [clang][msvc] Fix crash when mangling concept template arguments (PR #192951)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 20 04:42:48 PDT 2026
https://github.com/xiongzile created https://github.com/llvm/llvm-project/pull/192951
This fixes a crash in `MicrosoftMangle.cpp` when mangling a concept used as a
template template argument.
In the reproducer, the template argument is represented as
`TemplateArgument::Template`, and `getAsTemplate().getAsTemplateDecl()`
returns a `ConceptDecl`. The current implementation assumes that such
arguments can always be lowered through `getTemplatedDecl()` and then handled
as either a `TagDecl` or a `TypeAliasDecl`, which is not true for concepts.
As a result, the Microsoft mangling path crashes on this input, while the
Itanium ABI path does not.
This PR is marked draft because the exact mangling strategy for
`ConceptDecl` under the Microsoft ABI still needs to be confirmed.
Refs: https://github.com/llvm/llvm-project/issues/192817
>From 3d271eca57eafcb73e4b89c634633283147657f5 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] [MSVC] handle ConceptDecl
---
clang/lib/AST/MicrosoftMangle.cpp | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index 20c52969d7024..de81918703f24 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -1907,15 +1907,21 @@ 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 (const auto *CD = dyn_cast<ConceptDecl>(TD)) {
+ // concept-specific mangling
+ llvm_unreachable("ConceptDecl is not yet implemented!");
+ } 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 {
+ llvm_unreachable("unexpected template template NamedDecl!");
+ }
} else {
- llvm_unreachable("unexpected template template NamedDecl!");
+ llvm_unreachable("template decl without templated decl");
}
break;
}
More information about the cfe-commits
mailing list