Home | History | Annotate | Download | only in Sema
      1 // RUN: %clang_cc1 -fsyntax-only -verify -Wtautological-overlap-compare %s
      2 
      3 #define mydefine 2
      4 
      5 void f(int x) {
      6   int y = 0;
      7 
      8   // > || <
      9   if (x > 2 || x < 1) { }
     10   if (x > 2 || x < 2) { }
     11   if (x != 2 || x != 3) { } // expected-warning {{overlapping comparisons always evaluate to true}}
     12   if (x > 2 || x < 3) { } // expected-warning {{overlapping comparisons always evaluate to true}}
     13   if (x > 0 || x < 0) { }
     14 
     15   if (x > 2 || x <= 1) { }
     16   if (x > 2 || x <= 2) { } // expected-warning {{overlapping comparisons always evaluate to true}}
     17   if (x > 2 || x <= 3) { } // expected-warning {{overlapping comparisons always evaluate to true}}
     18 
     19   if (x >= 2 || x < 1) { }
     20   if (x >= 2 || x < 2) { } // expected-warning {{overlapping comparisons always evaluate to true}}
     21   if (x >= 2 || x < 3) { } // expected-warning {{overlapping comparisons always evaluate to true}}
     22 
     23   if (x >= 2 || x <= 1) { } // expected-warning {{overlapping comparisons always evaluate to true}}
     24   if (x >= 2 || x <= 2) { } // expected-warning {{overlapping comparisons always evaluate to true}}
     25   if (x >= 2 || x <= 3) { } // expected-warning {{overlapping comparisons always evaluate to true}}
     26   if (x >= 0 || x <= 0) { } // expected-warning {{overlapping comparisons always evaluate to true}}
     27 
     28   // > && <
     29   if (x > 2 && x < 1) { }  // expected-warning {{overlapping comparisons always evaluate to false}}
     30   if (x > 2 && x < 2) { }  // expected-warning {{overlapping comparisons always evaluate to false}}
     31   if (x > 2 && x < 3) { }  // expected-warning {{overlapping comparisons always evaluate to false}}
     32   if (x > 0 && x < 1) { }  // expected-warning {{overlapping comparisons always evaluate to false}}
     33 
     34   if (x > 2 && x <= 1) { }  // expected-warning {{overlapping comparisons always evaluate to false}}
     35   if (x > 2 && x <= 2) { }  // expected-warning {{overlapping comparisons always evaluate to false}}
     36   if (x > 2 && x <= 3) { }
     37 
     38   if (x >= 2 && x < 1) { }  // expected-warning {{overlapping comparisons always evaluate to false}}
     39   if (x >= 2 && x < 2) { }  // expected-warning {{overlapping comparisons always evaluate to false}}
     40   if (x >= 2 && x < 3) { }
     41   if (x >= 0 && x < 0) { }  // expected-warning {{overlapping comparisons always evaluate to false}}
     42 
     43   if (x >= 2 && x <= 1) { }  // expected-warning {{overlapping comparisons always evaluate to false}}
     44   if (x >= 2 && x <= 2) { }
     45   if (x >= 2 && x <= 3) { }
     46 
     47   // !=, ==, ..
     48   if (x != 2 || x != 3) { }  // expected-warning {{overlapping comparisons always evaluate to true}}
     49   if (x != 2 || x < 3) { }   // expected-warning {{overlapping comparisons always evaluate to true}}
     50   if (x == 2 && x == 3) { }  // expected-warning {{overlapping comparisons always evaluate to false}}
     51   if (x == 2 && x > 3) { }   // expected-warning {{overlapping comparisons always evaluate to false}}
     52   if (x == 3 && x < 0) { }  // expected-warning {{overlapping comparisons always evaluate to false}}
     53   if (3 == x && x < 0) { }  // expected-warning {{overlapping comparisons always evaluate to false}}
     54 
     55   if (x == mydefine && x > 3) { }
     56   if (x == (mydefine + 1) && x > 3) { }
     57 }
     58 
     59 // Don't generate a warning here.
     60 void array_out_of_bounds() {
     61   int x;
     62   int buffer[4];
     63   x = (-7 > 0) ? (buffer[-7]) : 0;
     64 }
     65