1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 23:29:39 +00:00

added testcase for issue #1937

This commit is contained in:
mrdudz 2021-02-09 19:50:08 +01:00
parent 6c90f3e2d2
commit ab8bb26868
2 changed files with 63 additions and 0 deletions

View File

@ -108,6 +108,14 @@ $(WORKDIR)/bug1265.$1.$2.prg: bug1265.c | $(WORKDIR)
$(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR)
$(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) $(NULLERR)
# this one fails with optimizations, without OptBoolTrans it works
$(WORKDIR)/bug1397.$1.$2.prg: bug1397.c | $(WORKDIR)
$(if $(QUIET),echo misc/bug1397.$1.$2.prg)
$(CC65) -O --disable-opt OptBoolTrans -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)
$(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)

55
test/misc/bug1397.c Normal file
View File

@ -0,0 +1,55 @@
/* bug #1937 - Incorrect Behavior Related to OptBoolTrans */
#include <stdio.h>
unsigned char c;
int *p;
void f1(void) {
int i = 1;
int *pa = (int *)0xaaaa;
int *pb = (int *)0xbbbb;
p = (i == 0) ? pa : pb;
c = 0x5a;
}
struct data_t {
unsigned char c;
int *p;
};
struct data_t data;
void f2(void) {
int i = 1;
int *pa = (int *)0xcccc;
int *pb = (int *)0xdddd;
struct data_t *po = &data;
po->p = (i == 0) ? pa : pb;
po->c = 0xa5;
}
int ret = 0;
int main(void) {
f1();
if (c != 0x5a) {
ret++;
}
printf("c: %hhx\n", c);
printf("p: %p\n", p);
f2();
if (data.c != 0xa5) {
ret++;
}
printf("c: %hhx\n", data.c);
printf("p: %p\n", data.p);
printf("failures: %d\n", ret);
return ret;
}