[PATCH] D85256: Add -Wtautological-value-range-compare warning.

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 11 12:12:44 PDT 2020


rsmith added a comment.

In D85256#2209211 <https://reviews.llvm.org/D85256#2209211>, @sberg wrote:

> I think this generates a false positive with `test.cc`
>
>   enum E { E1 = 1, E2 = 2 };
>   bool f(E e) { return ((e & E1) ? 1 : 0) + ((e & E2) ? 1 : 0) > 1; }
>
> and `clang++ -fsyntax-only -Wtautological-value-range-compare test.cc`
>
>   test.cc:2:62: warning: result of comparison of 1-bit unsigned value > 1 is always false [-Wtautological-value-range-compare]
>   bool f(E e) { return ((e & E1) ? 1 : 0) + ((e & E2) ? 1 : 0) > 1; }
>                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~

This appears to be a general problem: the `GetExprRange` mechanism in SemaChecking miscomputes the ranges for `+`, `*`, and `-` expressions, and we'll get them wrong for all warnings that use that mechanism :-(


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85256/new/

https://reviews.llvm.org/D85256



More information about the cfe-commits mailing list