llvm: implement Stdcall return types

This commit is contained in:
Veikka Tuominen
2023-01-19 16:13:52 +02:00
parent 5949851074
commit 2b7678bc42
3 changed files with 21 additions and 9 deletions

View File

@@ -999,13 +999,14 @@ typedef struct {
short y;
} Coord2;
void __attribute__((stdcall)) stdcall_coord2(Coord2 a, Coord2 b, Coord2 c) {
Coord2 __attribute__((stdcall)) stdcall_coord2(Coord2 a, Coord2 b, Coord2 c) {
assert_or_panic(a.x == 0x1111);
assert_or_panic(a.y == 0x2222);
assert_or_panic(b.x == 0x3333);
assert_or_panic(b.y == 0x4444);
assert_or_panic(c.x == 0x5555);
assert_or_panic(c.y == 0x6666);
return (Coord2){123, 456};
}
void __attribute__((stdcall)) stdcall_big_union(union BigUnion x) {

View File

@@ -1161,17 +1161,25 @@ const Coord2 = extern struct {
y: i16,
};
extern fn stdcall_coord2(Coord2, Coord2, Coord2) callconv(stdcall_callconv) void;
extern fn stdcall_coord2(Coord2, Coord2, Coord2) callconv(stdcall_callconv) Coord2;
test "Stdcall ABI structs" {
stdcall_coord2(
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
const res = stdcall_coord2(
.{ .x = 0x1111, .y = 0x2222 },
.{ .x = 0x3333, .y = 0x4444 },
.{ .x = 0x5555, .y = 0x6666 },
);
try expect(res.x == 123);
try expect(res.y == 456);
}
extern fn stdcall_big_union(BigUnion) callconv(stdcall_callconv) void;
test "Stdcall ABI big union" {
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
var x = BigUnion{
.a = BigStruct{
.a = 1,