[clang] [Clang] Force expressions with UO_Not to not be non-negative (PR #126846)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 20 13:15:31 PDT 2025


zygoloid wrote:

> > But still I feel generate a warning for this case went too far.
> 
> Yeah, that's probably right. Maybe for `-` on a signed operand, we should just return the original range with the `NonNegative` flag cleared out, and shouldn't add the extra bit for the `-128 -> 128` edge case. That's not technically correct, but probably is more useful in practice.

Hm. That change will reintroduce a false positive warning for:
```c++
bool b(signed char c) {
  return -c >= 128;
}
```
... that this patch fixed. But we don't produce a false positive for `0 - c >= 128`, so I still think what we ought to do here is to make `-c` behave the same way that `0 - c` does.

https://github.com/llvm/llvm-project/pull/126846


More information about the cfe-commits mailing list