Skip to content

Commit 8612770

Browse files
committed
[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 #63417
1 parent d140182 commit 8612770

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

clang/lib/CodeGen/MicrosoftCXXABI.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,10 @@ static bool isTrivialForMSVC(const CXXRecordDecl *RD, QualType Ty,
11101110
isa<VectorType>(Base)) {
11111111
return true;
11121112
}
1113+
if (CGM.getTarget().getTriple().isX86() &&
1114+
CGM.getABIInfo().isHomogeneousAggregate(Ty, Base, NumElts)) {
1115+
return true;
1116+
}
11131117

11141118
// We use the C++14 definition of an aggregate, so we also
11151119
// check for:

clang/test/CodeGenCXX/homogeneous-aggregates.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,22 @@ struct test2 : base2 { test2(double); protected: double v2;};
302302
test2 f(test2 *x) { return *x; }
303303
// WOA64: define dso_local void @"?f@pr62223@@YA?AUtest2@1@PEAU21@@Z"(ptr dead_on_unwind inreg noalias writable sret(%"struct.pr62223::test2") align 8 %{{.*}}, ptr noundef %{{.*}})
304304
}
305+
306+
namespace pr113104 {
307+
struct HFA {
308+
float a;
309+
float b;
310+
};
311+
312+
using HVA = float __attribute__((__vector_size__(16), __aligned__(16)));
313+
314+
struct base_hfa { HFA v1; };
315+
struct test_hfa : base_hfa { test_hfa(double); protected: HFA v2;};
316+
test_hfa CC f(test_hfa *x) { return *x; }
317+
// X64: define dso_local x86_vectorcallcc %"struct.pr113104::test_hfa" @"\01_ZN8pr1131041fEPNS_8test_hfaE@@8"(ptr noundef %x)
318+
319+
struct base_hva { HVA v1; };
320+
struct test_hva : base_hva { test_hva(double); protected: HVA v2;};
321+
test_hva CC f(test_hva *x) { return *x; }
322+
// X64: define dso_local x86_vectorcallcc %"struct.pr113104::test_hva" @"\01_ZN8pr1131041fEPNS_8test_hvaE@@8"(ptr noundef %x)
323+
}

0 commit comments

Comments
 (0)