[Bug c++/25411] New: Optimization with -O2 -finline-functions gives wrong code
hans dot ekkehard dot plesser at umb dot no
gcc-bugzilla@gcc.gnu.org
Wed Dec 14 13:39:00 GMT 2005
A test for functor expressions in the Vigra library testsuite gives erroneous
results if compiled with -O2 -finline-functions. No problem occurs if either
option is dropped. The error occurs as well with g++ 4.0.0, but not with
3.4.3. The error occurs under Tru64 V5.1B on an AlphaServer, but not under
Linux on i686 (g++ 4.0.0).
The program in question is
#include <iostream>
#include "vigra/functorexpression.hxx"
#include "vigra/rgbvalue.hxx"
using namespace vigra::functor;
int main()
{
vigra::RGBValue<int> data[] = { vigra::RGBValue<int>(0),
vigra::RGBValue<int>(1) };
vigra::RGBValue<int> sum(0);
int count = 0;
for ( int j = 0 ; j < 2 ; ++j )
std::cerr << "data[" << j << "]: " << data[j] << std::endl;
std::for_each(data, data+2,
(
Var(count) += Param(1) ,
Var(sum) += Arg1()
));
std::cerr << "count: " << count
<< "\nsum: " << sum
<< std::endl;
return 0;
}
The expected output is
data[0]: (0, 0, 0)
data[1]: (1, 1, 1)
count: 2
sum: (1, 1, 1)
If compiled with -O2 -finline-functions, the following is produced:
data[0]: (0, 0, 0)
data[1]: (1, 1, 1)
count: 0
sum: (3, 1, 1)
If the two items in the comma-expression that forms the third argument of
std::for_each() are exchanged, correct code is produced with the
-finline-functions option in place.
I will be happy to supply header files or the preprocessor output on request.
Hans E Plesser
--
Summary: Optimization with -O2 -finline-functions gives wrong
code
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: hans dot ekkehard dot plesser at umb dot no
GCC build triplet: alphaev7-dec-osf5.1b
GCC host triplet: alphaev7-dec-osf5.1b
GCC target triplet: alphaev7-dec-osf5.1b
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25411
More information about the Gcc-bugs
mailing list