From 62e3d9e6f8d0d4363f4a740300d933f2942b0ac0 Mon Sep 17 00:00:00 2001 From: Roberto Agostino Vitillo Date: Tue, 20 Sep 2011 19:25:24 +0000 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/call.c | 5 ++++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/other/final1.C | 26 ++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/other/final1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a6de5fae3c7..b85e16c3eb0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2011-09-20 Roberto Agostino Vitillo + + * call.c (build_new_method_call_1): Use non-virtual lookup + for final virtual functions. + 2011-09-16 Jason Merrill PR c++/50424 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index bdbede7fbe6..873b48b32b5 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 a5b35772c16..bd543b07811 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-09-20 Roberto Agostino Vitillo + + * g++.dg/other/final1.C: new test + 2011-09-20 Ira Rosen * 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 00000000000..ffb30c3ec2c --- /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" } } */ -- 2.30.2