On 2026-11-13 20:36, Jakub Jelinek wrote:
On Fri, Nov 13, 2026 at 08:20:27PM +0100, Torbjörn SVENSSON wrote:
I reported this failure earlier today in
https://gcc.gnu.org/pipermail/gcc-patches/2026-November/738737.html
Tonight, I had some more spare time, so I took another look and checked what
the test is really testing. I don't know why -1/-1 was selected, but since 0/-1
is the only valid expression (the only one without UB), I suppose we can change
to that.
Tested on arm-none-eabi, using r17-6056-g9adb420e4826a6 as the baseline.
Ok for trunk?
No, that looks incorrect. The test uses -fwrapv, I believe that makes
~0wb / ~0wb - ~0wb. Without -fwrapv it is obviously UB.
Same thing as whether ()-__INT_MAX__ - 1) / -1 is UB with -fwrapv or not.
I think there is something missing here.
According to the documentation for -fwrapv, it does not apply to division:
-fwrapv
This option instructs the compiler to assume that signed arithmetic
overflow of addition, subtraction and multiplication wraps around
using twos-complement representation. This flag enables some
optimizations and disables others. The options -ftrapv and -fwrapv
override each other, so using -ftrapv -fwrapv on the command-line
results in -fwrapv being effective. Note that only active options
override, so using -ftrapv -fwrapv -fno-wrapv on the command-line
results in -ftrapv being effective.
Assuming that the documentation is correct, then there is no other
expression than 0/-1 that is not UB, right?
Kind regards,
Torbjörn