From 61d934fd7bba94f79a297567053c81621bbf3c3b Mon Sep 17 00:00:00 2001 From: mrdudz Date: Fri, 25 Sep 2020 16:25:32 +0200 Subject: [PATCH] test related to issue #1265 --- test/misc/Makefile | 9 ++++++++ test/misc/bug1265.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 test/misc/bug1265.c diff --git a/test/misc/Makefile b/test/misc/Makefile index f8832e77e..f04bcadbd 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -100,6 +100,15 @@ $(WORKDIR)/bug1263.$1.$2.prg: pptest2.c | $(WORKDIR) $(if $(QUIET),echo misc/bug1263.$1.$2.prg) $(NOT) $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) +# this one requires --std=c89, it fails with --std=c99 +# it fails currently at runtime +$(WORKDIR)/bug1265.$1.$2.prg: bug1265.c | $(WORKDIR) + $(if $(QUIET),echo misc/bug1265.$1.$2.prg) + $(CC65) --standard c89 -t sim$2 -$1 -o $$(@:.prg=.s) $$< $(NULLERR) + $(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR) + $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) + $(NOT) $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) $(NULLERR) + # should compile, but then hangs in an endless loop $(WORKDIR)/endless.$1.$2.prg: endless.c | $(WORKDIR) $(if $(QUIET),echo misc/endless.$1.$2.prg) diff --git a/test/misc/bug1265.c b/test/misc/bug1265.c new file mode 100644 index 000000000..469946739 --- /dev/null +++ b/test/misc/bug1265.c @@ -0,0 +1,51 @@ +/* bug #1265 - misadjusted stack from unprototyped function call */ + +#include +#include + +int failures = 0; + +char str1[10]; +char str2[10]; + +int f2 (int x) { return x == 2345 ? 23 : -1; } + +int main (void) { + int x, n; + + sprintf (str1, "%p\n", &x); + puts(str1); + x = 1234; + n = f1 (x); + sprintf (str2, "%p\n", &x); + puts(str2); + + if (strcmp(str1, str2)) { + puts("not equal"); + failures++; + } + if (n != 42) { + puts("f1 returns wrong value"); + failures++; + } + + sprintf (str1, "%p\n", &x); + puts(str1); + x = 2345; + n = f2 (x); + sprintf (str2, "%p\n", &x); + puts(str2); + + if (strcmp(str1, str2)) { + puts("not equal"); + failures++; + } + if (n != 23) { + puts("f2 returns wrong value"); + failures++; + } + + return failures; +} + +int f1 (int x) { return x == 1234 ? 42 : -1; }