diff --git a/test/misc/Makefile b/test/misc/Makefile index bd4826d54..853e9d1e0 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -117,6 +117,14 @@ $(WORKDIR)/endless.$1.$2.prg: endless.c | $(WORKDIR) $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) $(NOT) $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) $(NULLERR) +# this one fails when optimization are enabled +$(WORKDIR)/bug1348.$1.$2.prg: bug1348.c | $(WORKDIR) + $(if $(QUIET),echo misc/bug1348.$1.$2.prg) + $(CC65) -Osr -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) + # these need reference data that can't be generated by a host-compiled program, # in a useful way $(WORKDIR)/limits.$1.$2.prg: limits.c $(ISEQUAL) | $(WORKDIR) diff --git a/test/misc/bug1348.c b/test/misc/bug1348.c new file mode 100644 index 000000000..913849482 --- /dev/null +++ b/test/misc/bug1348.c @@ -0,0 +1,54 @@ + +/* bug#1348, wrongly optimized integer promotion in comparison */ + +#include + +int notrandtab[] = { + 0xffff, 0x7fff, 0x3fff, 0x1fff, + 0x0fff, 0x07ff, 0x03ff, 0x01ff, + 0x00ff, 0x007f, 0x003f, 0x001f, + 0x000f, 0x0007, 0x0003, 0x0001 +}; + +unsigned char notrandcount = 0; + +int notrand(void) +{ + return notrandtab[notrandcount & 0x0f]; +} + +unsigned char n1, n2; +unsigned char i, ii, s; +unsigned char err = 0; + +unsigned char cmptab[] = { + 0xff, 0x7f, 0x3f, 0x1f, + 0x0f, 0x07, 0x03, 0x01, + 0x80, 0x40, 0x20, 0x10, + 0x08, 0x04, 0x02, 0x01 +}; + +int main(void) +{ + for (ii = 0; ii < 16; ++ii) { + s = cmptab[ii]; + for (i = 0; i < 16; ++i) { + n1 = n2 = 0; + if ((notrand() & 0xff) > s) { + n1 = 1; + } + if ((notrand() & 0xffu) > s) { + n2 = 1; + } + printf("%5d>%3d %d(%02x) %d(%02x) %s\n", + notrandtab[notrandcount & 0x0f], s, + n1, (notrand() & 0xff), + n2, (notrand() & 0xffu), + n1 == n2 ? "=" : "!=" + ); + if (n1 != n2) err = 1; + notrandcount++; + } + } + return err; +}