bool-compare.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. void f(int x, int y, int z) {
  3. int a,b;
  4. if ((a > 2) > 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}}
  5. if (a > b) {} // no warning
  6. if (a < b) {} // no warning
  7. if (a >= b) {} // no warning
  8. if (a <= b) {} // no warning
  9. if (a == b) {} // no warning
  10. if (a != b) {} // no warning
  11. if (a > 0) {} // no warning
  12. if (a > 1) {} // no warning
  13. if (a > 2) {} // no warning
  14. if (a >= 0) {} // no warning
  15. if (a >= 1) {} // no warning
  16. if (a >= 2) {} // no warning
  17. if (a >= -1) {} // no warning
  18. if (a <= 0) {} // no warning
  19. if (a <= 1) {} // no warning
  20. if (a <= 2) {} // no warning
  21. if (a <= -1) {} // no warning
  22. if (!a > 0) {} // no warning
  23. if (!a > 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}}
  24. if (!a > 2) {} // expected-warning {{comparison of constant 2 with boolean expression is always false}}
  25. if (!a > y) {} // no warning
  26. if (!a > b) {} // no warning
  27. if (!a > -1) {} // expected-warning {{comparison of constant -1 with boolean expression is always true}}
  28. if (!a < 0) {} // expected-warning {{comparison of constant 0 with boolean expression is always false}}
  29. if (!a < 1) {} // no warning
  30. if (!a < 2) {} // expected-warning {{comparison of constant 2 with boolean expression is always true}}
  31. if (!a < y) {} // no warning
  32. if (!a < b) {} // no warning
  33. if (!a < -1) {} // expected-warning {{comparison of constant -1 with boolean expression is always false}}
  34. if (!a >= 0) {} // expected-warning {{comparison of constant 0 with boolean expression is always true}}
  35. if (!a >= 1) {} // no warning
  36. if (!a >= 2) {} // expected-warning {{comparison of constant 2 with boolean expression is always false}}
  37. if (!a >= y) {} // no warning
  38. if (!a >= b) {} // no warning
  39. if (!a >= -1) {} // expected-warning {{comparison of constant -1 with boolean expression is always true}}
  40. if (!a <= 0) {} // no warning
  41. if (!a <= 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always true}}
  42. if (!a <= 2) {} // expected-warning {{comparison of constant 2 with boolean expression is always true}}
  43. if (!a <= y) {} // no warning
  44. if (!a <= b) {} // no warning
  45. if (!a <= -1) {} // expected-warning {{comparison of constant -1 with boolean expression is always false}}
  46. if ((a||b) > 0) {} // no warning
  47. if ((a||b) > 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}}
  48. if ((a||b) > 4) {} // expected-warning {{comparison of constant 4 with boolean expression is always false}}
  49. if ((a||b) > -1) {}// expected-warning {{comparison of constant -1 with boolean expression is always true}}
  50. if ((a&&b) > 0) {} // no warning
  51. if ((a&&b) > 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}}
  52. if ((a&&b) > 4) {} // expected-warning {{comparison of constant 4 with boolean expression is always false}}
  53. if ((a<y) > 0) {} // no warning
  54. if ((a<y) > 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}}
  55. if ((a<y) > 4) {} // expected-warning {{comparison of constant 4 with boolean expression is always false}}
  56. if ((a<y) > z) {} // no warning
  57. if ((a<y) > -1) {} // expected-warning {{comparison of constant -1 with boolean expression is always true}}
  58. if ((a<y) == 0) {} // no warning
  59. if ((a<y) == 1) {} // no warning
  60. if ((a<y) == 2) {} // expected-warning {{comparison of constant 2 with boolean expression is always false}}
  61. if ((a<y) == z) {} // no warning
  62. if ((a<y) == -1) {}// expected-warning {{comparison of constant -1 with boolean expression is always false}}
  63. if ((a<y) != 0) {} // no warning
  64. if ((a<y) != 1) {} // no warning
  65. if ((a<y) != 2) {} // expected-warning {{comparison of constant 2 with boolean expression is always true}}
  66. if ((a<y) != z) {} // no warning
  67. if ((a<y) != -1) {}// expected-warning {{comparison of constant -1 with boolean expression is always true}}
  68. if ((a<y) == z) {} // no warning
  69. if (a>y<z) {} // no warning
  70. if ((a<y) > z) {} // no warning
  71. if((a<y)>(z<y)) {} // no warning
  72. if((a<y)==(z<y)){} // no warning
  73. if((a<y)!=(z<y)){} // no warning
  74. if((z==x)<(y==z)){}// no warning
  75. if((a<y)!=((z==x)<(y==z))){} //no warning
  76. if (0 > !a) {} // expected-warning {{comparison of constant 0 with boolean expression is always false}}
  77. if (1 > !a) {} // no warning
  78. if (2 > !a) {} // expected-warning {{comparison of constant 2 with boolean expression is always true}}
  79. if (y > !a) {} // no warning
  80. if (-1 > !a) {} // expected-warning {{comparison of constant -1 with boolean expression is always false}}
  81. if (0 < !a) {} // no warning
  82. if (1 < !a) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}}
  83. if (2 < !a) {} // expected-warning {{comparison of constant 2 with boolean expression is always false}}
  84. if (y < !a) {} // no warning
  85. if (-1 < !a) {} // expected-warning {{comparison of constant -1 with boolean expression is always true}}
  86. if (0 >= !a) {} // no warning
  87. if (1 >= !a) {} // expected-warning {{comparison of constant 1 with boolean expression is always true}}
  88. if (2 >= !a) {} // expected-warning {{comparison of constant 2 with boolean expression is always true}}
  89. if (y >= !a) {} // no warning
  90. if (-1 >= !a) {} // expected-warning {{comparison of constant -1 with boolean expression is always false}}
  91. if (0 <= !a) {} // expected-warning {{comparison of constant 0 with boolean expression is always true}}
  92. if (1 <= !a) {} // no warning
  93. if (2 <= !a) {} // expected-warning {{comparison of constant 2 with boolean expression is always false}}
  94. if (y <= !a) {} // no warning
  95. if (-1 <= !a) {} // expected-warning {{comparison of constant -1 with boolean expression is always true}}
  96. if (0 > (a||b)) {} // expected-warning {{comparison of constant 0 with boolean expression is always false}}
  97. if (1 > (a||b)) {} // no warning
  98. if (4 > (a||b)) {} // expected-warning {{comparison of constant 4 with boolean expression is always true}}
  99. if (0 > (a&&b)) {} // expected-warning {{comparison of constant 0 with boolean expression is always false}}
  100. if (1 > (a&&b)) {} // no warning
  101. if (4 > (a&&b)) {} // expected-warning {{comparison of constant 4 with boolean expression is always true}}
  102. if (0 > (a<y)) {} // expected-warning {{comparison of constant 0 with boolean expression is always false}}
  103. if (1 > (a<y)) {} // no warning
  104. if (4 > (a<y)) {} // expected-warning {{comparison of constant 4 with boolean expression is always true}}
  105. if (z > (a<y)) {} // no warning
  106. if (-1 > (a<y)) {} // expected-warning {{comparison of constant -1 with boolean expression is always false}}
  107. if (0 == (a<y)) {} // no warning
  108. if (1 == (a<y)) {} // no warning
  109. if (2 == (a<y)) {} // expected-warning {{comparison of constant 2 with boolean expression is always false}}
  110. if (z == (a<y)) {} // no warning
  111. if (-1 == (a<y)){} // expected-warning {{comparison of constant -1 with boolean expression is always false}}
  112. if (0 !=(a<y)) {} // no warning
  113. if (1 !=(a<y)) {} // no warning
  114. if (2 !=(a<y)) {} // expected-warning {{comparison of constant 2 with boolean expression is always true}}
  115. if (z !=(a<y)) {} // no warning
  116. if (-1 !=(a<y)) {} // expected-warning {{comparison of constant -1 with boolean expression is always true}}
  117. if (z ==(a<y)) {} // no warning
  118. if (z<a>y) {} // no warning
  119. if (z > (a<y)) {} // no warning
  120. if((z<y)>(a<y)) {} // no warning
  121. if((z<y)==(a<y)){} // no warning
  122. if((z<y)!=(a<y)){} // no warning
  123. if((y==z)<(z==x)){} // no warning
  124. if(((z==x)<(y==z))!=(a<y)){} // no warning
  125. if(((z==x)<(-1==z))!=(a<y)){} // no warning
  126. if(((z==x)<(z==-1))!=(a<y)){} // no warning
  127. if(((z==x)<-1)!=(a<y)){} // expected-warning {{comparison of constant -1 with boolean expression is always false}}
  128. if(((z==x)< 2)!=(a<y)){} // expected-warning {{comparison of constant 2 with boolean expression is always true}}
  129. if(((z==x)<(z>2))!=(a<y)){} // no warning
  130. }