From b5d4b908c4f69642944060e8a38b00d2b82ad053 Mon Sep 17 00:00:00 2001 From: herman ten brugge Date: Tue, 22 Jun 2021 07:38:39 +0200 Subject: [PATCH] Fix function call on arm64 and riscv arm64-gen.c/riscv64-gen.c - Copy code from x86_64-gen.c (fetch cpu flag before generating any code) tests/tcctest.c: - Add test code --- arm64-gen.c | 4 ++++ riscv64-gen.c | 5 +++++ tests/tcctest.c | 14 ++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/arm64-gen.c b/arm64-gen.c index 63894091..83193f60 100644 --- a/arm64-gen.c +++ b/arm64-gen.c @@ -1010,6 +1010,10 @@ ST_FUNC void gfunc_call(int nb_args) stack = (stack + 15) >> 4 << 4; + /* fetch cpu flag before generating any code */ + if ((vtop->r & VT_VALMASK) == VT_CMP) + gv(RC_INT); + if (stack >= 0x1000000) // 16Mb tcc_error("stack size too big %lu", stack); if (stack & 0xfff) diff --git a/riscv64-gen.c b/riscv64-gen.c index 54e52bfe..04b591f9 100644 --- a/riscv64-gen.c +++ b/riscv64-gen.c @@ -621,6 +621,11 @@ ST_FUNC void gfunc_call(int nb_args) stack_adj = (stack_adj + 15) & -16; tempspace = (tempspace + 15) & -16; stack_add = stack_adj + tempspace; + + /* fetch cpu flag before generating any code */ + if ((vtop->r & VT_VALMASK) == VT_CMP) + gv(RC_INT); + if (stack_add) { if (stack_add >= 0x1000) { o(0x37 | (5 << 7) | (-stack_add & 0xfffff000)); //lui t0, upper(v) diff --git a/tests/tcctest.c b/tests/tcctest.c index e58a97fc..16fa83e5 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -4161,6 +4161,19 @@ void bounds_check1_test (void) pv(y); } +/* This failed on arm64/riscv64 */ +void map_add(int a, int b, int c, int d, int e, int f, int g, int h, int i) +{ + printf ("%d %d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h, i); +} + +void func_arg_test(void) +{ + int a = 0; + int b = 1; + map_add(0, 1, 2, 3, 4, 5, 6, 7, a && b); +} + /* gcc 2.95.3 does not handle correctly CR in strings or after strays */ #define CORRECT_CR_HANDLING @@ -4276,6 +4289,7 @@ int main(int argc, char **argv) RUN(volatile_test); RUN(attrib_test); RUN(bounds_check1_test); + RUN(func_arg_test); return 0; }