================
@@ -169,7 +169,84 @@ int struct_test(struct A a) {
   return a.x > 5 && a.y < 1;  // no warning, different variables
 
   return a.x > 5 && a.x < 1;
-  // expected-warning@-1{{overlapping comparisons always evaluate to false}}
+  // expected-warning@-1{{non-overlapping comparisons always evaluate to 
false}}
   return a.y == 1 || a.y != 1;
   // expected-warning@-1{{overlapping comparisons always evaluate to true}}
 }
+
+void char_tests(char c) {
+  if (c > 'a' || c < 'z') {}
+  // expected-warning@-1{{overlapping comparisons always evaluate to true}}
+  if (c > 'z' && c < 'a') {}
+  // expected-warning@-1{{non-overlapping comparisons always evaluate to 
false}}
+  if (c == 'a' && c == 'z') {}
+  // expected-warning@-1{{non-overlapping comparisons always evaluate to 
false}}
+  if (c != 'a' || c != 'z') {}
+  // expected-warning@-1{{overlapping comparisons always evaluate to true}}
+}
+
+void float_tests(float f) {
+  if (f > 1.0 || f < 2.0) {}
+  // expected-warning@-1{{overlapping comparisons always evaluate to true}}
----------------
Sirraide wrote:

> If we consider `nan` as a possible value for `f`, this flag would be wrong in 
> the first place

Yeah, that’s a good point. Maybe we should have a comment for that somewhere 
(either in the test cases or the code).

> `__builtin_nan()/__builtin_inf()` wouldn't trigger this flag at all since 
> this flag only deals with literal comparands, but I can still add them.

Right, I didn’t think about that because we’re doing constant evaluation to get 
the value, which *could* handle e.g. `__builtin_inf()`. I think in that case 
it’s fine as is.



https://github.com/llvm/llvm-project/pull/133653
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to