public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/28707]  New: Incorrect optimization inside member function
@ 2006-08-13 13:10 pierre at senellart dot com
  2006-08-13 15:15 ` [Bug c++/28707] [4.0 Regression] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: pierre at senellart dot com @ 2006-08-13 13:10 UTC (permalink / raw)
  To: gcc-bugs

Consider the following minimal example :

--cut after--
#include<iostream>

struct A {
  long double * t;
  int n;

  A() { n=2; t=new long double[2]; }
  long double &operator()(unsigned i) {return t[i];};
  void bug();
};

void A::bug()
{
  A a;
  for(int k=0;k<n;k++) {
    if(k!=0)
      a(k-1)=0;
    a(k)=1;
  }

  if(a(0)==1)
    std::cerr << "bug" << std::endl;
}

int main()
{
  A a;
  a.bug();
  return 0;
}
--cut before--

When compiled with -O with g++ 4.0.1 or 4.0.3, "bug" is displayed, which is
incorrect. This does not happen when no optimization is performed.

Reproducible with the two following compilers (output of "g++ -v"):
Using built-in specs.
Reading specs from /usr/local/util/etc/gcc-3.4-fedora.specs
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,java,f95,ada --enable-java-awt=gtk
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
--host=i386-redhat-linux
Thread model: posix
gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)

Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.0 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-awt=gtk-default --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr
--disable-werror --with-tune=pentium4 --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.3 (Ubuntu 4.0.3-1ubuntu5)

Not reproducible with g++ 3.5 on i486-linux.

This bug also disappears when long double is replaced with double.


-- 
           Summary: Incorrect optimization inside member function
           Product: gcc
           Version: 4.0.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pierre at senellart dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28707


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

* [Bug c++/28707] [4.0 Regression] Incorrect optimization inside member function
  2006-08-13 13:10 [Bug c++/28707] New: Incorrect optimization inside member function pierre at senellart dot com
@ 2006-08-13 15:15 ` pinskia at gcc dot gnu dot org
  2006-08-14  7:40 ` [Bug tree-optimization/28707] " law at redhat dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-08-13 15:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-08-13 15:15 -------
Only a 4.0.x regression.  DSE removes the store for some reason.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |law at gcc dot gnu dot org
           Keywords|                            |wrong-code
      Known to fail|                            |4.0.3
      Known to work|                            |4.1.0 3.4.0
            Summary|Incorrect optimization      |[4.0 Regression] Incorrect
                   |inside member function      |optimization inside member
                   |                            |function
   Target Milestone|---                         |4.0.4


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28707


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

* [Bug tree-optimization/28707] [4.0 Regression] Incorrect optimization inside member function
  2006-08-13 13:10 [Bug c++/28707] New: Incorrect optimization inside member function pierre at senellart dot com
  2006-08-13 15:15 ` [Bug c++/28707] [4.0 Regression] " pinskia at gcc dot gnu dot org
@ 2006-08-14  7:40 ` law at redhat dot com
  2006-08-16  5:40 ` pinskia at gcc dot gnu dot org
  2007-02-03 18:53 ` gdr at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: law at redhat dot com @ 2006-08-14  7:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from law at redhat dot com  2006-08-14 07:39 -------
Created an attachment (id=12073)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12073&action=view)
Backport of patch to GCC 4.0 branch (not thoroughly tested)

This bug was fixed long ago (prior to branching for GCC 4.1).  However, the fix
was never backported to the GCC 4.0 branch.  Attached is a lightly tested
backport of the patch.

Given the age of GCC 4.0 and my priorities, I'm not planning to run this
through the testing process necessary to get it included in GCC 4.0.x  The GCC
4.0.x release manager (or anyone else for that matter) is welcome to run
through the proper procedures to get this patch included.  Credit for the fix
should go to Daniel Jacobowitz. 


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28707


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

* [Bug tree-optimization/28707] [4.0 Regression] Incorrect optimization inside member function
  2006-08-13 13:10 [Bug c++/28707] New: Incorrect optimization inside member function pierre at senellart dot com
  2006-08-13 15:15 ` [Bug c++/28707] [4.0 Regression] " pinskia at gcc dot gnu dot org
  2006-08-14  7:40 ` [Bug tree-optimization/28707] " law at redhat dot com
@ 2006-08-16  5:40 ` pinskia at gcc dot gnu dot org
  2007-02-03 18:53 ` gdr at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-08-16  5:40 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-08-16 05:40:07
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28707


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

* [Bug tree-optimization/28707] [4.0 Regression] Incorrect optimization inside member function
  2006-08-13 13:10 [Bug c++/28707] New: Incorrect optimization inside member function pierre at senellart dot com
                   ` (2 preceding siblings ...)
  2006-08-16  5:40 ` pinskia at gcc dot gnu dot org
@ 2007-02-03 18:53 ` gdr at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: gdr at gcc dot gnu dot org @ 2007-02-03 18:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from gdr at gcc dot gnu dot org  2007-02-03 18:52 -------
Fixed in GCC-4.1.0.
Won't fix for GCC-4.0.x.


-- 

gdr at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28707


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

end of thread, other threads:[~2007-02-03 18:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-13 13:10 [Bug c++/28707] New: Incorrect optimization inside member function pierre at senellart dot com
2006-08-13 15:15 ` [Bug c++/28707] [4.0 Regression] " pinskia at gcc dot gnu dot org
2006-08-14  7:40 ` [Bug tree-optimization/28707] " law at redhat dot com
2006-08-16  5:40 ` pinskia at gcc dot gnu dot org
2007-02-03 18:53 ` gdr 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).