[PATCH] D142867: [Clang] Add machinery to catch overflow in unary minus outside of a constant expression context
Hubert Tong via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 15 16:36:03 PST 2023
hubert.reinterpretcast added a comment.
In D142867#4108079 <https://reviews.llvm.org/D142867#4108079>, @eaeltsin wrote:
> The warning now fires even if overflow is prevented with `if constexpr`:
>
> if constexpr (width <= 64) {
> if constexpr (width == 64) {
> return 1;
> }
> return -static_cast<int64_t>(uint64_t{1} << (width - 1));
> }
>
> https://godbolt.org/z/M3xdcKd3M
For reference, actually placing the second return into an `else` block (thus making it a discarded statement) does suppress the diagnostic:
https://godbolt.org/z/Kb6Md5PrK
I also question the focus on `if constexpr`. Replacing with `if (true) { return 1; }` should be as effective in the non-`else`-block case in suppressing the warning in terms of QoI.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142867/new/
https://reviews.llvm.org/D142867
More information about the cfe-commits
mailing list