diff options
author | Roberto Agostino Vitillo <ravitillo@lbl.gov> | 2011-09-20 19:25:24 +0000 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2011-09-20 15:25:24 -0400 |
commit | 62e3d9e6f8d0d4363f4a740300d933f2942b0ac0 (patch) | |
tree | 30b04e27081702eafa9cfec69694ea4f5752fdfe /gcc | |
parent | 47640f4069f5f50af488270e9ca48de1c2737d04 (diff) | |
download | gcc-62e3d9e6f8d0d4363f4a740300d933f2942b0ac0.zip gcc-62e3d9e6f8d0d4363f4a740300d933f2942b0ac0.tar.gz gcc-62e3d9e6f8d0d4363f4a740300d933f2942b0ac0.tar.bz2 |
call.c (build_new_method_call_1): Use non-virtual lookup for final virtual functions.
* call.c (build_new_method_call_1): Use non-virtual lookup
for final virtual functions.
From-SVN: r179014
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/call.c | 5 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/other/final1.C | 26 |
4 files changed, 39 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a6de5fa..b85e16c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2011-09-20 Roberto Agostino Vitillo <ravitillo@lbl.gov> + + * call.c (build_new_method_call_1): Use non-virtual lookup + for final virtual functions. + 2011-09-16 Jason Merrill <jason@redhat.com> PR c++/50424 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index bdbede7..873b48b 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -7282,8 +7282,11 @@ build_new_method_call_1 (tree instance, tree fns, VEC(tree,gc) **args, } else { + /* Optimize away vtable lookup if we know that this function + can't be overridden. */ if (DECL_VINDEX (fn) && ! (flags & LOOKUP_NONVIRTUAL) - && resolves_to_fixed_type_p (instance, 0)) + && (resolves_to_fixed_type_p (instance, 0) + || DECL_FINAL_P (fn) || CLASSTYPE_FINAL (basetype))) flags |= LOOKUP_NONVIRTUAL; if (explicit_targs) flags |= LOOKUP_EXPLICIT_TMPL_ARGS; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a5b3577..bd543b0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-09-20 Roberto Agostino Vitillo <ravitillo@lbl.gov> + + * g++.dg/other/final1.C: new test + 2011-09-20 Ira Rosen <ira.rosen@linaro.org> * g++.dg/vect/slp-pr50413.cc: Don't run the test. Remove main () diff --git a/gcc/testsuite/g++.dg/other/final1.C b/gcc/testsuite/g++.dg/other/final1.C new file mode 100644 index 0000000..ffb30c3 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/final1.C @@ -0,0 +1,26 @@ +/* Verify that final methods are devirtualized */ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-original -std=c++0x" } */ + +struct A final +{ + virtual void foo () + { + } +}; + +struct B +{ + virtual void foo () final + { + } +}; + +void fun(A* a, B* b) +{ + a->foo(); + b->foo(); +} + +/* { dg-final { scan-tree-dump-times "A::foo" 2 "original" } } */ +/* { dg-final { scan-tree-dump-times "B::foo" 2 "original" } } */ |