[Bug testsuite/31290] gcc.c-torture/execute/920612-1.c and gcc.c-torture/execute/920711-1.c depend on signed overflow being defined

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Aug 30 15:19:53 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31290

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Philipp from comment #4)
> I disagree about this bug for gcc.c-torture/execute/920711-1.c. I think
> there was no bug here, and the "fix" actually introduced a problem, and
> should be reverted:

No there is a bug.
int f(long a){return (--a > 0);}
int main(){if(f(0x80000000L)==0)abort();exit(0);}


0x80000000L is still 0x80000000 bitwise. so we get 0x80000000L - 1 which is
undefined if long is 32bits. If long is 64bits then 0x80000000L is still that
(and no implementation defined casting) and not undefined there.

> By section 4.5 of the GCC manual https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html#Integers-implementation the result of the conversion is -1.

No it is INT_MIN (for 32bit long):
For conversion to a type of width N, the value is reduced modulo 2^N to be
within range of the type; no signal is raised.

That means 0x80000000ULL will be 0x80000000L (if long is 32bits and long long
is 64bit).


More information about the Gcc-bugs mailing list