public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57958] New: Incorrect code generation in lambda with argument of type reference to template class
@ 2013-07-23  1:56 tudorb at fb dot com
  2013-07-23  1:59 ` [Bug c++/57958] " tudorb at fb dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: tudorb at fb dot com @ 2013-07-23  1:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57958
           Summary: Incorrect code generation in lambda with argument of
                    type reference to template class
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tudorb at fb dot com

Created attachment 30538
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30538&action=edit
Source file that exhibits broken behavior

gcc (tested in 4.6.2 and 4.7.1) generates incorrect code for the "fn" lambda,
resulting in an extraneous destructor call.  Compiler with -O0 (this is reduced
from a more complex example involving shared_ptr which exhibited the bug with
-O3 as well).

Source attached.  The bug remains without #include <cstdio> and without the
call to printf, which are there just for exposition.

x86_64 disassembly (from gcc 4.7.1):

Dump of assembler code for function operator()(Foo<Data> const&) const:
   0x00000000004006ec <+0>:    push   %rbp
   0x00000000004006ed <+1>:    mov    %rsp,%rbp
   0x00000000004006f0 <+4>:    sub    $0x30,%rsp
   0x00000000004006f4 <+8>:    mov    %rdi,-0x18(%rbp)
   0x00000000004006f8 <+12>:    mov    %rsi,-0x20(%rbp)
   0x00000000004006fc <+16>:    mov    %rdx,-0x28(%rbp)
=> 0x0000000000400700 <+20>:    mov    -0x28(%rbp),%rdx
   0x0000000000400704 <+24>:    lea    -0x1(%rbp),%rax
   0x0000000000400708 <+28>:    mov    %rdx,%rsi
   0x000000000040070b <+31>:    mov    %rax,%rdi
   0x000000000040070e <+34>:    callq  0x400794 <Foo<Data>::Foo(Foo<Data>
const&)>
   0x0000000000400713 <+39>:    lea    -0x1(%rbp),%rax
   0x0000000000400717 <+43>:    mov    %rax,%rdi
   0x000000000040071a <+46>:    callq  0x4007b2 <Foo<Data>::~Foo()>
   0x000000000040071f <+51>:    leaveq
   0x0000000000400720 <+52>:    retq
End of assembler dump.

The bug only happens if Foo is a template.  If Foo is not a template, the code
is correct:

Dump of assembler code for function operator()(Foo const&) const:
   0x00000000004006ec <+0>:    push   %rbp
   0x00000000004006ed <+1>:    mov    %rsp,%rbp
   0x00000000004006f0 <+4>:    sub    $0x20,%rsp
   0x00000000004006f4 <+8>:    mov    %rdi,-0x8(%rbp)
   0x00000000004006f8 <+12>:    mov    %rsi,-0x10(%rbp)
   0x00000000004006fc <+16>:    mov    %rdx,-0x18(%rbp)
=> 0x0000000000400700 <+20>:    mov    -0x18(%rbp),%rdx
   0x0000000000400704 <+24>:    mov    -0x8(%rbp),%rax
   0x0000000000400708 <+28>:    mov    %rdx,%rsi
   0x000000000040070b <+31>:    mov    %rax,%rdi
   0x000000000040070e <+34>:    callq  0x4007a6 <Foo::Foo(Foo const&)>
   0x0000000000400713 <+39>:    mov    -0x8(%rbp),%rax
   0x0000000000400717 <+43>:    leaveq
   0x0000000000400718 <+44>:    retq
End of assembler dump.


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

* [Bug c++/57958] Incorrect code generation in lambda with argument of type reference to template class
  2013-07-23  1:56 [Bug c++/57958] New: Incorrect code generation in lambda with argument of type reference to template class tudorb at fb dot com
@ 2013-07-23  1:59 ` tudorb at fb dot com
  2013-07-23  2:11 ` tudorb at fb dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: tudorb at fb dot com @ 2013-07-23  1:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Tudor Bosman <tudorb at fb dot com> ---
Created attachment 30539
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30539&action=edit
Source file that exhibits broken behavior


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

* [Bug c++/57958] Incorrect code generation in lambda with argument of type reference to template class
  2013-07-23  1:56 [Bug c++/57958] New: Incorrect code generation in lambda with argument of type reference to template class tudorb at fb dot com
  2013-07-23  1:59 ` [Bug c++/57958] " tudorb at fb dot com
@ 2013-07-23  2:11 ` tudorb at fb dot com
  2013-07-23  7:45 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: tudorb at fb dot com @ 2013-07-23  2:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Tudor Bosman <tudorb at fb dot com> ---
g++ -v output (ignore the weird paths):

Using built-in specs.
COLLECT_GCC=l/f/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/g++
COLLECT_LTO_WRAPPER=/mnt/gvfs/third-party/1ebd27fa7983fc50f525eb890ae74ebbb9336a72/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin/../libexec/gcc/x86_64-redhat-linux-gnu/4.7.1/lto-wrapper
Target: x86_64-redhat-linux-gnu
Configured with:
/home/engshare/third-party/src/gcc/gcc-4.7.1/gcc-4.7.1/configure
--build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu
--target=x86_64-redhat-linux-gnu
--prefix=/home/engshare/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc
--exec-prefix=/home/engshare/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc
--bindir=/home/engshare/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/bin
--sbindir=/home/engshare/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/sbin
--sysconfdir=/home/engshare/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/etc
--datadir=/home/engshare/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/share
--includedir=/home/engshare/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/include
--libdir=/home/engshare/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/lib
--libexecdir=/home/engshare/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/libexec
--localstatedir=/home/engshare/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/var
--sharedstatedir=/home/engshare/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/com
--mandir=/home/engshare/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/share/man
--infodir=/home/engshare/third-party/centos5.2-native/gcc/gcc-4.7.1/cc6c9dc/share/info
--with-gmp=/home/engshare/third-party/centos5.2-native/gmp/gmp-5.0.1/da39a3e
--with-mpfr=/home/engshare/third-party/centos5.2-native/mpfr/mpfr-3.0.0/c68f0aa
--with-mpc=/home/engshare/third-party/centos5.2-native/mpc/mpc-0.8.2/18cfc0e
--with-ppl=/home/engshare/third-party/centos5.2-native/ppl/ppl-0.10/c68f0aa
--with-cloog=/home/engshare/third-party/centos5.2-native/cloog/cloog-0.15.7/ab7be4d
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-languages=c,c++,fortran
--disable-libgcj --enable-linker-build-id --with-gnu-as --with-gnu-ld
--with-host-libstdcxx='-L/usr/lib/gcc/x86_64-redhat-linux/4.1.2 -lstdc++'
--disable-multilib --enable-libstdcxx-time
Thread model: posix
gcc version 4.7.1 (GCC)


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

* [Bug c++/57958] Incorrect code generation in lambda with argument of type reference to template class
  2013-07-23  1:56 [Bug c++/57958] New: Incorrect code generation in lambda with argument of type reference to template class tudorb at fb dot com
  2013-07-23  1:59 ` [Bug c++/57958] " tudorb at fb dot com
  2013-07-23  2:11 ` tudorb at fb dot com
@ 2013-07-23  7:45 ` paolo.carlini at oracle dot com
  2014-04-23 20:11 ` dinar at gcc dot gnu.org
  2014-04-24 18:52 ` dinar at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-07-23  7:45 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
           Priority|P3                          |P2
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-07-23
             Blocks|                            |54367
     Ever confirmed|0                           |1


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

* [Bug c++/57958] Incorrect code generation in lambda with argument of type reference to template class
  2013-07-23  1:56 [Bug c++/57958] New: Incorrect code generation in lambda with argument of type reference to template class tudorb at fb dot com
                   ` (2 preceding siblings ...)
  2013-07-23  7:45 ` paolo.carlini at oracle dot com
@ 2014-04-23 20:11 ` dinar at gcc dot gnu.org
  2014-04-24 18:52 ` dinar at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: dinar at gcc dot gnu.org @ 2014-04-23 20:11 UTC (permalink / raw)
  To: gcc-bugs

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

dinar at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |dinar at gcc dot gnu.org
         Resolution|---                         |FIXED

--- Comment #3 from dinar at gcc dot gnu.org ---
fixed on trunk with revision 209721


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

* [Bug c++/57958] Incorrect code generation in lambda with argument of type reference to template class
  2013-07-23  1:56 [Bug c++/57958] New: Incorrect code generation in lambda with argument of type reference to template class tudorb at fb dot com
                   ` (3 preceding siblings ...)
  2014-04-23 20:11 ` dinar at gcc dot gnu.org
@ 2014-04-24 18:52 ` dinar at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: dinar at gcc dot gnu.org @ 2014-04-24 18:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from dinar at gcc dot gnu.org ---
Author: dinar
Date: Thu Apr 24 18:51:29 2014
New Revision: 209757

URL: http://gcc.gnu.org/viewcvs?rev=209757&root=gcc&view=rev
Log:
add recored to gcc/testsuite/ChangeLog for PR c++/57958

Modified:
    trunk/MAINTAINERS
    trunk/gcc/testsuite/ChangeLog


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

end of thread, other threads:[~2014-04-24 18:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-23  1:56 [Bug c++/57958] New: Incorrect code generation in lambda with argument of type reference to template class tudorb at fb dot com
2013-07-23  1:59 ` [Bug c++/57958] " tudorb at fb dot com
2013-07-23  2:11 ` tudorb at fb dot com
2013-07-23  7:45 ` paolo.carlini at oracle dot com
2014-04-23 20:11 ` dinar at gcc dot gnu.org
2014-04-24 18:52 ` dinar at gcc dot gnu.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).