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

Yutong Zhu via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 19 06:00:01 PDT 2025


YutongZhuu wrote:

> I think this change might went too far. We are seeing this check flagging code like this:
> 
> ```
> error: implicit conversion loses integer precision: 'int' to 'int8_t' (aka 'signed char') [-Werror,-Wimplicit-int-conversion]:
> int8_t shift = ...
> ...
> shift = -shift;
>       ~ ^~~~~~
> ```
> 
> While technically this is an implicit int conversion, as '-' promote value of 'shift' from `int8_t` to `int` and the expression reassigns it back to `int8_t`. But the implicit conversion here has no side effects and it is a common practice. We appreciate the fact that clang now flagging cases like the one in the summary, but flagging/fixing the cases like the one above seems to be unnecessary. Would it be possible to provide better fine grained control over the `-Wsign-compare` so the clang could still flag the the cases like the one in the summary but ignore the cases where implicit conversion has no side effects or UB?

I agree, I will look into this :)

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


More information about the cfe-commits mailing list