[clang] [clang][AST] Implement -Wunsigned-integer-overflow for checking for unsigned integer constants overflow (PR #222173)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 9 06:00:31 PDT 2026


https://github.com/AaronBallman commented:

Thank you for working on this! There's a few things worth thinking about here:

Based on past experience, we don't generally accept new off-by-default diagnostics unless there's a very strong signal that users will enable them (most off-by-default diagnostics are not enabled very often which makes adding and maintaining them questionable). Instead, we ask what can be done to enable it by default which generally means a near-zero false positive rate. I don't believe this diagnostic would meet the bar for it being off-by-default.

"False positive" is hard to nail down here given that it's well-defined behavior. Limiting it to just multiplication and addition seems questionable to me. e.g., why shouldn't `0u - 1u` be diagnosed? If diagnosing that, why not `-1u`?

My intuition is that this kind of diagnostic is better left to other tooling (overflow behavior types, sanitizers, linters or static analyzers) given that it's well-defined behavior both at runtime and constexpr evaluation time and how much code intentionally overflows even constant expressions. However, I think @ojhunt has been thinking about this design space a considerable amount and maybe he has a different take on this.

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


More information about the cfe-commits mailing list