Arch Linux

Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

FS#43267 - [gcc] O1 modify output of simple computation

Attached to Project: Arch Linux
Opened by Colin Pitrat (LiFo2) - Monday, 29 December 2014, 21:51 GMT
Last edited by Allan McRae (Allan) - Monday, 29 December 2014, 23:15 GMT
Task Type Bug Report
Category Upstream Bugs
Status Closed
Assigned To Allan McRae (Allan)
Architecture i686
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

Description:
When building the following program with -O1, it outputs 85 whereas without -O1 it outputs 84:

#include <iostream>
#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;
std::cout << "Result = " << value << std::endl;
return 0;
}

The compilation lines I use are really minimal:
- g++ main.cc
vs
- g++ -O1 main.cc

I tried to find which optimization flag was producing this issue but couldn't find any !

- I don't have the issue when I provide explicitely all -O1 optimization flags (obtained with gcc -Q -O1 --help=optimizers | grep "\-f" | grep enabled | awk '{ print $1 }' | xargs) and not -O1 flag
- Among all optimizer flags, I have the issue only with -fsingle-precision-constant, -ffloat-store & -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)

The version of GCC I use is GCC 4.9.2

Regards,
Colin
This task depends upon

Closed by  Allan McRae (Allan)
Monday, 29 December 2014, 23:15 GMT
Reason for closing:  Not a bug
Comment by Allan McRae (Allan) - Monday, 29 December 2014, 22:47 GMT
And when you change "int16_t value" to "double value"?
Comment by Allan McRae (Allan) - Monday, 29 December 2014, 23:14 GMT
Anyway - this is i686 math and minor floating point differences leading to a big difference when cast to an int. Not really a bug....

Loading...