[clang] [Clang][AST] Fix MS Mangle concept uneval context template instantiation crash (PR #117845)

Max Winkler via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 28 15:57:17 PST 2024


https://github.com/MaxEW707 updated https://github.com/llvm/llvm-project/pull/117845

>From 58a26201c8582fc573aa681867d57c236e799acb Mon Sep 17 00:00:00 2001
From: MaxEW707 <max.enrico.winkler at gmail.com>
Date: Tue, 26 Nov 2024 19:45:10 -0800
Subject: [PATCH 1/2] Fix MS Mangle concept uneval context template
 instantiation crash

---
 clang/lib/AST/MicrosoftMangle.cpp          | 10 ++++++++-
 clang/test/AST/ms-uneval-context-crash.cpp | 25 ++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/ms-uneval-context-crash.cpp

diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index dbc161347025c0..c177e3b1d01ddf 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -3374,7 +3374,15 @@ void MicrosoftCXXNameMangler::mangleType(const MemberPointerType *T,
 
 void MicrosoftCXXNameMangler::mangleType(const TemplateTypeParmType *T,
                                          Qualifiers, SourceRange Range) {
-  Error(Range.getBegin(), "template type parameter type") << Range;
+  Out << '?';
+
+  llvm::SmallString<64> Name;
+  Name += "<TTPT_";
+  Name += llvm::utostr(T->getDepth());
+  Name += "_";
+  Name += llvm::utostr(T->getIndex());
+  Name += ">";
+  mangleSourceName(Name);
 }
 
 void MicrosoftCXXNameMangler::mangleType(const SubstTemplateTypeParmPackType *T,
diff --git a/clang/test/AST/ms-uneval-context-crash.cpp b/clang/test/AST/ms-uneval-context-crash.cpp
new file mode 100644
index 00000000000000..b2f7e58381da81
--- /dev/null
+++ b/clang/test/AST/ms-uneval-context-crash.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c++20 -fms-compatibility -fms-compatibility-version=19.33 -emit-llvm %s -o - -triple=x86_64-windows-msvc | FileCheck %s
+
+template <typename T>
+concept C = requires
+{
+    { T::test([](){}) };
+};
+
+template<typename T>
+struct Widget {};
+
+template <C T>
+struct Widget<T> {};
+
+struct Baz
+{
+    template<typename F>
+    static constexpr decltype(auto) test(F&&) {}
+};
+
+void test()
+{
+    Widget<Baz> w;
+}
+// CHECK: @"?test@@YAXXZ"

>From daf061085525b366775392017fd30008c7b7fb1c Mon Sep 17 00:00:00 2001
From: MaxEW707 <max.enrico.winkler at gmail.com>
Date: Thu, 28 Nov 2024 15:56:54 -0800
Subject: [PATCH 2/2] Move to CodeGenCXX

---
 clang/test/{AST => CodeGenCXX}/ms-uneval-context-crash.cpp | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename clang/test/{AST => CodeGenCXX}/ms-uneval-context-crash.cpp (100%)

diff --git a/clang/test/AST/ms-uneval-context-crash.cpp b/clang/test/CodeGenCXX/ms-uneval-context-crash.cpp
similarity index 100%
rename from clang/test/AST/ms-uneval-context-crash.cpp
rename to clang/test/CodeGenCXX/ms-uneval-context-crash.cpp



More information about the cfe-commits mailing list