On 02/06/16 10:08, Bernd Schmidt wrote:
On 05/23/2016 01:17 PM, Kyrill Tkachov wrote:
In this PR we end up hitting a signed overflow in noce_get_alt_condition
when we try to
increment or decrement a HOST_WIDE_INT that might be HOST_WIDE_INT_MAX
or HOST_WIDE_INT_MIN.
I've confirmed the overflow by adding an assert before the operation:
gcc_assert (desired_val != HOST_WIDE_INT_MAX);
Don't we have to check for overflow in whatever mode the comparison is in,
rather than using HOST_WIDE_INT?
The overflow happens because no the next line the code checks for:
actual_val == desired_val + 1
so if desired_val is HOST_WIDE_INT_MAX the "+ 1" overflows it. I don't think
the mode here is relevant
as we're trying to avoid undefined behaviour in the compiler itself.
I expect the compile test doesn't actually test anything without some sort of
sanitizer enabled for the compiler? If this results in a miscompilation, can
you construct an executable test?
As described in https://gcc.gnu.org/ml/gcc-patches/2016-05/msg01790.html, I
couldn't get it to miscompile anything.
The bug was reported through a run instrumented with sanitisation.
I agree the testcase is not very useful as it stands, at best it only checks
that we don't ICE (which we didn't anyway)
but since the problem here is undefined behaviour the effects of the bug depend
on the compiler used to compile GCC itself.
Thanks,
Kyrill
Bernd