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