mirror of
git://repo.or.cz/tinycc.git
synced 2026-06-17 15:44:18 +08:00
arm64: Save func results before struct args
Some checks failed
build and test / test-x86_64-linux (push) Has been cancelled
build and test / test-x86_64-osx (push) Has been cancelled
build and test / test-aarch64-osx (push) Has been cancelled
build and test / test-x86-win32 (push) Has been cancelled
build and test / test-armv7-linux (push) Has been cancelled
build and test / test-aarch64-linux (push) Has been cancelled
build and test / test-riscv64-linux (push) Has been cancelled
Some checks failed
build and test / test-x86_64-linux (push) Has been cancelled
build and test / test-x86_64-osx (push) Has been cancelled
build and test / test-aarch64-osx (push) Has been cancelled
build and test / test-x86-win32 (push) Has been cancelled
build and test / test-armv7-linux (push) Has been cancelled
build and test / test-aarch64-linux (push) Has been cancelled
build and test / test-riscv64-linux (push) Has been cancelled
In gfunc_call(), structure members are loaded into registers during argument handling. This operation may overwrite previous function call results stored in registers (e.g., s0). To prevent this, we must save function call results to the stack before processing structure arguments.
This commit is contained in:
parent
32b597746c
commit
0c12363fd3
@ -1101,6 +1101,9 @@ ST_FUNC void gfunc_call(int nb_args)
|
||||
// value in floating-point registers
|
||||
if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
|
||||
uint32_t j, sz, n = arm64_hfa(&vtop->type, &sz);
|
||||
// save regs because struct may overwrite previous func call result
|
||||
save_regs(0);
|
||||
|
||||
vtop->type.t = VT_PTR;
|
||||
gaddrof();
|
||||
gv(RC_R30);
|
||||
|
||||
23
tests/tests2/137_funcall_struct_args.c
Normal file
23
tests/tests2/137_funcall_struct_args.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
|
||||
// arm64-gen.c: gfunc_call() Second pass when struct args may overwrite previous func call result
|
||||
struct vec {
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
|
||||
void bug(float x, float y) {
|
||||
printf("x=%f\ny=%f\n", x, y);
|
||||
}
|
||||
|
||||
float dot(struct vec v) {
|
||||
return 999.5;
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
struct vec a;
|
||||
a.x = 33.0f;
|
||||
a.y = 77.0f;
|
||||
bug(dot(a), dot(a));
|
||||
}
|
||||
|
||||
2
tests/tests2/137_funcall_struct_args.expect
Normal file
2
tests/tests2/137_funcall_struct_args.expect
Normal file
@ -0,0 +1,2 @@
|
||||
x=999.500000
|
||||
y=999.500000
|
||||
Loading…
Reference in New Issue
Block a user