Complete unreachable checking for switch statements.

This commit is contained in:
Kugel Fuhr
2025-07-26 09:03:27 +02:00
parent 70c1bd5e3c
commit 8f4a4040d6
7 changed files with 239 additions and 62 deletions

View File

@@ -44,7 +44,7 @@ static int f3(void)
case 2: return a+1;
default: return a+2;
}
/* Unreachable but no warning */
/* Unreachable */
return a;
}
@@ -58,11 +58,71 @@ static int f4(void)
default: return a+2;
} while (1);
}
/* Unreachable but no warning */
/* Unreachable */
return a;
}
static int f5(void)
{
do {
switch (a) {
case 1: return a;
case 2: ++a; continue;
default: return 1;
}
} while (0);
/* Unreachable */
return 2;
}
static int f6(void)
{
do {
L: switch (a) {
case 1: return a;
case 2: ++a; goto L;
default: return 1;
}
} while (0);
/* Unreachable but no warning because of "goto" */
return 2;
}
static int f7(void)
{
do {
switch (a) {
/* Unreachable */
a = 3;
case 1: return a;
case 2: ++a; continue;
default: return 1;
}
} while (0);
/* Unreachable but no warning because of weird switch */
return 2;
}
static void duff(char* to, char* from, unsigned count)
{
unsigned n = (count+7)/8;
switch (count%8) {
case 0: do { *to = *from++;
case 7: *to = *from++;
case 6: *to = *from++;
case 5: *to = *from++;
case 4: *to = *from++;
case 3: *to = *from++;
case 2: *to = *from++;
case 1: *to = *from++;
} while (--n>0);
}
}
int main(void)
{
return f1() + f2() + f3() + f4();
char x[11];
char y[11];
duff(x, y, 11);
return f1() + f2() + f3() + f4() + f5() + f6() + f7();
}