public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/10741: inefficient compiler generated copy constructor
@ 2003-05-12  1:16 dann
  0 siblings, 0 replies; only message in thread
From: dann @ 2003-05-12  1:16 UTC (permalink / raw)
  To: gcc-gnats


>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:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-05-12  1:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-12  1:16 c++/10741: inefficient compiler generated copy constructor dann

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).