Created attachment 1479738 [details] Test code Description of problem: I have a certain loop in my code where I get unexpected values in variables updated in the loop body. The problem is related to conversion or comparison between double and integer types. Version-Release number of selected component (if applicable): 4.9.3-1.el7 How reproducible: Every time Steps to Reproduce: 1. On Linux, i686-w64-mingw32-g++ -mms-bitfields -O2 -I/usr/i686-w64-mingw32/sys-root/mingw/include -L/usr/i686-w64-mingw32/sys-root/mingw/lib testLoop.cpp -o testLoop.exe 2. Copy testLoop.exe and the necessary MinGW libs to a Windows system (I assume you know how.) 3. On Windows, cd where-you-put-the-files testLoop.exe Actual results: 0 0 0 0 0.344262 0 0 0 0.688525 0 0 0 1.03279 1 1 1 1.37705 1 1 1 1.72131 1 1 1 2.06557 2 2 2 2.40984 2 2 2 2.7541 2 2 2 3.09836 3 3 3 3.44262 3 3 3 3.78689 3 3 3 4.13115 4 4 4 4.47541 4 4 4 4.81967 4 4 4 5.16393 5 5 5 5.5082 5 5 5 5.85246 5 5 5 6.19672 6 6 6 6.54098 6 6 6 6.88525 6 6 6 7.22951 7 7 7 7.57377 7 7 7 7.91803 7 7 7 8.2623 8 8 8 8.60656 8 8 8 8.95082 8 8 8 9.29508 9 9 9 9.63934 9 9 9 9.98361 9 9 9 10.3279 10 10 10 10.6721 10 10 10 11.0164 11 11 11 11.3607 11 11 11 11.7049 11 11 11 12.0492 12 12 12 12.3934 12 12 12 12.7377 12 12 12 13.082 13 13 13 13.4262 13 13 13 13.7705 13 13 13 14.1148 14 14 14 14.459 14 14 14 14.8033 14 14 14 15.1475 15 15 15 15.4918 15 15 15 15.8361 15 15 15 16.1803 16 16 16 16.5246 16 16 16 16.8689 16 16 16 17.2131 17 17 17 17.5574 17 17 17 17.9016 17 17 17 18.2459 18 18 18 18.5902 18 18 18 18.9344 18 18 18 19.2787 19 19 19 19.623 19 19 19 19.9672 19 19 19 20.3115 20 20 20 20.6557 20 20 20 SHOULD NOT BE HERE 21 20 21 21 Expected results: 0 0 0 0 0.344262 0 0 0 0.688525 0 0 0 1.03279 1 1 1 1.37705 1 1 1 1.72131 1 1 1 2.06557 2 2 2 2.40984 2 2 2 2.7541 2 2 2 3.09836 3 3 3 3.44262 3 3 3 3.78689 3 3 3 4.13115 4 4 4 4.47541 4 4 4 4.81967 4 4 4 5.16393 5 5 5 5.5082 5 5 5 5.85246 5 5 5 6.19672 6 6 6 6.54098 6 6 6 6.88525 6 6 6 7.22951 7 7 7 7.57377 7 7 7 7.91803 7 7 7 8.2623 8 8 8 8.60656 8 8 8 8.95082 8 8 8 9.29508 9 9 9 9.63934 9 9 9 9.98361 9 9 9 10.3279 10 10 10 10.6721 10 10 10 11.0164 11 11 11 11.3607 11 11 11 11.7049 11 11 11 12.0492 12 12 12 12.3934 12 12 12 12.7377 12 12 12 13.082 13 13 13 13.4262 13 13 13 13.7705 13 13 13 14.1148 14 14 14 14.459 14 14 14 14.8033 14 14 14 15.1475 15 15 15 15.4918 15 15 15 15.8361 15 15 15 16.1803 16 16 16 16.5246 16 16 16 16.8689 16 16 16 17.2131 17 17 17 17.5574 17 17 17 17.9016 17 17 17 18.2459 18 18 18 18.5902 18 18 18 18.9344 18 18 18 19.2787 19 19 19 19.623 19 19 19 19.9672 19 19 19 20.3115 20 20 20 20.6557 20 20 20 Additional info: I get the "expected results" if 1. Remove "-O2" from the compile command. 2. I compile and run natively on my 64-bit Linux system. 3. Build a 64-bit Windows version, with our without "-O2" - e.g. x86_64-w64-mingw32-g++ -O2 -mms-bitfields -I/usr/x86_64-w64-mingw32/sys-root/mingw/include -L/usr/x86_64-w64-mingw32/sys-root/mingw/lib testLoop.cpp -o testLoop.exe 1.) leads me to conclude that there must be an issue with how loops are optimised when -O2 is enabled. I get similar issues with for(double pos=0; pos<classValues.size(); pos+=step) { size_t index=static_cast<size_t>(pos); ... I'm testing on an old workstation running 64-bit Windows 7 enterprise.
Just want to save you a bit of time here and say that you will need to take this issue up with the upstream mingw-w64 project (or even GCC if you suspect a GCC bug). We are only dealing with packaging here.
Don't Fedora/Red Hat package maintainers occasionally forward requests to upstream bug reporting tools? This is very helpful, as it saves users from having separate accounts around the net for each and every piece of software they are using...
We do sometimes. In this case since the main developer working on the mingw-gcc package sadly passed away we're short on people to follow up detailed bug reports. Plus you likely understand the bug far better than I do.
See https://sourceforge.net/p/mingw-w64/bugs/759/
This package has changed maintainer in Fedora. Reassigning to the new maintainer of this component.