Look out the output:
1. When no O2 option set, the output is:
send out: 500000 Time: 1165250900
192.168.1.1 100000
2. When -O2 option is set, the output is:
192.168.1.1 send out: 500000 Time: 1165250934
100000
It proves that the execution sequence has been changed. I think it's a block
bug, due to the reason that I can not control the execution flow, I had
disabled -O2 optimization, but that's a big performance discount to my program.
Source Code:
#include <iostream>
#include <ctime>
float
CalcDownSpeed()
{
// fake define
int nStartTime = 100;
int nTotalSendOut = 500000;
int nLastCalc = 10000000;
int now = time(NULL);
std::cout << "send out: " << nTotalSendOut << " Time: " << now -
nLastCalc << std::endl;
float downspeed = 100000;
return downspeed;
}
int main()
{
std::cout << "192.168.1.1" << "\t" << CalcDownSpeed() << std::endl;
return 0;
}
--
Summary: When O2 optimization option is set, the execution flow
is changed.
Product: gcc
Version: 3.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: windows2000d at gmail dot com
GCC host triplet: Intel platform
GCC target triplet: Red hat linux, 2.6.9-5.EL
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31398