[Bug c/64442] New: -O1 modify output of a simple computation with rounding
colin.pitrat+gcc at gmail dot com
gcc-bugzilla@gcc.gnu.org
Tue Dec 30 11:53:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64442
Bug ID: 64442
Summary: -O1 modify output of a simple computation with
rounding
Product: gcc
Version: 4.9.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: colin.pitrat+gcc at gmail dot com
When building the following program with -O1, it outputs 85 whereas without -O1
it outputs 84:
#include <stdio.h>
#include <stdint.h>
int main()
{
double max = 8.03;
double a = 6.01;
double b = 5;
double c = (double)0xFF / (max - b);
int16_t value = (a - b) * c;
printf("Result = %d\n", value);
return 0;
}
The compilation lines I use are really minimal:
- gcc main.c
vs
- gcc -O1 main.c
I tried to find which optimization flag was producing this issue but couldn't
find any !
- I don't have the issue when I don't use -O1 but provide explicitely all (or
any of) -O1 optimization flags (obtained with gcc -Q -O1 --help=optimizers |
grep "\-f" | grep enabled | awk '{ print $1 }' | xargs)
- Among all optimizer flags, I have the same issue only when providing either
-fsingle-precision-constant, -ffloat-store or -fshort-double but those flags
are supposed to be deactivated in -O1
Note that I didn't test -fpack-struct because it didn't build
Regards,
Colin
More information about the Gcc-bugs
mailing list