https://github.com/efriedma-quic created 
https://github.com/llvm/llvm-project/pull/237634

Under the Microsoft ABI, a class with a user-provided constructor cannot be 
returned in a register.  This check was fixed in 3ab4ae9e58c09 to also handle 
template constructors.  That fix missed a special case of the special case: a 
deleted template constructor does not count as user-provided.

Fixes #237188

>From 8d5ec133a66663e7a78466094022bb3ba363144f Mon Sep 17 00:00:00 2001
From: Eli Friedman <[email protected]>
Date: Sat, 31 Oct 2026 14:03:28 -0700
Subject: [PATCH] [clang codegen] Fix MS ABI with deleted template constructor

Under the Microsoft ABI, a class with a user-provided constructor
cannot be returned in a register.  This check was fixed in 3ab4ae9e58c09
to also handle template constructors.  That fix missed a special case
of the speecial case: a deleted template constructor does not count as
user-provided.

Fixes #237188
---
 clang/docs/ReleaseNotes.md                       |  5 +++++
 clang/lib/CodeGen/MicrosoftCXXABI.cpp            |  3 ++-
 clang/test/CodeGen/arm64-microsoft-arguments.cpp | 13 +++++++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 53d688d2e11e7c..a75ad9ca7fc74b 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -157,6 +157,11 @@ features cannot lower the translation-unit ABI level;
   accesses to these fields. `__attribute__((packed))` on the field or the
   enclosing record still reduces the alignment. (#GH208256)
 
+- On Windows targets using Microsoft C++ ABI, fixed returning a class with
+  a deleted template constructor which should be returned in a register.
+  This affects the ABI of `std::strong_ordering` in some versions of the
+  Microsoft STL. (#GH237188)
+
 ### AST Dumping Potentially Breaking Changes
 
 ### Clang Frontend Potentially Breaking Changes
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 86916104d13440..73c889d27c2a13 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1172,7 +1172,8 @@ static bool isTrivialForMSVC(const CXXRecordDecl *RD, 
QualType Ty,
       if (Ctor->isUserProvided())
         return false;
     } else if (auto *Template = dyn_cast<FunctionTemplateDecl>(D)) {
-      if (isa<CXXConstructorDecl>(Template->getTemplatedDecl()))
+      if (isa<CXXConstructorDecl>(Template->getTemplatedDecl()) &&
+          !Template->getTemplatedDecl()->isDeleted())
         return false;
     } else if (auto *MethodDecl = dyn_cast<CXXMethodDecl>(D)) {
       if (MethodDecl->isCopyAssignmentOperator() && MethodDecl->isDeleted())
diff --git a/clang/test/CodeGen/arm64-microsoft-arguments.cpp 
b/clang/test/CodeGen/arm64-microsoft-arguments.cpp
index 50a1b1f6bf5549..5a49eaf83c7cc3 100644
--- a/clang/test/CodeGen/arm64-microsoft-arguments.cpp
+++ b/clang/test/CodeGen/arm64-microsoft-arguments.cpp
@@ -216,3 +216,16 @@ S12 f12() {
   S12 x((int*)0);
   return func12(x);
 }
+
+// GH237188
+// Ignore deleted template constructor
+// CHECK: define dso_local i32 @"?f13@@YA?AUS13@@PEAU1@@Z"(ptr noundef {{.*}})
+// CHECK: call i32 @"?func13@@YA?AUS13@@U1@@Z"(i32 {{.*}})
+struct S13 {
+  template<typename T> S13(T*) = delete;
+  int x;
+};
+S13 func13(S13 x);
+S13 f13(S13 *p) {
+  return func13(*p);
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to