This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/23372] New: Temporary aggregate copy not elided when passing parameters by value


This bug is similar to bug 16405, but although 16405 was fixed in 4.0, this one
is still present and is a regression from GCC 3.4 (not from 3.3 as was the
previous one). So I prefer opening a new bug-report.

The testcase simply calls a function f by passing the parameter by value:

struct A {
  int a[1000];
  //A(A const &);
};
void f(A);
void g(A *a) { f(*a); }

When compiled with gcc 3.3 and 3.4, the generated code for g is optimal: the
value *a is directly copied in the stack frame that will be used by f. With gcc
4.0, there is first a temporary copy in the stack frame of g, before copying the
value in the stack frame of f (two memcpys instead of one).

When putting a dummy copy constructor, both memcpys disappear: the code is
optimal. So the problem seems to be with the default trivial copy constructor.

The testcase is compiled with "g++-4.0 -O3", Debian package:

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 --enable-nls
--without-included-gettext --enable-threads=posix --program-suffix=-4.0
--enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk
--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 --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.2 20050806 (prerelease) (Debian 4.0.1-4)

-- 
           Summary: Temporary aggregate copy not elided when passing
                    parameters by value
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: guillaume dot melquiond at ens-lyon dot fr
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i486-linux-gnu


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]