From 58a26201c8582fc573aa681867d57c236e799acb Mon Sep 17 00:00:00 2001 From: MaxEW707 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 += "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 +concept C = requires +{ + { T::test([](){}) }; +}; + +template +struct Widget {}; + +template +struct Widget {}; + +struct Baz +{ + template + static constexpr decltype(auto) test(F&&) {} +}; + +void test() +{ + Widget w; +} +// CHECK: @"?test@@YAXXZ" From daf061085525b366775392017fd30008c7b7fb1c Mon Sep 17 00:00:00 2001 From: MaxEW707 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