From 0db23a8951ee43e8fdcb4377a58b045af6142983 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sun, 23 May 2021 18:55:06 +0200 Subject: [PATCH] testcase for issue #263 --- test/val/bug263.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/val/bug263.c diff --git a/test/val/bug263.c b/test/val/bug263.c new file mode 100644 index 000000000..6f3f8f57e --- /dev/null +++ b/test/val/bug263.c @@ -0,0 +1,49 @@ + +/* issue #263 - cc65 miscompiles w/ a static variable and -O */ + +#include +#include + +int failures = 0; + +void __fastcall__ set_vram_update(unsigned char *ptr) +{ + printf("set_vram_update: %04x\n", ptr); + if (ptr != NULL) { + failures++; + } +} + +unsigned char __fastcall__ ppu_wait_nmi(void) +{ + // we need to make sure somehow the akku is not zero before the break + return 0x1234; +} + +unsigned char ctrl, ret, i; + +unsigned char gameloop (void) +{ + ctrl = 0; + ret = 0; + while(1) { + if (ctrl & 1) { + while (--i) { + ppu_wait_nmi(); + } + break; + } + ctrl = 1; + } + // This will pass garbage, not NULL. + set_vram_update(NULL); + return ret; +} + +int main(void) +{ + gameloop(); + printf("failures: %d\n", failures); + return failures; +} +