diff options
| author | Cody Tapscott <topolarity@tapscott.me> | 2022-09-27 19:57:43 -0700 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-09-28 12:48:28 +0300 |
| commit | e165b8b223bfaaeb5953dec9a1f03b8e0ce4ddab (patch) | |
| tree | 67af3c2ea71a7b50d283009ed92f0d08223e221d /test | |
| parent | f3a1b5c481646ee35813cbe8bb2b0a3979df3ab8 (diff) | |
| download | zig-e165b8b223bfaaeb5953dec9a1f03b8e0ce4ddab.tar.gz zig-e165b8b223bfaaeb5953dec9a1f03b8e0ce4ddab.zip | |
stage2: Fix multiple_llvm_int parameter passing
Small iteration oopsie
We could really use some more comprehensive C ABI tests.
Diffstat (limited to 'test')
| -rw-r--r-- | test/c_abi/cfuncs.c | 52 | ||||
| -rw-r--r-- | test/c_abi/main.zig | 71 |
2 files changed, 123 insertions, 0 deletions
diff --git a/test/c_abi/cfuncs.c b/test/c_abi/cfuncs.c index 439de8bbae..89de8ebcb6 100644 --- a/test/c_abi/cfuncs.c +++ b/test/c_abi/cfuncs.c @@ -120,6 +120,24 @@ typedef struct Vector5 { float q; } Vector5; +typedef struct Rect { + uint32_t left; + uint32_t right; + uint32_t top; + uint32_t bottom; +} Rect; + +void zig_multiple_struct_ints(struct Rect, struct Rect); + +typedef struct FloatRect { + float left; + float right; + float top; + float bottom; +} FloatRect; + +void zig_multiple_struct_floats(struct FloatRect, struct FloatRect); + void run_c_tests(void) { zig_u8(0xff); zig_u16(0xfffe); @@ -201,6 +219,18 @@ void run_c_tests(void) { } { + struct Rect r1 = {1, 21, 16, 4}; + struct Rect r2 = {178, 189, 21, 15}; + zig_multiple_struct_ints(r1, r2); + } + + { + struct FloatRect r1 = {1, 21, 16, 4}; + struct FloatRect r2 = {178, 189, 21, 15}; + zig_multiple_struct_floats(r1, r2); + } + + { assert_or_panic(zig_ret_bool() == 1); assert_or_panic(zig_ret_u8() == 0xff); @@ -436,6 +466,28 @@ void c_big_struct_floats(Vector5 vec) { assert_or_panic(vec.q == 55); } +void c_multiple_struct_ints(Rect x, Rect y) { + assert_or_panic(x.left == 1); + assert_or_panic(x.right == 21); + assert_or_panic(x.top == 16); + assert_or_panic(x.bottom == 4); + assert_or_panic(y.left == 178); + assert_or_panic(y.right == 189); + assert_or_panic(y.top == 21); + assert_or_panic(y.bottom == 15); +} + +void c_multiple_struct_floats(FloatRect x, FloatRect y) { + assert_or_panic(x.left == 1); + assert_or_panic(x.right == 21); + assert_or_panic(x.top == 16); + assert_or_panic(x.bottom == 4); + assert_or_panic(y.left == 178); + assert_or_panic(y.right == 189); + assert_or_panic(y.top == 21); + assert_or_panic(y.bottom == 15); +} + bool c_ret_bool() { return 1; } diff --git a/test/c_abi/main.zig b/test/c_abi/main.zig index 1bf58d3fcf..e8e2f4861c 100644 --- a/test/c_abi/main.zig +++ b/test/c_abi/main.zig @@ -355,6 +355,9 @@ export fn zig_split_struct_mixed(x: SplitStructMixed) void { extern fn c_big_struct_both(BigStruct) BigStruct; +extern fn c_multiple_struct_ints(Rect, Rect) void; +extern fn c_multiple_struct_floats(FloatRect, FloatRect) void; + test "C ABI sret and byval together" { var s = BigStruct{ .a = 1, @@ -423,6 +426,74 @@ test "C ABI structs of floats as parameter" { c_big_struct_floats(v5); } +const Rect = extern struct { + left: u32, + right: u32, + top: u32, + bottom: u32, +}; + +export fn zig_multiple_struct_ints(x: Rect, y: Rect) void { + expect(x.left == 1) catch @panic("test failure"); + expect(x.right == 21) catch @panic("test failure"); + expect(x.top == 16) catch @panic("test failure"); + expect(x.bottom == 4) catch @panic("test failure"); + expect(y.left == 178) catch @panic("test failure"); + expect(y.right == 189) catch @panic("test failure"); + expect(y.top == 21) catch @panic("test failure"); + expect(y.bottom == 15) catch @panic("test failure"); +} + +test "C ABI structs of ints as multiple parameters" { + var r1 = Rect{ + .left = 1, + .right = 21, + .top = 16, + .bottom = 4, + }; + var r2 = Rect{ + .left = 178, + .right = 189, + .top = 21, + .bottom = 15, + }; + c_multiple_struct_ints(r1, r2); +} + +const FloatRect = extern struct { + left: f32, + right: f32, + top: f32, + bottom: f32, +}; + +export fn zig_multiple_struct_floats(x: FloatRect, y: FloatRect) void { + expect(x.left == 1) catch @panic("test failure"); + expect(x.right == 21) catch @panic("test failure"); + expect(x.top == 16) catch @panic("test failure"); + expect(x.bottom == 4) catch @panic("test failure"); + expect(y.left == 178) catch @panic("test failure"); + expect(y.right == 189) catch @panic("test failure"); + expect(y.top == 21) catch @panic("test failure"); + expect(y.bottom == 15) catch @panic("test failure"); +} + +test "C ABI structs of floats as multiple parameters" { + var r1 = FloatRect{ + .left = 1, + .right = 21, + .top = 16, + .bottom = 4, + }; + var r2 = FloatRect{ + .left = 178, + .right = 189, + .top = 21, + .bottom = 15, + }; + c_multiple_struct_floats(r1, r2); +} + export fn zig_ret_bool() bool { return true; } |
