c++/10741: inefficient compiler generated copy constructor
dann@godzilla.ics.uci.edu
dann@godzilla.ics.uci.edu
Mon May 12 03:03:00 GMT 2003
>Number: 10741
>Category: c++
>Synopsis: inefficient compiler generated copy constructor
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon May 12 01:16:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Dan Nicolaescu <dann@godzilla.ics.uci.edu>
>Release: all
>Organization:
>Environment:
i686-redhat-linux-gnu
>Description:
Given the following code:
class Complex {
public:
int re, im;
Complex( int r, int i ) : re(r), im(i) {}
#ifdef MYCONSTRUCTOR
Complex( const Complex & F ) : re(F.re),im(F.im) {}
#endif
Complex() {}
};
Complex Yy;
void oop_style()
{
Complex factor (53, 37);
Yy = factor;
}
The oop_style function is compiled to (on x86):
_Z9oop_stylev:
.LFB11:
subl $12, %esp #,
.LCFI0:
movl $53, (%esp) #,
movl (%esp), %edx #, tmp64
movl $37, 4(%esp) #, <variable>.im
movl 4(%esp), %ecx #,
movl %edx, Yy # tmp64,
movl %ecx, Yy+4 #,
addl $12, %esp #,
ret
when using g++ -O3 -fverbose-asm -fomit-frame-pointer
and to:
_Z9oop_stylev:
.LFB14:
subl $28, %esp #,
.LCFI0:
movl $53, %eax #,
movl $37, %edx #,
movl %eax, Yy #,
movl %edx, Yy+4 #,
addl $28, %esp #,
ret
when using g++ -O3 -DMYCONSTRUCTOR -fverbose-asm -fomit-frame-pointer
Note the extra move to the stack when using the compiler generated
constructor.
See also:
http://gcc.gnu.org/ml/gcc/2003-05/msg00485.html
>How-To-Repeat:
Follow the instructions in the description.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list