warn-unreachable.c revision 823000cdeeb2deb861dd92463d739c1e71fea5d2
1// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wunreachable-code -Wno-unused-value
2
3int halt() __attribute__((noreturn));
4int live();
5int dead();
6
7void test1() {
8  goto c;
9  d:
10  goto e;       // expected-warning {{will never be executed}}
11  c: ;
12  int i;
13  return;
14  goto b;        // expected-warning {{will never be executed}}
15  goto a;        // expected-warning {{will never be executed}}
16  b:
17  i = 1;
18  a:
19  i = 2;
20  goto f;
21  e:
22  goto d;
23  f: ;
24}
25
26void test2() {
27  switch (live()) {
28  case 1:
29    halt(),
30      dead();   // expected-warning {{will never be executed}}
31
32  case 2:
33    live(),
34      halt(),
35      dead();   // expected-warning {{will never be executed}}
36
37  case 3:
38  live()
39    + halt();
40  dead();     // expected-warning {{will never be executed}}
41
42  case 4:
43  a4:
44    live(),
45      halt();
46    goto a4;    // expected-warning {{will never be executed}}
47
48  case 5:
49    goto a5;
50  c5:
51    dead();     // expected-warning {{will never be executed}}
52    goto b5;
53  a5:
54    live(),
55      halt();
56  b5:
57    goto c5;
58
59  case 6:
60    if (live())
61      goto e6;
62    live(),
63      halt();
64  d6:
65    dead();     // expected-warning {{will never be executed}}
66    goto b6;
67  c6:
68    dead();
69    goto b6;
70  e6:
71    live(),
72      halt();
73  b6:
74    goto c6;
75  }
76}
77