[clang] [clang][codegen] Fix ABI for HVA/HFA returns on x86_64 MSVC (PR #113104)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 20 15:00:00 PDT 2024
https://github.com/kin4stat updated https://github.com/llvm/llvm-project/pull/113104
>From 86127708ed74db3c6a826c13f7c21b11a457c76d Mon Sep 17 00:00:00 2001
From: kin4stat <dkustov4 at gmail.com>
Date: Sun, 20 Oct 2024 23:43:03 +0300
Subject: [PATCH] [clang codegen] Fix ABI for HVA/HFA returns on x86_64 MSVC
MSVC normally has a bunch of restrictions on returning values directly
which don't apply to passing values directly. (This roughly corresponds
to the definition of a C++14 aggregate.) However, these restrictions
don't apply to HVAs and HFAs; make sure we check for that.
Fixes llvm/llvm-project#63417
---
clang/lib/CodeGen/MicrosoftCXXABI.cpp | 4 ++++
.../CodeGenCXX/homogeneous-aggregates.cpp | 19 +++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 0b0b45ffead92f..fa5d83243f60fe 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1110,6 +1110,10 @@ static bool isTrivialForMSVC(const CXXRecordDecl *RD, QualType Ty,
isa<VectorType>(Base)) {
return true;
}
+ if (CGM.getTarget().getTriple().isX86() &&
+ CGM.getABIInfo().isHomogeneousAggregate(Ty, Base, NumElts)) {
+ return true;
+ }
// We use the C++14 definition of an aggregate, so we also
// check for:
diff --git a/clang/test/CodeGenCXX/homogeneous-aggregates.cpp b/clang/test/CodeGenCXX/homogeneous-aggregates.cpp
index 63ffc6b5bfac84..cf8019d2f18964 100644
--- a/clang/test/CodeGenCXX/homogeneous-aggregates.cpp
+++ b/clang/test/CodeGenCXX/homogeneous-aggregates.cpp
@@ -302,3 +302,22 @@ struct test2 : base2 { test2(double); protected: double v2;};
test2 f(test2 *x) { return *x; }
// WOA64: define dso_local void @"?f at pr62223@@YA?AUtest2 at 1@PEAU21@@Z"(ptr dead_on_unwind inreg noalias writable sret(%"struct.pr62223::test2") align 8 %{{.*}}, ptr noundef %{{.*}})
}
+
+namespace pr113104 {
+struct HFA {
+ float a;
+ float b;
+};
+
+using HVA = float __attribute__((__vector_size__(16), __aligned__(16)));
+
+struct base_hfa { HFA v1; };
+struct test_hfa : base_hfa { test_hfa(double); protected: HFA v2;};
+test_hfa CC f(test_hfa *x) { return *x; }
+// X64: define dso_local x86_vectorcallcc %"struct.pr113104::test_hfa" @"\01_ZN8pr1131041fEPNS_8test_hfaE@@8"(ptr noundef %x)
+
+struct base_hva { HVA v1; };
+struct test_hva : base_hva { test_hva(double); protected: HVA v2;};
+test_hva CC f(test_hva *x) { return *x; }
+// X64: define dso_local x86_vectorcallcc %"struct.pr113104::test_hva" @"\01_ZN8pr1131041fEPNS_8test_hvaE@@8"(ptr noundef %x)
+}
\ No newline at end of file
More information about the cfe-commits
mailing list