http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56899
Bug #: 56899
Summary: Wrong constant folding
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
AssignedTo: [email protected]
ReportedBy: [email protected]
GCC 4.7.2 and 4.8.0 with -O2 option miscompile the following code where
INT_MIN == -2147483648.
$ cat error.c
int main (void)
{
volatile int v = 10;
int x = -214748365 * ( v - 1 );
return ( x == -1932735285 ); /* should return 1 */
}
$ gcc error.c -O2
$ ./a.out
$ echo $?
0
The following code, with "volatile" removed from variable v, is
correctly compiled.
$ cat noerror.c
int main(void)
{
int v = 10;
int x = -214748365 * ( v - 1 );
return ( x == -1932735285 ); /* should return 1 */
}
$ gcc noerror.c -O2
$ ./a.out
$ echo $?
1
The miscompile occurs on options "-O1 -fstrict-overflow."