I confirm your test case fails on Linux x64. It looks your patch pay attention to PTR_SIZE == 4 (i.e. it now enters if only with 32bit processor). However, w.o. the patch I can't reproduce the core dump on aarch64 Linux nor with Windows x64 which are also a 64bit processors. They both correctly display "42 42" No core dumps does not mean it works, memory may be corrupted somewhere else.
Either your patch is only required for Linux x64 or there is something to investigate more carefully. I can only test on different platforms but I'm unable to give you further advices. M2c C. -----Original Message----- From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On Behalf Of Herman ten Brugge via Tinycc-devel Sent: Tuesday, October 22, 2019 22:15 To: tinycc-devel@nongnu.org Cc: Herman ten Brugge Subject: [Tinycc-devel] core dump because stack overwritten I have a small testcase: -------------- #include <stdio.h> #include <stdlib.h> #include <inttypes.h> int main(void) { struct tst_struct { uint64_t cnt; } *tst = (struct tst_struct *) malloc (sizeof (struct tst_struct)); tst->cnt = 42; printf ("%" PRIu64 " %" PRIu64 "\n", tst->cnt, (uint64_t) (tst->cnt / 1.0)); return 0; } ---------------- when I compile this with tcc and run it I get a core dump. The problem is that the stack is overwritten. I have a fix. ------------------------ --- a/tccgen.c 2019-10-22 19:52:48.761977245 +0200 +++ b/tccgen.c 2019-10-22 22:08:08.465825842 +0200 @@ -1203,7 +1203,7 @@ ST_FUNC void save_reg_upstack(int r, int } #endif /* special long long case */ - if ((p->r2 & VT_VALMASK) < VT_CONST) { + if (PTR_SIZE == 4 && (p->r2 & VT_VALMASK) < VT_CONST) { sv.c.i += PTR_SIZE; store(p->r2, &sv); } --------------------- But am not sure if this is the correct fix. The code generator is quite complex. Herman _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel