Idiom exclusion is really so important
Idiom exclusion is really so important
Posted Nov 13, 2024 10:31 UTC (Wed) by intelfx (subscriber, #130118)In reply to: Idiom exclusion is really so important by magfr
Parent article: Progress on toolchain security features
>
> x+y<x
>
> is considered easier to read and better than
>
> INT_MAX-y<=x
It is considered better in the eyes of the language lawyers. Which, apparently, is enough to trump any kind of readability concerns.
I'd ask a different question, though. With the amount of compiler extensions already part of "kernel C" (some of which are even in this article), I'm having a hard time understanding reasons for not adding a `__builtin_wraps(expr)` kind of thing that explicitly evaluates `expr` under `-fwrapv` rules and tests that for overflow.
Surely an `if (__builtin_wraps(a + b))` is more readable than both `if (a + b < a)` and `if (INT_MAX - b <= a)`?
