Improved flow analysis in general and especially for "for" loops. Added more
tests.
This commit is contained in:
@@ -157,6 +157,11 @@ $(WORKDIR)/flow-do-01.$1.$2.prg: flow-do-01.c $(ISEQUAL) | $(WORKDIR)
|
||||
$(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-for-01.$1.$2.prg: flow-for-01.c $(ISEQUAL) | $(WORKDIR)
|
||||
$(if $(QUIET),echo misc/flow-for-01.$1.$2.prg)
|
||||
$(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLOUT) 2>$(WORKDIR)/flow-for-01.$1.$2.out
|
||||
$(ISEQUAL) $(WORKDIR)/flow-for-01.$1.$2.out flow-for-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
|
||||
|
||||
90
test/misc/flow-for-01.c
Normal file
90
test/misc/flow-for-01.c
Normal file
@@ -0,0 +1,90 @@
|
||||
int a;
|
||||
|
||||
static int f1(void)
|
||||
{
|
||||
for (;;) {
|
||||
++a;
|
||||
}
|
||||
/* Unreachable */
|
||||
a = 2;
|
||||
return a;
|
||||
}
|
||||
|
||||
static int f2(void)
|
||||
{
|
||||
for (;1;) {
|
||||
++a;
|
||||
}
|
||||
/* Unreachable */
|
||||
a = 2;
|
||||
return a;
|
||||
}
|
||||
|
||||
static int f3(void)
|
||||
{
|
||||
for (;;) {
|
||||
++a;
|
||||
if (a == 5) break;
|
||||
}
|
||||
/* Reachable */
|
||||
a = 2;
|
||||
return a;
|
||||
}
|
||||
|
||||
static int f4(void)
|
||||
{
|
||||
for (;;) {
|
||||
++a;
|
||||
return a;
|
||||
}
|
||||
/* Unreachable */
|
||||
a = 2;
|
||||
}
|
||||
|
||||
static int f5(void)
|
||||
{
|
||||
for (;0;) {
|
||||
/* Unreachable */
|
||||
++a;
|
||||
return a;
|
||||
}
|
||||
/* Reachable */
|
||||
a = 2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int f6(void)
|
||||
{
|
||||
for (;;) {
|
||||
++a;
|
||||
if (a == 4) goto L;
|
||||
return a;
|
||||
}
|
||||
/* Reachable via L */
|
||||
L: a = 2;
|
||||
}
|
||||
|
||||
static int f7(void)
|
||||
{
|
||||
for (;0;) {
|
||||
/* Unreachable but no warning */
|
||||
}
|
||||
a = 2;
|
||||
return a;
|
||||
}
|
||||
|
||||
static int f8(void)
|
||||
{
|
||||
for (;a;) {
|
||||
return a;
|
||||
}
|
||||
/* Reachable */
|
||||
a = 2;
|
||||
return a;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return f1() + f2() + f3() + f4() + f5() + f6() + f7() + f8();
|
||||
}
|
||||
|
||||
4
test/misc/flow-for-01.ref
Normal file
4
test/misc/flow-for-01.ref
Normal file
@@ -0,0 +1,4 @@
|
||||
flow-for-01.c:9: Warning: Unreachable code
|
||||
flow-for-01.c:19: Warning: Unreachable code
|
||||
flow-for-01.c:41: Warning: Unreachable code
|
||||
flow-for-01.c:48: Warning: Unreachable code
|
||||
@@ -63,8 +63,18 @@ static int f6(void)
|
||||
return a;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
static int f7(void)
|
||||
{
|
||||
return f1() + f2() + f3() + f4() + f5() + f6();
|
||||
while (a) {
|
||||
return a;
|
||||
}
|
||||
/* Reachable */
|
||||
a = 2;
|
||||
return a;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return f1() + f2() + f3() + f4() + f5() + f6() + f7();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ static int f2(void)
|
||||
/* Unreachable */
|
||||
break;
|
||||
}
|
||||
/* Unreachable but no warning */
|
||||
/* Unreachable */
|
||||
a = 2;
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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:26: 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
|
||||
|
||||
Reference in New Issue
Block a user