[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:20:30 PDT 2026


https://github.com/xiongzile updated https://github.com/llvm/llvm-project/pull/192951

>From 2fe017a76fda331271e109a31b93fd46fd1165d4 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 | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index 20c52969d7024..307f1bcee1964 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -1907,10 +1907,18 @@ 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);
+    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;
+    }
+
+    const auto *ND = TD->getTemplatedDecl();
+    if (const auto *Tag = dyn_cast<TagDecl>(ND)) {
+      mangleType(Tag);
     } else if (isa<TypeAliasDecl>(ND)) {
       Out << "$$Y";
       mangleName(ND);



More information about the cfe-commits mailing list