public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/25411]  New: Optimization with -O2 -finline-functions gives wrong code
@ 2005-12-14 13:39 hans dot ekkehard dot plesser at umb dot no
  2005-12-14 13:45 ` [Bug c++/25411] " hans dot ekkehard dot plesser at umb dot no
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: hans dot ekkehard dot plesser at umb dot no @ 2005-12-14 13:39 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-01-01  5:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-14 13:39 [Bug c++/25411] New: Optimization with -O2 -finline-functions gives wrong code hans dot ekkehard dot plesser at umb dot no
2005-12-14 13:45 ` [Bug c++/25411] " hans dot ekkehard dot plesser at umb dot no
2005-12-14 15:54 ` rguenth at gcc dot gnu dot org
2005-12-15  8:41 ` falk at debian dot org
2005-12-16 11:50 ` hans dot ekkehard dot plesser at umb dot no
2005-12-16 21:34 ` falk at debian dot org
2006-01-01  5:26 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).