1*0a6a1f1dSLionel Sambuc// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wunreachable-code-aggressive -Wno-unused-value -Wno-covered-switch-default 2f4a2713aSLionel Sambuc 3f4a2713aSLionel Sambuc// This previously triggered a warning from -Wunreachable-code because of 4f4a2713aSLionel Sambuc// a busted CFG. 5f4a2713aSLionel Sambuctypedef signed char BOOL; 6f4a2713aSLionel SambucBOOL radar10989084() { 7f4a2713aSLionel Sambuc @autoreleasepool { // no-warning 8f4a2713aSLionel Sambuc return __objc_yes; 9f4a2713aSLionel Sambuc } 10f4a2713aSLionel Sambuc} 11f4a2713aSLionel Sambuc 12f4a2713aSLionel Sambuc// Test the warning works. 13f4a2713aSLionel Sambucvoid test_unreachable() { 14f4a2713aSLionel Sambuc return; 15f4a2713aSLionel Sambuc return; // expected-warning {{will never be executed}} 16f4a2713aSLionel Sambuc} 17f4a2713aSLionel Sambuc 18*0a6a1f1dSLionel Sambuc#define NO __objc_no 19*0a6a1f1dSLionel Sambuc#define YES __objc_yes 20*0a6a1f1dSLionel Sambuc#define CONFIG NO 21*0a6a1f1dSLionel Sambuc 22*0a6a1f1dSLionel Sambuc// Test that 'NO' and 'YES' are not treated as configuration macros. 23*0a6a1f1dSLionel Sambucint test_NO() { 24*0a6a1f1dSLionel Sambuc if (NO) 25*0a6a1f1dSLionel Sambuc return 1; // expected-warning {{will never be executed}} 26*0a6a1f1dSLionel Sambuc else 27*0a6a1f1dSLionel Sambuc return 0; 28*0a6a1f1dSLionel Sambuc} 29*0a6a1f1dSLionel Sambuc 30*0a6a1f1dSLionel Sambucint test_YES() { 31*0a6a1f1dSLionel Sambuc if (YES) 32*0a6a1f1dSLionel Sambuc return 1; 33*0a6a1f1dSLionel Sambuc else 34*0a6a1f1dSLionel Sambuc return 0; // expected-warning {{will never be executed}} 35*0a6a1f1dSLionel Sambuc} 36*0a6a1f1dSLionel Sambuc 37*0a6a1f1dSLionel Sambucint test_CONFIG() { 38*0a6a1f1dSLionel Sambuc if (CONFIG) 39*0a6a1f1dSLionel Sambuc return 1; 40*0a6a1f1dSLionel Sambuc else 41*0a6a1f1dSLionel Sambuc return 0; 42*0a6a1f1dSLionel Sambuc} 43*0a6a1f1dSLionel Sambuc 44*0a6a1f1dSLionel Sambuc// FIXME: This should at some point report a warning 45*0a6a1f1dSLionel Sambuc// that the loop increment is unreachable. 46*0a6a1f1dSLionel Sambucvoid test_loop_increment(id container) { 47*0a6a1f1dSLionel Sambuc for (id x in container) { // no-warning 48*0a6a1f1dSLionel Sambuc break; 49*0a6a1f1dSLionel Sambuc } 50*0a6a1f1dSLionel Sambuc} 51*0a6a1f1dSLionel Sambuc 52*0a6a1f1dSLionel Sambucvoid calledFun() {} 53*0a6a1f1dSLionel Sambuc 54*0a6a1f1dSLionel Sambuc// Test "silencing" with parentheses. 55*0a6a1f1dSLionel Sambucvoid test_with_paren_silencing(int x) { 56*0a6a1f1dSLionel Sambuc if (NO) calledFun(); // expected-warning {{will never be executed}} expected-note {{silence by adding parentheses to mark code as explicitly dead}} 57*0a6a1f1dSLionel Sambuc if ((NO)) calledFun(); // no-warning 58*0a6a1f1dSLionel Sambuc 59*0a6a1f1dSLionel Sambuc if (YES) // expected-note {{silence by adding parentheses to mark code as explicitly dead}} 60*0a6a1f1dSLionel Sambuc calledFun(); 61*0a6a1f1dSLionel Sambuc else 62*0a6a1f1dSLionel Sambuc calledFun(); // expected-warning {{will never be executed}} 63*0a6a1f1dSLionel Sambuc 64*0a6a1f1dSLionel Sambuc if ((YES)) 65*0a6a1f1dSLionel Sambuc calledFun(); 66*0a6a1f1dSLionel Sambuc else 67*0a6a1f1dSLionel Sambuc calledFun(); // no-warning 68*0a6a1f1dSLionel Sambuc 69*0a6a1f1dSLionel Sambuc if (!YES) // expected-note {{silence by adding parentheses to mark code as explicitly dead}} 70*0a6a1f1dSLionel Sambuc calledFun(); // expected-warning {{code will never be executed}} 71*0a6a1f1dSLionel Sambuc else 72*0a6a1f1dSLionel Sambuc calledFun(); 73*0a6a1f1dSLionel Sambuc 74*0a6a1f1dSLionel Sambuc if ((!YES)) 75*0a6a1f1dSLionel Sambuc calledFun(); // no-warning 76*0a6a1f1dSLionel Sambuc else 77*0a6a1f1dSLionel Sambuc calledFun(); 78*0a6a1f1dSLionel Sambuc 79*0a6a1f1dSLionel Sambuc if (!(YES)) 80*0a6a1f1dSLionel Sambuc calledFun(); // no-warning 81*0a6a1f1dSLionel Sambuc else 82*0a6a1f1dSLionel Sambuc calledFun(); 83*0a6a1f1dSLionel Sambuc} 84*0a6a1f1dSLionel Sambuc 85