diff --git a/test/misc/Makefile b/test/misc/Makefile index b131fef2e..089159cfd 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -177,6 +177,11 @@ $(WORKDIR)/flow-switch-01.$1.$2.prg: flow-switch-01.c $(ISEQUAL) | $(WORKDIR) $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLOUT) 2>$(WORKDIR)/flow-switch-01.$1.$2.out $(ISEQUAL) $(WORKDIR)/flow-switch-01.$1.$2.out flow-switch-01.ref +$(WORKDIR)/flow-switch-02.$1.$2.prg: flow-switch-02.c $(ISEQUAL) | $(WORKDIR) + $(if $(QUIET),echo misc/flow-switch-02.$1.$2.prg) + $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLOUT) 2>$(WORKDIR)/flow-switch-02.$1.$2.out + $(ISEQUAL) $(WORKDIR)/flow-switch-02.$1.$2.out flow-switch-02.ref + $(WORKDIR)/flow-while-01.$1.$2.prg: flow-while-01.c $(ISEQUAL) | $(WORKDIR) $(if $(QUIET),echo misc/flow-while-01.$1.$2.prg) $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLOUT) 2>$(WORKDIR)/flow-while-01.$1.$2.out diff --git a/test/misc/flow-switch-02.c b/test/misc/flow-switch-02.c new file mode 100644 index 000000000..f54a456b2 --- /dev/null +++ b/test/misc/flow-switch-02.c @@ -0,0 +1,107 @@ +char a, b; + +static int f1(void) +{ + switch (a) { + case 1: return 1; + case 0xFF: break; + default: return 2; + } + /* Reachable */ + return a; +} + +static int f2(void) +{ + switch (a) { + case 1: return 1; + case 0x100: break; /* Unreachable */ + default: return 2; + } + /* Unreachable despite the "break" above */ + return a; +} + +static int f3(void) +{ + + switch (a) { + case 1: + if (b > 128) { + a = 2; + break; + } else { + a = 1; + } + return a; + default: + return 2; + } + /* Reachable */ + return a; +} + +static int f4(void) +{ + + switch (a) { + case 1: + if (b > 255) { + /* Unreachable */ + a = 2; + break; + } else { + a = 1; + } + return a; + default: + return 2; + } + /* Unreachable despite the "break" above */ + return a; +} + +static int f5(void) +{ + + switch (a) { + case 1: + if (b >= 0) { + a = 2; + } else { + /* Unreachable */ + a = 1; + break; + } + return a; + default: + return 2; + } + /* Unreachable despite the "break" above */ + return a; +} + +static int f6(void) +{ + + switch (a) { + case 1: + while (0) { + /* Unreachable */ + if (b >= 128) { + a = 2; + break; + } + } + return a; + default: + return 2; + } + /* Unreachable despite the "break" above */ + return a; +} + +int main(void) +{ + return f1() + f2() + f3() + f4() + f5() + f6(); +} diff --git a/test/misc/flow-switch-02.ref b/test/misc/flow-switch-02.ref new file mode 100644 index 000000000..1012c9b42 --- /dev/null +++ b/test/misc/flow-switch-02.ref @@ -0,0 +1,10 @@ +flow-switch-02.c:18: Warning: Case value (256) out of range for switch condition type +flow-switch-02.c:22: Warning: Unreachable code +flow-switch-02.c:49: Warning: Result of comparison is always false +flow-switch-02.c:51: Warning: Unreachable code +flow-switch-02.c:61: Warning: Unreachable code +flow-switch-02.c:69: Warning: Result of comparison is always true +flow-switch-02.c:73: Warning: Unreachable code +flow-switch-02.c:81: Warning: Unreachable code +flow-switch-02.c:91: Warning: Unreachable code +flow-switch-02.c:101: Warning: Unreachable code