authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-06-10 11:46:27+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-10 12:50:25-04:00
log43a09f7efcc34567f119ca315ceba5a7a7e09956
tree733599dfd6daff2080a7bf3e6e535107d65093bc
parent2a7fdd56c6cb9e13634e48eef99b27755f7d2819

stage1: Fix handling of C ABI parameters split in multiple regs

Take into account the increased number of parameters when flattening a structure into one or more SSE registers. Fixes #9061

3 files changed, 12 insertions(+), 2 deletions(-)

src/stage1/codegen.cpp+2-2
......@@ -2161,11 +2161,11 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
21612161 // Register 2: (ptr + 1).*
21622162
21632163 // One floating point register per f64 or 2 f32's
2164 size_t number_of_fp_regs = (size_t)ceilf((float)ty_size / (float)8);
2164 size_t number_of_fp_regs = (ty_size + 7) / 8;
21652165
21662166 switch (fn_walk->id) {
21672167 case FnWalkIdAttrs: {
2168 fn_walk->data.attrs.gen_i += 1;
2168 fn_walk->data.attrs.gen_i += number_of_fp_regs;
21692169 break;
21702170 }
21712171 case FnWalkIdCall: {
test/stage1/c_abi/cfuncs.c+8
......@@ -1,6 +1,7 @@
11#include <inttypes.h>
22#include <stdlib.h>
33#include <stdbool.h>
4#include <string.h>
45
56void zig_panic();
67
......@@ -253,6 +254,13 @@ void c_small_struct_floats(Vector3 vec) {
253254 assert_or_panic(vec.z == 12.0);
254255}
255256
257void c_small_struct_floats_extra(Vector3 vec, const char *str) {
258 assert_or_panic(vec.x == 3.0);
259 assert_or_panic(vec.y == 6.0);
260 assert_or_panic(vec.z == 12.0);
261 assert_or_panic(!strcmp(str, "hello"));
262}
263
256264void c_big_struct_floats(Vector5 vec) {
257265 assert_or_panic(vec.x == 76.0);
258266 assert_or_panic(vec.y == -1.0);
test/stage1/c_abi/main.zig+2
......@@ -257,6 +257,7 @@ const Vector3 = extern struct {
257257 z: f32,
258258};
259259extern fn c_small_struct_floats(Vector3) void;
260extern fn c_small_struct_floats_extra(Vector3, ?[*]const u8) void;
260261
261262const Vector5 = extern struct {
262263 x: f32,
......@@ -274,6 +275,7 @@ test "C ABI structs of floats as parameter" {
274275 .z = 12.0,
275276 };
276277 c_small_struct_floats(v3);
278 c_small_struct_floats_extra(v3, "hello");
277279
278280 var v5 = Vector5{
279281 .x = 76.0,