Author: Eli Friedman Date: 2026-11-15T21:04:16+01:00 New Revision: 2e7a09547728b192a354f685168717989aa0c17a
URL: https://github.com/llvm/llvm-project/commit/2e7a09547728b192a354f685168717989aa0c17a DIFF: https://github.com/llvm/llvm-project/commit/2e7a09547728b192a354f685168717989aa0c17a.diff LOG: release/23.x: [clang codegen] Fix MS ABI with deleted template constructor (#237634) Manaul backport of 2abfa104dc091113f844d252b4df2a22e800e4b8. (The code change is the same, the generated IR for the testcase changed slightly.) Added: Modified: clang/docs/ReleaseNotes.md clang/lib/CodeGen/MicrosoftCXXABI.cpp clang/test/CodeGen/arm64-microsoft-arguments.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 3cd184d27f153e..75ccdd8b1b21dc 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -163,6 +163,11 @@ latest release, please see the [Clang Web Site](https://clang.llvm.org) or the This makes alignment behavior fully compatible with MSVC and fixes incorrect over‑alignment / under‑alignment of globals. `-fclang-abi-compat=22` restores the previous behavior. (#GH196071), (#GH171855) +- 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 - The JSON AST dump now includes all fields from `AvailabilityAttr`: `platform`, diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp index d324580036f6a0..03e85fa94036df 100644 --- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -1168,12 +1168,13 @@ static bool isTrivialForMSVC(const CXXRecordDecl *RD, QualType Ty, if (RD->needsImplicitCopyAssignment() && !RD->hasSimpleCopyAssignment()) return false; for (const Decl *D : RD->decls()) { - if (auto *Ctor = dyn_cast<CXXConstructorDecl>(D)) { - if (Ctor->isUserProvided()) - return false; - } else if (auto *Template = dyn_cast<FunctionTemplateDecl>(D)) { - if (isa<CXXConstructorDecl>(Template->getTemplatedDecl())) - return false; + auto *Ctor = dyn_cast<CXXConstructorDecl>(D); + if (!Ctor) { + if (auto *Template = dyn_cast<FunctionTemplateDecl>(D)) + Ctor = dyn_cast<CXXConstructorDecl>(Template->getTemplatedDecl()); + } + if (Ctor && Ctor->isUserProvided()) { + return false; } else if (auto *MethodDecl = dyn_cast<CXXMethodDecl>(D)) { if (MethodDecl->isCopyAssignmentOperator() && MethodDecl->isDeleted()) return false; diff --git a/clang/test/CodeGen/arm64-microsoft-arguments.cpp b/clang/test/CodeGen/arm64-microsoft-arguments.cpp index 14707d9814cbbb..2426731448bc98 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"(i64 {{.*}}) +struct S13 { + template<typename T> S13(T*) = delete; + int x; +}; +S13 func13(S13 x); +S13 f13(S13 *p) { + return func13(*p); +} _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
