public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "vincenzo.innocente at cern dot ch" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/53186] New: [C++11] missing devirtualization for operators "final"
Date: Wed, 02 May 2012 07:59:00 -0000	[thread overview]
Message-ID: <bug-53186-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             Bug #: 53186
           Summary: [C++11] missing devirtualization for operators "final"
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: vincenzo.innocente@cern.ch


the example below shows how the keyword "final" has NO effect in devirtualizing
operators while it works for methods (as solved in PR49488)

cat  opFinal.cpp
struct A {
  virtual void operator()();
  virtual void m();
};

struct F1 {
  virtual void operator()() final;
  virtual void m() final;
};

struct F2 final {
  virtual void operator()();
  virtual void m();
};


void fooAop(A & a) {a();}
void fooA(A & a) {a.m();}
void fooF1op(F1 & a) {a();}
void fooF1(F1 & a) {a.m();}
void fooF2op(F2 & a) {a();}
void fooF2(F2 & a) {a.m();}
c++ -std=gnu++11 -c opFinal.cpp; nm opFinal.o; otool -t -v -V -X opFinal.o |
c++filt
00000000000000c0 s EH_frame1
0000000000000021 T __Z4fooAR1A
0000000000000067 T __Z5fooF1R2F1
00000000000000a2 T __Z5fooF2R2F2
0000000000000000 T __Z6fooAopR1A
0000000000000046 T __Z7fooF1opR2F1
0000000000000081 T __Z7fooF2opR2F2
                 U __ZN2F11mEv
                 U __ZN2F21mEv
fooAop(A&):
pushq    %rbp
movq    %rsp,%rbp
subq    $0x10,%rsp
movq    %rdi,0xf8(%rbp)
movq    0xf8(%rbp),%rax
movq    (%rax),%rax
movq    (%rax),%rax
movq    0xf8(%rbp),%rdx
movq    %rdx,%rdi
call    *%rax
leave
ret
fooA(A&):
pushq    %rbp
movq    %rsp,%rbp
subq    $0x10,%rsp
movq    %rdi,0xf8(%rbp)
movq    0xf8(%rbp),%rax
movq    (%rax),%rax
addq    $0x08,%rax
movq    (%rax),%rax
movq    0xf8(%rbp),%rdx
movq    %rdx,%rdi
call    *%rax
leave
ret
fooF1op(F1&):
pushq    %rbp
movq    %rsp,%rbp
subq    $0x10,%rsp
movq    %rdi,0xf8(%rbp)
movq    0xf8(%rbp),%rax
movq    (%rax),%rax
movq    (%rax),%rax
movq    0xf8(%rbp),%rdx
movq    %rdx,%rdi
call    *%rax
leave
ret
fooF1(F1&):
pushq    %rbp
movq    %rsp,%rbp
subq    $0x10,%rsp
movq    %rdi,0xf8(%rbp)
movq    0xf8(%rbp),%rax
movq    %rax,%rdi
callq    F1::m()
leave
ret
fooF2op(F2&):
pushq    %rbp
movq    %rsp,%rbp
subq    $0x10,%rsp
movq    %rdi,0xf8(%rbp)
movq    0xf8(%rbp),%rax
movq    (%rax),%rax
movq    (%rax),%rax
movq    0xf8(%rbp),%rdx
movq    %rdx,%rdi
call    *%rax
leave
ret
fooF2(F2&):
pushq    %rbp
movq    %rsp,%rbp
subq    $0x10,%rsp
movq    %rdi,0xf8(%rbp)
movq    0xf8(%rbp),%rax
movq    %rax,%rdi
callq    F2::m()
leave
ret
host-001:bugs48 innocent$ cat  opFinal.cpp
struct A {
  virtual void operator()();
  virtual void m();
};

struct F1 {
  virtual void operator()() final;
  virtual void m() final;
};

struct F2 final {
  virtual void operator()();
  virtual void m();
};


void fooAop(A & a) {a();}
void fooA(A & a) {a.m();}
void fooF1op(F1 & a) {a();}
void fooF1(F1 & a) {a.m();}
void fooF2op(F2 & a) {a();}
void fooF2(F2 & a) {a.m();}



host-001:bugs48 innocent$ c++ -std=gnu++11 -c opFinal.cpp; nm opFinal.o; otool
-t -v -V -X opFinal.o | c++filt
00000000000000c0 s EH_frame1
0000000000000021 T __Z4fooAR1A
0000000000000067 T __Z5fooF1R2F1
00000000000000a2 T __Z5fooF2R2F2
0000000000000000 T __Z6fooAopR1A
0000000000000046 T __Z7fooF1opR2F1
0000000000000081 T __Z7fooF2opR2F2
                 U __ZN2F11mEv
                 U __ZN2F21mEv
fooAop(A&):
pushq    %rbp
movq    %rsp,%rbp
subq    $0x10,%rsp
movq    %rdi,0xf8(%rbp)
movq    0xf8(%rbp),%rax
movq    (%rax),%rax
movq    (%rax),%rax
movq    0xf8(%rbp),%rdx
movq    %rdx,%rdi
call    *%rax
leave
ret
fooA(A&):
pushq    %rbp
movq    %rsp,%rbp
subq    $0x10,%rsp
movq    %rdi,0xf8(%rbp)
movq    0xf8(%rbp),%rax
movq    (%rax),%rax
addq    $0x08,%rax
movq    (%rax),%rax
movq    0xf8(%rbp),%rdx
movq    %rdx,%rdi
call    *%rax
leave
ret
fooF1op(F1&):
pushq    %rbp
movq    %rsp,%rbp
subq    $0x10,%rsp
movq    %rdi,0xf8(%rbp)
movq    0xf8(%rbp),%rax
movq    (%rax),%rax
movq    (%rax),%rax
movq    0xf8(%rbp),%rdx
movq    %rdx,%rdi
call    *%rax
leave
ret
fooF1(F1&):
pushq    %rbp
movq    %rsp,%rbp
subq    $0x10,%rsp
movq    %rdi,0xf8(%rbp)
movq    0xf8(%rbp),%rax
movq    %rax,%rdi
callq    F1::m()
leave
ret
fooF2op(F2&):
pushq    %rbp
movq    %rsp,%rbp
subq    $0x10,%rsp
movq    %rdi,0xf8(%rbp)
movq    0xf8(%rbp),%rax
movq    (%rax),%rax
movq    (%rax),%rax
movq    0xf8(%rbp),%rdx
movq    %rdx,%rdi
call    *%rax
leave
ret
fooF2(F2&):
pushq    %rbp
movq    %rsp,%rbp
subq    $0x10,%rsp
movq    %rdi,0xf8(%rbp)
movq    0xf8(%rbp),%rax
movq    %rax,%rdi
callq    F2::m()
leave
ret
host-001:bugs48 innocent$ c++ -v
Using built-in specs.
COLLECT_GCC=c++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin11.3.0/4.8.0/lto-wrapper
Target: x86_64-apple-darwin11.3.0
Configured with: ./configure --enable-languages=c,c++,fortran
--disable-multilib --disable-bootstrap --enable-lto -disable-libitm :
(reconfigured) ./configure --enable-languages=c,c++,fortran --disable-multilib
--disable-bootstrap --enable-lto -disable-libitm
Thread model: posix
gcc version 4.8.0 20120416 (experimental) [trunk revision 186494] (GCC)


             reply	other threads:[~2012-05-02  7:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-02  7:59 vincenzo.innocente at cern dot ch [this message]
2012-05-03  0:51 ` [Bug c++/53186] " paolo.carlini at oracle dot com
2012-05-03  0:51 ` paolo.carlini at oracle dot com
2012-05-03  6:43 ` vincenzo.innocente at cern dot ch
2012-05-03  6:46 ` vincenzo.innocente at cern dot ch
2012-05-03 14:29 ` paolo at gcc dot gnu.org
2012-05-03 14:32 ` paolo at gcc dot gnu.org
2012-05-03 14:33 ` paolo.carlini at oracle dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-53186-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).