warn-unreachable.c revision 55f988efeb08b84c2dd9e4c05990b88c81fe2b58
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(), halt(), 34 dead(); // expected-warning {{will never be executed}} 35 36 case 3: 37 live() 38 + // expected-warning {{will never be executed}} 39 halt(); 40 dead(); 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 case 7: 76 halt() 77 + // expected-warning {{will never be executed}} 78 dead(); 79 - // expected-warning {{will never be executed}} 80 halt(); 81 } 82} 83