public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53186] New: [C++11] missing devirtualization for operators "final"
@ 2012-05-02 7:59 vincenzo.innocente at cern dot ch
2012-05-03 0:51 ` [Bug c++/53186] " paolo.carlini at oracle dot com
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2012-05-02 7:59 UTC (permalink / raw)
To: gcc-bugs
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)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/53186] [C++11] missing devirtualization for operators "final"
2012-05-02 7:59 [Bug c++/53186] New: [C++11] missing devirtualization for operators "final" vincenzo.innocente at cern dot ch
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
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-05-03 0:51 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53186
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2012-05-03
AssignedTo|unassigned at gcc dot |paolo.carlini at oracle dot
|gnu.org |com
Target Milestone|--- |4.8.0
Ever Confirmed|0 |1
--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-05-03 00:50:41 UTC ---
Confirmed.
It looks like we do not devirtualize all sorts of operators (conversions,
arithmetic, logic...) but the recipe is essentially the same.
I'm going to attach a draft patch which you may want to start testing (passes
the testsuite).
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/53186] [C++11] missing devirtualization for operators "final"
2012-05-02 7:59 [Bug c++/53186] New: [C++11] missing devirtualization for operators "final" vincenzo.innocente at cern dot ch
@ 2012-05-03 0:51 ` paolo.carlini at oracle dot com
2012-05-03 0:51 ` paolo.carlini at oracle dot com
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-05-03 0:51 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53186
--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-05-03 00:51:22 UTC ---
Created attachment 27295
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27295
Draft
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/53186] [C++11] missing devirtualization for operators "final"
2012-05-02 7:59 [Bug c++/53186] New: [C++11] missing devirtualization for operators "final" vincenzo.innocente at cern dot ch
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
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2012-05-03 6:43 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53186
--- Comment #3 from vincenzo Innocente <vincenzo.innocente at cern dot ch> 2012-05-03 06:42:46 UTC ---
not bad…
hope it could be back ported to 4.7.1
c++ -std=gnu++11 -c opFinal.cpp; nm opFinal.o; otool -t -v -V -X opFinal.o |
c++filt
00000000000000b0 s EH_frame1
0000000000000021 T __Z4fooAR1A
0000000000000060 T __Z5fooF1R2F1
0000000000000094 T __Z5fooF2R2F2
0000000000000000 T __Z6fooAopR1A
0000000000000046 T __Z7fooF1opR2F1
000000000000007a T __Z7fooF2opR2F2
U __ZN2F11mEv
U __ZN2F1clEv
U __ZN2F21mEv
U __ZN2F2clEv
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,%rdi
callq F1::operator()()
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,%rdi
callq F2::operator()()
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/53186] [C++11] missing devirtualization for operators "final"
2012-05-02 7:59 [Bug c++/53186] New: [C++11] missing devirtualization for operators "final" vincenzo.innocente at cern dot ch
` (2 preceding siblings ...)
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
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2012-05-03 6:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53186
--- Comment #4 from vincenzo Innocente <vincenzo.innocente at cern dot ch> 2012-05-03 06:46:01 UTC ---
Ciao Paolo,
grazie per il patch.
Io no so quale sia lo "standard" gcc, ma credo sarebbe meglio distribuire patch
che si applicano direttamente dalla directory principale e non da una
subdirectory specifica.
Il tuo in particolare richiede
cd gcc/cp
patch -p) < …
cd ../../
make
v.
On 3 May, 2012, at 2:51 AM, paolo.carlini at oracle dot com wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53186
>
> --- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-05-03 00:51:22 UTC ---
> Created attachment 27295
> --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27295
> Draft
>
> --
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/53186] [C++11] missing devirtualization for operators "final"
2012-05-02 7:59 [Bug c++/53186] New: [C++11] missing devirtualization for operators "final" vincenzo.innocente at cern dot ch
` (3 preceding siblings ...)
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
6 siblings, 0 replies; 8+ messages in thread
From: paolo at gcc dot gnu.org @ 2012-05-03 14:29 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53186
--- Comment #5 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2012-05-03 14:28:52 UTC ---
Author: paolo
Date: Thu May 3 14:28:46 2012
New Revision: 187097
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187097
Log:
/cp
2012-05-03 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53186
* call.c (build_over_call): Handle final member functions
and class types.
(build_new_method_call_1): Do not handle here.
/testsuite
2012-05-03 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53186
* g++.dg/other/final2.C: New.
Added:
trunk/gcc/testsuite/g++.dg/other/final2.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/call.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/53186] [C++11] missing devirtualization for operators "final"
2012-05-02 7:59 [Bug c++/53186] New: [C++11] missing devirtualization for operators "final" vincenzo.innocente at cern dot ch
` (4 preceding siblings ...)
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
6 siblings, 0 replies; 8+ messages in thread
From: paolo at gcc dot gnu.org @ 2012-05-03 14:32 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53186
--- Comment #6 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2012-05-03 14:32:20 UTC ---
Author: paolo
Date: Thu May 3 14:32:15 2012
New Revision: 187098
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187098
Log:
/cp
2012-05-03 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53186
* call.c (build_over_call): Handle final member functions
and class types.
(build_new_method_call_1): Do not handle here.
/testsuite
2012-05-03 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53186
* g++.dg/other/final2.C: New.
Added:
branches/gcc-4_7-branch/gcc/testsuite/g++.dg/other/final2.C
Modified:
branches/gcc-4_7-branch/gcc/cp/ChangeLog
branches/gcc-4_7-branch/gcc/cp/call.c
branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/53186] [C++11] missing devirtualization for operators "final"
2012-05-02 7:59 [Bug c++/53186] New: [C++11] missing devirtualization for operators "final" vincenzo.innocente at cern dot ch
` (5 preceding siblings ...)
2012-05-03 14:32 ` paolo at gcc dot gnu.org
@ 2012-05-03 14:33 ` paolo.carlini at oracle dot com
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-05-03 14:33 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53186
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
Target Milestone|4.8.0 |4.7.1
--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-05-03 14:33:09 UTC ---
Done for mainline and 4.7.1.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-05-03 14:33 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-02 7:59 [Bug c++/53186] New: [C++11] missing devirtualization for operators "final" vincenzo.innocente at cern dot ch
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
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).