public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/16115] New: 3.5: problem with argument passing via temporary (breaks auto_ptr)
@ 2004-06-21 16:43 gcc-bugzilla at gcc dot gnu dot org
  2004-06-21 16:55 ` [Bug tree-optimization/16115] [3.5 regression] " bangerth at dealii dot org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2004-06-21 16:43 UTC (permalink / raw)
  To: gcc-bugs



The code y1.cc below seems to produce the wrong result if it is compiled
with -O2.  (It works ok, however, with either -O1 or -O3.)


$ g++ -O2 -o y1 y1.cc
$ ./y1
a bfffb690
d 0 0
dtor 1 bfffb690
$

In the last line of output, i expect the value of a printed by the destructor
to be 0; however, it is still 1.


Here is the generated code for the foo() and main() functions (passed
through c++filt, omitting exception handling labels and cleanups):

foo(auto_ptr):
	pushl	%ebp
	xorl	%edx, %edx
	movl	%esp, %ebp
	xorl	%eax, %eax
	subl	$24, %esp
	movl	%edx, 8(%esp)
	movl	%eax, 4(%esp)
	movl	$.LC0, (%esp)
	call	printf
	leave
	ret


main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$40, %esp
	andl	$-16, %esp
	subl	$16, %esp
	movl	%esi, -4(%ebp)
	leal	-24(%ebp), %esi
	movl	%ebx, -8(%ebp)
	movl	$1, -24(%ebp)
	movl	%esi, 4(%esp)
	movl	$.LC1, (%esp)
	call	printf
	movl	%esi, (%esp)
	call	foo(auto_ptr)
	movl	-24(%ebp), %eax
	movl	%esi, 8(%esp)
	movl	$.LC2, (%esp)
	movl	%eax, 4(%esp)
	call	printf
	movl	-8(%ebp), %ebx
	xorl	%eax, %eax
	movl	-4(%ebp), %esi
	movl	%ebp, %esp
	popl	%ebp
	ret
...
.LC0:
	.string	"d %x %x\n"
.LC1:
	.string	"a %x\n"
.LC2:
	.string	"dtor %x %x\n"


It looks like something is going wrong with handling the temporary object
that gets passed to foo().

With gcc 3.4, this code works as expected, so this is a regression.


FYI, here is an earlier stage in the reduction of the test case, with
the auto_ptr class left intact.  Here, the problem shows up as a double
deletion of the allocated object.  Again, it shows up at -O2, but not
at -O1 or -O3.

$ g++ -O2 -o y y.cc
$ ./y
a ctor 804a008
a dtor 804a008
a dtor 804a008
$


y.cc -------------------------------------------
#include <memory>

struct A
{
  A() { printf ("a ctor %x\n", this); }
  ~A() { printf ("a dtor %x\n", this); }
};


void foo (std::auto_ptr<A> a)
{
  delete a.release();
}


int main ()
{
  foo (std::auto_ptr<A> (new A));
}
------------------------------------------------

Environment:
System: Linux karma 2.6.6 #15 Thu May 13 15:07:54 EDT 2004 i686 i686 i386 GNU/Linux
Architecture: i686

	<machine, os, target, libraries (multiple lines)>
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /home/sss/gcc/gcc/configure --prefix=/usr/local/gcc --enable-threads=posix --enable-long-long --enable-languages=c,c++,f95

How-To-Repeat:

Compile the following with -O2 and run:

y1.cc ------------------------------------------
extern "C" int printf(const char*, ...);

struct auto_ptr
{
  int _M_ptr;
  auto_ptr(int p) : _M_ptr(1) { printf ("a %x\n", this); }
  ~auto_ptr() { printf ("dtor %x %x\n", _M_ptr, this); }
  void release() {  _M_ptr = 0;  }
  auto_ptr(const auto_ptr&a) : _M_ptr (a._M_ptr) { printf ("b %x\n", this); }
};


void foo (auto_ptr a)
{
  a.release();
  printf ("d %x %x\n", a._M_ptr, 0);
}

int main ()
{
  foo (0);
}
------------------------------------------------
------- Additional Comments From snyder at fnal dot gov  2004-06-21 16:43 -------
Fix:
	<how to correct or work around the problem, if known (multiple lines)>

-- 
           Summary: 3.5: problem with argument passing via temporary (breaks
                    auto_ptr)
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: snyder at fnal dot gov
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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

end of thread, other threads:[~2004-07-18 14:15 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-21 16:43 [Bug tree-optimization/16115] New: 3.5: problem with argument passing via temporary (breaks auto_ptr) gcc-bugzilla at gcc dot gnu dot org
2004-06-21 16:55 ` [Bug tree-optimization/16115] [3.5 regression] " bangerth at dealii dot org
2004-06-21 18:26 ` [Bug tree-optimization/16115] [3.5 regression] double-destruction " bangerth at dealii dot org
2004-06-22  6:34 ` pinskia at gcc dot gnu dot org
2004-06-22  8:00 ` rth at gcc dot gnu dot org
2004-06-22 21:08 ` rth at gcc dot gnu dot org
2004-06-22 21:48 ` rth at gcc dot gnu dot org
2004-06-24 20:07 ` cvs-commit at gcc dot gnu dot org
2004-06-24 20:08 ` cvs-commit at gcc dot gnu dot org
2004-06-24 21:16 ` pinskia at gcc dot gnu dot org
2004-07-06  7:16 ` cvs-commit at gcc dot gnu dot org
2004-07-06  7:23 ` mmitchel at gcc dot gnu dot org
2004-07-18  5:44 ` cvs-commit at gcc dot gnu dot org
2004-07-18 13:41 ` cvs-commit at gcc dot gnu dot org
2004-07-18 14:15 ` 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).