1 /* This checks various ways of dead code inside if statements
2 where there are non-obvious ways of how the code is actually
3 not dead due to reachable by labels. */
4 extern int printf (const char *, ...);
5 static void kb_wait_1(void)
7 unsigned long timeout
= 2;
9 /* Here the else arm is a statement expression that's supposed
10 to be suppressed. The label inside the while would unsuppress
11 code generation again if not handled correctly. And that
12 would wreak havoc to the cond-expression because there's no
13 jump-around emitted, the whole statement expression really
14 needs to not generate code (perhaps except useless forward jumps). */
16 printf("timeout=%ld\n", timeout
) :
32 static void foo(int i
)
35 printf ("g=%d\n", global
);
38 static int check(void)
40 printf ("check %d\n", global
);
44 static void dowhile(void)
50 } else if (global
== 2) {
53 /* The following break shouldn't disable the check() call,
54 as it's reachable by the continues above. */
59 static void nondead_after_dead_return(void)
61 /* This statement expr is not entered, and hence that fact that it
62 doesn't fall-through should not influence the surrounding code. */
64 printf ("nondead works\n");
73 /* Simple test of dead code at first sight which isn't actually dead. */
83 /* Some more non-obvious uses where the problems are loops, so that even
84 the first loop statements aren't actually dead. */
96 /* The same with statement expressions. One might be tempted to
97 handle them specially by counting if inside statement exprs and
98 not unsuppressing code at loops at all then.
99 See kb_wait_1 for the other side of the medal where that wouldn't work. */
106 printf ("SEtwice\n");
113 /* The other two loop forms: */
136 /* And check that case and default labels have the same effect
137 of disabling code suppression. */
154 printf ("caseok2\n");
162 nondead_after_dead_return();