diff --git a/test/misc/Makefile b/test/misc/Makefile index 6a5611c68..3e8b0c157 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -152,7 +152,37 @@ $(WORKDIR)/bug2655.$1.$2.prg: bug2655.c $(ISEQUAL) | $(WORKDIR) $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLOUT) 2>$(WORKDIR)/bug2655.$1.$2.out $(ISEQUAL) $(WORKDIR)/bug2655.$1.$2.out bug2655.ref -$(WORKDIR)/limits.$1.$2.prg: limits.c $(ISEQUAL) | $(WORKDIR) +$(WORKDIR)/flow-do-01.$1.$2.prg: flow-do-01.c $(ISEQUAL) | $(WORKDIR) + $(if $(QUIET),echo misc/flow-do-01.$1.$2.prg) + $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLOUT) 2>$(WORKDIR)/flow-do-01.$1.$2.out + $(ISEQUAL) $(WORKDIR)/flow-do-01.$1.$2.out flow-do-01.ref + +$(WORKDIR)/flow-if-01.$1.$2.prg: flow-if-01.c $(ISEQUAL) | $(WORKDIR) + $(if $(QUIET),echo misc/flow-if-01.$1.$2.prg) + $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLOUT) 2>$(WORKDIR)/flow-if-01.$1.$2.out + $(ISEQUAL) $(WORKDIR)/flow-if-01.$1.$2.out flow-if-01.ref + +$(WORKDIR)/flow-if-02.$1.$2.prg: flow-if-02.c $(ISEQUAL) | $(WORKDIR) + $(if $(QUIET),echo misc/flow-if-02.$1.$2.prg) + $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLOUT) 2>$(WORKDIR)/flow-if-02.$1.$2.out + $(ISEQUAL) $(WORKDIR)/flow-if-02.$1.$2.out flow-if-02.ref + +$(WORKDIR)/flow-switch-01.$1.$2.prg: flow-switch-01.c $(ISEQUAL) | $(WORKDIR) + $(if $(QUIET),echo misc/flow-switch-01.$1.$2.prg) + $(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-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 + $(ISEQUAL) $(WORKDIR)/flow-while-01.$1.$2.out flow-while-01.ref + +$(WORKDIR)/flow-while-02.$1.$2.prg: flow-while-02.c $(ISEQUAL) | $(WORKDIR) + $(if $(QUIET),echo misc/flow-while-02.$1.$2.prg) + $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLOUT) 2>$(WORKDIR)/flow-while-02.$1.$2.out + $(ISEQUAL) $(WORKDIR)/flow-while-02.$1.$2.out flow-while-02.ref + +$(WORKDIR)/limits.$1.$2.prg: limits.c $(ISEQUAL) | $(WORKDIR) $(if $(QUIET),echo misc/limits.$1.$2.prg) $(CC65) -t sim$2 -$1 -o $$(@:.prg=.s) $$< $(NULLOUT) $(CATERR) $(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR) diff --git a/test/misc/bug2655.ref b/test/misc/bug2655.ref index 99e2d6698..7b1fd2e86 100644 --- a/test/misc/bug2655.ref +++ b/test/misc/bug2655.ref @@ -1,2 +1,2 @@ -bug2655.c:5: Warning: Unreachable code -bug2655.c:12: Warning: Unreachable code +bug2655.c:6: Warning: Unreachable code +bug2655.c:13: Warning: Unreachable code diff --git a/test/misc/flow-do-01.c b/test/misc/flow-do-01.c new file mode 100644 index 000000000..7d4cb86e2 --- /dev/null +++ b/test/misc/flow-do-01.c @@ -0,0 +1,87 @@ +int a; + +static int f1(void) +{ + do { + return a; + } while (a == 2); + /* Unreachable */ + a = 2; + return a; +} + +static int f2(void) +{ + do { + return a; + } while (1); + /* Unreachable */ + a = 2; + return a; +} + +static int f3(void) +{ + do { + return a; + } while (0); + /* Unreachable */ + a = 2; + return a; +} + +static int f4(void) +{ + do { + continue; /* Turns do/while into an endless loop */ + } while (0); + /* Unreachable */ + a = 2; + return a; +} + +static int f5(void) +{ + do { + if (a == 2) { + break; + } + return a; + } while (0); + /* Reachable */ + a = 2; + return a; +} + +static int f6(void) +{ + do { + if (a == 2) { + break; + } + continue; + } while (0); + /* Reachable */ + a = 2; + return a; +} + +static int f7(void) +{ + do { + if (a == 2) { + return a; + } else { + continue; + } + } while (1); + /* Unreachable */ + a = 2; + return a; +} + +int main(void) +{ + return f1() + f2() + f3() + f4() + f5() + f6() + f7(); +} + diff --git a/test/misc/flow-do-01.ref b/test/misc/flow-do-01.ref new file mode 100644 index 000000000..d082b9406 --- /dev/null +++ b/test/misc/flow-do-01.ref @@ -0,0 +1,5 @@ +flow-do-01.c:9: Warning: Unreachable code +flow-do-01.c:19: Warning: Unreachable code +flow-do-01.c:29: Warning: Unreachable code +flow-do-01.c:39: Warning: Unreachable code +flow-do-01.c:79: Warning: Unreachable code diff --git a/test/misc/flow-if-01.c b/test/misc/flow-if-01.c new file mode 100644 index 000000000..533a55c11 --- /dev/null +++ b/test/misc/flow-if-01.c @@ -0,0 +1,62 @@ +int a, b; + +static int f1(void) +{ + if (a == 1) { + return 1; + } + /* Reachable */ + a = 2; + return a; +} + +static int f2(void) +{ + if (a == 1) { + a = 2; + } else { + return 1; + } + /* Reachable */ + return a; +} + +static int f3(void) +{ + if (a == 1) { + return 1; + } else { + a = 2; + } + /* Reachable */ + return a; +} + +static int f4(void) +{ + if (a == 1) { + return 1; + } else { + return 0; + } + /* Unreachable */ + a = 2; +} + +static int f5(void) +{ + if (1) { + return 1; + } else { + /* Unreachable */ + return 0; + } + /* Unreachable */ + a = 2; +} + +int main(void) +{ + return f1() + f2() + f3() + f4() + f5(); +} + diff --git a/test/misc/flow-if-01.ref b/test/misc/flow-if-01.ref new file mode 100644 index 000000000..f7c547d23 --- /dev/null +++ b/test/misc/flow-if-01.ref @@ -0,0 +1,3 @@ +flow-if-01.c:43: Warning: Unreachable code +flow-if-01.c:52: Warning: Unreachable code +flow-if-01.c:55: Warning: Unreachable code diff --git a/test/misc/flow-if-02.c b/test/misc/flow-if-02.c new file mode 100644 index 000000000..6e30d9d5f --- /dev/null +++ b/test/misc/flow-if-02.c @@ -0,0 +1,49 @@ +int a, b; + +static int f1(void) +{ + if (0) { + /* Unreachable but no warning */ + } else { + a = 2; + } + return a; +} + +static int f2(void) +{ + if (0) { + /* Unreachable */ + a = 1; + } else { + a = 2; + } + return a; +} + +static int f3(void) +{ + if (1) { + a = 2; + } else { + /* Unreachable but no warning */ + } + return a; +} + +static int f4(void) +{ + if (1) { + a = 2; + } else { + /* Unreachable */ + a = 1; + } + return a; +} + +int main(void) +{ + return f1() + f2() + f3() + f4(); +} + diff --git a/test/misc/flow-if-02.ref b/test/misc/flow-if-02.ref new file mode 100644 index 000000000..91547afd7 --- /dev/null +++ b/test/misc/flow-if-02.ref @@ -0,0 +1,2 @@ +flow-if-02.c:17: Warning: Unreachable code +flow-if-02.c:40: Warning: Unreachable code diff --git a/test/misc/flow-switch-01.c b/test/misc/flow-switch-01.c new file mode 100644 index 000000000..b55c2f70f --- /dev/null +++ b/test/misc/flow-switch-01.c @@ -0,0 +1,68 @@ +int a; + +static int f1(void) +{ + switch (a) { + /* Unreachable */ + a = 3; + case 1: + a = 2; + break; + case 2: + a = 1; + break; + default: + a = 0; + break; + } + /* Reachable */ + return a; +} + +static int f2(void) +{ + switch (a) { + /* Reachable */ +L: a = 3; + case 1: + goto L; + case 2: + a = 1; + break; + default: + a = 0; + break; + } + /* Reachable */ + return a; +} + +static int f3(void) +{ + switch (a) { + case 1: return a; + case 2: return a+1; + default: return a+2; + } + /* Unreachable but no warning */ + return a; +} + +static int f4(void) +{ + switch (a) { + /* No warning */ + do { + case 1: ++a; continue; + case 2: return a+1; + default: return a+2; + } while (1); + } + /* Unreachable but no warning */ + return a; +} + +int main(void) +{ + return f1() + f2() + f3() + f4(); +} diff --git a/test/misc/flow-switch-01.ref b/test/misc/flow-switch-01.ref new file mode 100644 index 000000000..61391476b --- /dev/null +++ b/test/misc/flow-switch-01.ref @@ -0,0 +1 @@ +flow-switch-01.c:7: Warning: Unreachable code diff --git a/test/misc/flow-while-01.c b/test/misc/flow-while-01.c new file mode 100644 index 000000000..5ba4f8d9f --- /dev/null +++ b/test/misc/flow-while-01.c @@ -0,0 +1,70 @@ +int a; + +static int f1(void) +{ + while (1) { + ++a; + } + /* Unreachable */ + a = 2; + return a; +} + +static int f2(void) +{ + while (1) { + ++a; + if (a == 5) break; + } + /* Reachable */ + a = 2; + return a; +} + +static int f3(void) +{ + while (1) { + ++a; + return a; + } + /* Unreachable */ + a = 2; +} + +static int f4(void) +{ + while (0) { + /* Unreachable */ + ++a; + return a; + } + /* Reachable */ + a = 2; + return 0; +} + +static int f5(void) +{ + while (1) { + ++a; + if (a == 4) goto L; + return a; + } + /* Reachable via L */ +L: a = 2; +} + +static int f6(void) +{ + while (0) { + /* Unreachable but no warning */ + } + a = 2; + return a; +} + +int main(void) +{ + return f1() + f2() + f3() + f4() + f5() + f6(); +} + diff --git a/test/misc/flow-while-01.ref b/test/misc/flow-while-01.ref new file mode 100644 index 000000000..489d92ad1 --- /dev/null +++ b/test/misc/flow-while-01.ref @@ -0,0 +1,3 @@ +flow-while-01.c:9: Warning: Unreachable code +flow-while-01.c:31: Warning: Unreachable code +flow-while-01.c:38: Warning: Unreachable code diff --git a/test/misc/flow-while-02.c b/test/misc/flow-while-02.c new file mode 100644 index 000000000..11ea2c0c4 --- /dev/null +++ b/test/misc/flow-while-02.c @@ -0,0 +1,74 @@ +int a; + +static int f1(void) +{ + while (1) { + while (0) { + /* Unreachable */ + ++a; + } + } + /* Unreachable */ + a = 2; + return a; +} + +static int f2(void) +{ + while (1) { + do { + return a; + } while (0); + /* Unreachable */ + break; + } + /* Unreachable but no warning */ + a = 2; + return a; +} + +static int f3(void) +{ + do { + while (1) { + break; + } + } while (1); + /* Unreachable */ + a = 2; + return a; +} + +static int f4(void) +{ + do { + while (1) { + return a; + } + } while (0); + /* Unreachable */ + a = 2; + return a; +} + +static int f5(void) +{ + do { + do { + if (a == 2) { + return a; + } else { + continue; + } + } while (0); + } while (0); + /* Unreachable */ + a = 2; + return a; +} + +int main(void) +{ + return f1()/ + f2() + f3() + f4() + f5(); +} + diff --git a/test/misc/flow-while-02.ref b/test/misc/flow-while-02.ref new file mode 100644 index 000000000..2609f395a --- /dev/null +++ b/test/misc/flow-while-02.ref @@ -0,0 +1,6 @@ +flow-while-02.c:8: Warning: Unreachable code +flow-while-02.c:12: Warning: Unreachable code +flow-while-02.c:23: Warning: Unreachable code +flow-while-02.c:38: Warning: Unreachable code +flow-while-02.c:50: Warning: Unreachable code +flow-while-02.c:66: Warning: Unreachable code