Merge pull request #2702 from mrdudz/testbug2172
added repro cases from #2172 as tests
This commit is contained in:
56
test/todo/bug2172_invalid_code.c
Normal file
56
test/todo/bug2172_invalid_code.c
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
// bug #2172 - Invalid code generated for switch statement
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// cc65 -o bug2172.s -Cl -Oirs -T -t c64 bug2172.c
|
||||
int func(int expr)
|
||||
{
|
||||
switch (expr) {
|
||||
int i;
|
||||
case 0:
|
||||
i = 17;
|
||||
return i;
|
||||
default:
|
||||
i = 16;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
int err = 0;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i = 0;
|
||||
int n = 42;
|
||||
for (i = -3; i < 0; i++) {
|
||||
n = func(i);
|
||||
if ((i < -3) || (i >= 0)) {
|
||||
goto stackerr;
|
||||
}
|
||||
printf("i:%d expect:16 got:%d\n", i, n);
|
||||
if (n != 16) {
|
||||
err++;
|
||||
}
|
||||
}
|
||||
n = func(0);
|
||||
printf("i:%d expect:17 got:%d\n", 0, n);
|
||||
if (n != 17) {
|
||||
err++;
|
||||
}
|
||||
for (i = 1; i < 4; i++) {
|
||||
n = func(i);
|
||||
if ((i < 1) || (i >= 4)) {
|
||||
goto stackerr;
|
||||
}
|
||||
printf("i:%d expect:16 got:%d\n", i, n);
|
||||
if (n != 16) {
|
||||
err++;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
stackerr:
|
||||
fputs("stack messed up?\n", stdout);
|
||||
return -1;
|
||||
}
|
||||
51
test/todo/bug2172b_invalid_code.c
Normal file
51
test/todo/bug2172b_invalid_code.c
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* Just some arbitrary code, more fun with goto */
|
||||
int func(int m)
|
||||
{
|
||||
long x = -42; /* sp: -4 */
|
||||
switch (x) {
|
||||
/* return 0; // C99 only */
|
||||
int i = 42; /* sp: -6 */
|
||||
L0:
|
||||
--i;
|
||||
default:
|
||||
if (i != 0) {
|
||||
long j = 13; /* sp: -10 */
|
||||
goto L1;
|
||||
L1:
|
||||
case 0x7FFF01:
|
||||
m--;
|
||||
case 0x7EFF0001:
|
||||
case 0x7FFF0001:
|
||||
i++;
|
||||
} /* sp: -6 */
|
||||
case 0x7FFF00:
|
||||
case 0x7FFF0000:
|
||||
break;
|
||||
goto L0;
|
||||
{
|
||||
int skipped = 42; /* sp: -8 */
|
||||
case 0x7EFF00:
|
||||
case 0x7EFF0000:
|
||||
++skipped;
|
||||
} /* sp: -6 */
|
||||
} /* sp: -4 */
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
int err = 0;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int n = 42;
|
||||
n = func(7);
|
||||
if (n != 7) {
|
||||
err++;
|
||||
}
|
||||
printf("n:%d\n", n);
|
||||
return err;
|
||||
}
|
||||
Reference in New Issue
Block a user