public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/12815] New: Code compiled with optimization behaves unexpectedly
@ 2003-10-28 15:43 boris at kolpackov dot net
  2003-10-28 16:14 ` [Bug optimization/12815] [3.3/3.4 Regression] " pinskia at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: boris at kolpackov dot net @ 2003-10-28 15:43 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: Code compiled with optimization behaves unexpectedly
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: boris at kolpackov dot net
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-gnu-linux
  GCC host triplet: i686-gnu-linux
GCC target triplet: i686-gnu-linux

$ cat >test.cpp
#include <typeinfo>
#include <iostream>

using std::cerr;
using std::endl;

bool
operator== (std::type_info const* pa, std::type_info const& b)
{
  return *pa == b;
}

struct A
{
  virtual
  ~A () {}
};

struct APtr
{
  APtr (A* p)
      : p_ (p)
  {
  }

  A&
  operator* () const
  {
    return *p_;
  }

private:
  A* p_;
};

int
main ()
{
  APtr ap (new A);
  
  for(bool cont__ = true; cont__;)
  {
    cerr << "outer: cont__ " << cont__ << endl;
    
    for(std::type_info const* const exp__ ((&typeid (*ap)));
        cont__;
        cont__ = false)
    {
      cerr << "inner: cont__ " << cont__ << endl;
      
      if(cont__ &&
         exp__ == (typeid (int)) &&
         (cont__ = false, true))
      {
        cerr << "condition" << endl;        
      }
    }
  }
}

$ g++ --version
g++ (GCC) 3.3.2 (Debian)

$ g++ ./test.cpp
$ ./a.out
outer: cont__ 1
inner: cont__ 1
$ g++ -O ./test.cpp
$ ./a.out # will result in infinite loop
outer: cont__ 1
inner: cont__ 1
inner: cont__ 1
inner: cont__ 1
inner: cont__ 1
inner: cont__ 1
inner: cont__ 1
^C
$


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

* [Bug optimization/12815] [3.3/3.4 Regression] Code compiled with optimization behaves unexpectedly
  2003-10-28 15:43 [Bug optimization/12815] New: Code compiled with optimization behaves unexpectedly boris at kolpackov dot net
@ 2003-10-28 16:14 ` pinskia at gcc dot gnu dot org
  2003-10-28 17:20 ` falk at debian dot org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-10-28 16:14 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
            Summary|Code compiled with          |[3.3/3.4 Regression] Code
                   |optimization behaves        |compiled with optimization
                   |unexpectedly                |behaves unexpectedly
   Target Milestone|---                         |3.3.3


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-10-28 16:11 -------
Here is the smallest I could get it, also it is a regression from 3.0.4:
//#define __GXX_MERGED_TYPEINFO_NAMES
#include <typeinfo>

extern "C" void exit(int);
bool
operator== (std::type_info const* pa, std::type_info const& b)
{
  return *pa == b;
}
struct A
{
  virtual
  ~A () {}
};
struct APtr
{
  APtr (A* p)
      : p_ (p)
  {
  }
  A&
  operator* () const
  {
    return *p_;
  }
private:
  A* p_;
};
void f(void){exit(1);}
int
main ()
{
  APtr ap (new A);
  for(bool cont__ = true; cont__;)
  {
    for(std::type_info const* const exp__ ((&typeid (*ap)));
        cont__;
        cont__ = false)
    {
      if(cont__ &&
         exp__ == (typeid (int)))
      {
	f();
      }
    }
  }
}


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

* [Bug optimization/12815] [3.3/3.4 Regression] Code compiled with optimization behaves unexpectedly
  2003-10-28 15:43 [Bug optimization/12815] New: Code compiled with optimization behaves unexpectedly boris at kolpackov dot net
  2003-10-28 16:14 ` [Bug optimization/12815] [3.3/3.4 Regression] " pinskia at gcc dot gnu dot org
@ 2003-10-28 17:20 ` falk at debian dot org
  2003-10-28 18:02 ` bangerth at dealii dot org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: falk at debian dot org @ 2003-10-28 17:20 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


falk at debian dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Target Milestone|3.3.3                       |---


------- Additional Comments From falk at debian dot org  2003-10-28 16:28 -------
A slightly smaller test case:

#include <typeinfo>
#include <iostream>

struct A { virtual ~A () {} };

struct APtr
{ 
  APtr (A* p)  : p_ (p) { }
  A& operator* () const { return *p_;  }
  A* p_;
};

int main ()
{ 
  APtr ap (new A);
  std::type_info const* const exp = &typeid (*ap);
  for (bool cont = true; cont; cont = false)
    { 
      std::cout << "inner: cont " << cont << std::endl;
      if (exp) ;
    }
}


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

* [Bug optimization/12815] [3.3/3.4 Regression] Code compiled with optimization behaves unexpectedly
  2003-10-28 15:43 [Bug optimization/12815] New: Code compiled with optimization behaves unexpectedly boris at kolpackov dot net
  2003-10-28 16:14 ` [Bug optimization/12815] [3.3/3.4 Regression] " pinskia at gcc dot gnu dot org
  2003-10-28 17:20 ` falk at debian dot org
@ 2003-10-28 18:02 ` bangerth at dealii dot org
  2003-12-03 14:12 ` [Bug c++/12815] " ebotcazou at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bangerth at dealii dot org @ 2003-10-28 18:02 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical
   Target Milestone|---                         |3.3.3


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

* [Bug c++/12815] [3.3/3.4 Regression] Code compiled with optimization behaves unexpectedly
  2003-10-28 15:43 [Bug optimization/12815] New: Code compiled with optimization behaves unexpectedly boris at kolpackov dot net
                   ` (2 preceding siblings ...)
  2003-10-28 18:02 ` bangerth at dealii dot org
@ 2003-12-03 14:12 ` ebotcazou at gcc dot gnu dot org
  2003-12-16 22:45 ` pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2003-12-03 14:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ebotcazou at gcc dot gnu dot org  2003-12-03 14:12 -------
This is a C++ problem I think. It appears that the 'A' object is constructed
twice (or that two instances are constructed if this is the intended behaviour),
the first time for

  APtr ap (new A);

and the second time for

  if (exp)

The first instance is never used, only the second one through 'typeid'.


The problem is the following: because A has a vtable, a 'jump' instruction is
emitted inside the constructor to another insn of this constructor. Now the
'jump' inside the *second* constructor points to the insn which is targeted by
the 'jump' inside the *first* constructor, that is the 'label' of the first
constructor was reused for the second constructor. After that, all hell breaks
loose.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|optimization                |c++


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


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

* [Bug c++/12815] [3.3/3.4 Regression] Code compiled with optimization behaves unexpectedly
  2003-10-28 15:43 [Bug optimization/12815] New: Code compiled with optimization behaves unexpectedly boris at kolpackov dot net
                   ` (3 preceding siblings ...)
  2003-12-03 14:12 ` [Bug c++/12815] " ebotcazou at gcc dot gnu dot org
@ 2003-12-16 22:45 ` pinskia at gcc dot gnu dot org
  2004-01-05 22:13 ` mmitchel at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-16 22:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-16 22:12 -------
On tree-ssa, the optimization phases delete the store to cont for some reason!

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|0000-00-00 00:00:00         |2003-12-16 22:12:26
               date|                            |


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


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

* [Bug c++/12815] [3.3/3.4 Regression] Code compiled with optimization behaves unexpectedly
  2003-10-28 15:43 [Bug optimization/12815] New: Code compiled with optimization behaves unexpectedly boris at kolpackov dot net
                   ` (4 preceding siblings ...)
  2003-12-16 22:45 ` pinskia at gcc dot gnu dot org
@ 2004-01-05 22:13 ` mmitchel at gcc dot gnu dot org
  2004-01-06  0:52 ` cvs-commit at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2004-01-05 22:13 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |mark at codesourcery dot com
                   |dot org                     |
             Status|NEW                         |ASSIGNED


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


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

* [Bug c++/12815] [3.3/3.4 Regression] Code compiled with optimization behaves unexpectedly
  2003-10-28 15:43 [Bug optimization/12815] New: Code compiled with optimization behaves unexpectedly boris at kolpackov dot net
                   ` (5 preceding siblings ...)
  2004-01-05 22:13 ` mmitchel at gcc dot gnu dot org
@ 2004-01-06  0:52 ` cvs-commit at gcc dot gnu dot org
  2004-01-06  0:52 ` cvs-commit at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-01-06  0:52 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-01-06 00:52 -------
Subject: Bug 12815

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-01-06 00:52:38

Modified files:
	gcc/cp         : ChangeLog 

Log message:
	PR c++/12815
	* class.c (build_vtbl_ref_1): Do not unconditionally mark vtable
	references as constant.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3857&r2=1.3858



-- 


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


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

* [Bug c++/12815] [3.3/3.4 Regression] Code compiled with optimization behaves unexpectedly
  2003-10-28 15:43 [Bug optimization/12815] New: Code compiled with optimization behaves unexpectedly boris at kolpackov dot net
                   ` (6 preceding siblings ...)
  2004-01-06  0:52 ` cvs-commit at gcc dot gnu dot org
@ 2004-01-06  0:52 ` cvs-commit at gcc dot gnu dot org
  2004-01-06  0:55 ` [Bug c++/12815] [3.3 " mmitchel at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-01-06  0:52 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-01-06 00:52 -------
Subject: Bug 12815

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-01-06 00:52:12

Modified files:
	gcc/cp         : ChangeLog class.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/rtti: typeid4.C 

Log message:
	PR c++/12816
	* class.c (build_vtbl_ref_1): Do not unconditionally mark vtable
	references as constant.
	
	PR c++/12815
	* g++.dg/rtti/typeid4.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3856&r2=1.3857
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&r1=1.591&r2=1.592
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3339&r2=1.3340
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/rtti/typeid4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


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


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

* [Bug c++/12815] [3.3 Regression] Code compiled with optimization behaves unexpectedly
  2003-10-28 15:43 [Bug optimization/12815] New: Code compiled with optimization behaves unexpectedly boris at kolpackov dot net
                   ` (7 preceding siblings ...)
  2004-01-06  0:52 ` cvs-commit at gcc dot gnu dot org
@ 2004-01-06  0:55 ` mmitchel at gcc dot gnu dot org
  2004-01-06  0:55 ` mmitchel at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2004-01-06  0:55 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|mark at codesourcery dot com|unassigned at gcc dot gnu
                   |                            |dot org
             Status|ASSIGNED                    |NEW


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


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

* [Bug c++/12815] [3.3 Regression] Code compiled with optimization behaves unexpectedly
  2003-10-28 15:43 [Bug optimization/12815] New: Code compiled with optimization behaves unexpectedly boris at kolpackov dot net
                   ` (8 preceding siblings ...)
  2004-01-06  0:55 ` [Bug c++/12815] [3.3 " mmitchel at gcc dot gnu dot org
@ 2004-01-06  0:55 ` mmitchel at gcc dot gnu dot org
  2004-01-13  0:01 ` cvs-commit at gcc dot gnu dot org
  2004-01-14  9:06 ` gdr at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2004-01-06  0:55 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From mmitchel at gcc dot gnu dot org  2004-01-06 00:55 -------
Fixed in GCC 3.4.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[3.3/3.4 Regression] Code   |[3.3 Regression] Code
                   |compiled with optimization  |compiled with optimization
                   |behaves unexpectedly        |behaves unexpectedly


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


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

* [Bug c++/12815] [3.3 Regression] Code compiled with optimization behaves unexpectedly
  2003-10-28 15:43 [Bug optimization/12815] New: Code compiled with optimization behaves unexpectedly boris at kolpackov dot net
                   ` (9 preceding siblings ...)
  2004-01-06  0:55 ` mmitchel at gcc dot gnu dot org
@ 2004-01-13  0:01 ` cvs-commit at gcc dot gnu dot org
  2004-01-14  9:06 ` gdr at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-01-13  0:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-01-13 00:01 -------
Subject: Bug 12815

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jason@gcc.gnu.org	2004-01-13 00:01:47

Modified files:
	gcc/cp         : ChangeLog class.c 

Log message:
	PR c++/12815
	* class.c (build_base_path): Do not mark vtable references as
	TREE_CONSTANT.
	(build_vtbl_ref_1): Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3872&r2=1.3873
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&r1=1.594&r2=1.595



-- 


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


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

* [Bug c++/12815] [3.3 Regression] Code compiled with optimization behaves unexpectedly
  2003-10-28 15:43 [Bug optimization/12815] New: Code compiled with optimization behaves unexpectedly boris at kolpackov dot net
                   ` (10 preceding siblings ...)
  2004-01-13  0:01 ` cvs-commit at gcc dot gnu dot org
@ 2004-01-14  9:06 ` gdr at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: gdr at gcc dot gnu dot org @ 2004-01-14  9:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gdr at gcc dot gnu dot org  2004-01-14 09:06 -------
fixed also for 3.3.3

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


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


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

end of thread, other threads:[~2004-01-14  9:06 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-28 15:43 [Bug optimization/12815] New: Code compiled with optimization behaves unexpectedly boris at kolpackov dot net
2003-10-28 16:14 ` [Bug optimization/12815] [3.3/3.4 Regression] " pinskia at gcc dot gnu dot org
2003-10-28 17:20 ` falk at debian dot org
2003-10-28 18:02 ` bangerth at dealii dot org
2003-12-03 14:12 ` [Bug c++/12815] " ebotcazou at gcc dot gnu dot org
2003-12-16 22:45 ` pinskia at gcc dot gnu dot org
2004-01-05 22:13 ` mmitchel at gcc dot gnu dot org
2004-01-06  0:52 ` cvs-commit at gcc dot gnu dot org
2004-01-06  0:52 ` cvs-commit at gcc dot gnu dot org
2004-01-06  0:55 ` [Bug c++/12815] [3.3 " mmitchel at gcc dot gnu dot org
2004-01-06  0:55 ` mmitchel at gcc dot gnu dot org
2004-01-13  0:01 ` cvs-commit at gcc dot gnu dot org
2004-01-14  9:06 ` 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).