https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93806
Bug ID: 93806
Summary: Wrong optimization: instability of floating-point
results with -funsafe-math-optimizations leads to
nonsense
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: ch3root at openwall dot com
Target Milestone: ---
With -funsafe-math-optimizations, floating-point results are effectively
unstable, this instability can taint everything around and lead to nonsense.
(Similar to pr93681 and pr93682.)
Instability is not limited to FP numbers, it extends to integers too:
----------------------------------------------------------------------
#include <stdio.h>
__attribute__((noipa)) // imagine it in a separate TU
static double opaque(double d) { return d; }
int main()
{
int x = opaque(1);
int a = 1 + opaque(0x1p-60) != x;
printf("a = %d\n", a);
if (x == 1) {
opaque(0);
if (a)
printf("a is 1\n");
}
}
----------------------------------------------------------------------
$ gcc -std=c11 -pedantic -Wall -Wextra -funsafe-math-optimizations -O3 test.c
&& ./a.out
a = 0
a is 1
----------------------------------------------------------------------
gcc x86-64 version: gcc (GCC) 10.0.1 20200218 (experimental)
----------------------------------------------------------------------