From 75b41faa236ff0bbedf0cfe7de92d0092fd38757 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 8 Jul 2019 09:51:07 +0000 Subject: [PATCH] re PR c++/65143 ([C++11] missing devirtualization for virtual base in "final" classes) 2019-07-08 Paolo Carlini PR c++/65143 * g++.dg/tree-ssa/final2.C: New. * g++.dg/tree-ssa/final3.C: Likewise. From-SVN: r273228 --- gcc/testsuite/ChangeLog | 6 +++++ gcc/testsuite/g++.dg/tree-ssa/final2.C | 35 ++++++++++++++++++++++++++ gcc/testsuite/g++.dg/tree-ssa/final3.C | 23 +++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 gcc/testsuite/g++.dg/tree-ssa/final2.C create mode 100644 gcc/testsuite/g++.dg/tree-ssa/final3.C diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ca899513c0a..61150ea17ba 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-07-08 Paolo Carlini + + PR c++/65143 + * g++.dg/tree-ssa/final2.C: New. + * g++.dg/tree-ssa/final3.C: Likewise. + 2019-07-08 Javier Miranda * gnat.dg/interface10.adb: New testcase. diff --git a/gcc/testsuite/g++.dg/tree-ssa/final2.C b/gcc/testsuite/g++.dg/tree-ssa/final2.C new file mode 100644 index 00000000000..b0fc8603a3d --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/final2.C @@ -0,0 +1,35 @@ +// PR c++/65143 +// { dg-do compile { target c++11 } } +// { dg-additional-options -fdump-tree-gimple } +// { dg-final { scan-tree-dump-times "vptr" 1 gimple } } + +struct A +{ + int i(); +}; + +struct B : public virtual A +{ + int get() + { + return A::i() + 1; + } +}; + +struct C final : public B +{ + int get() + { + return A::i() + 2; + } +}; + +int foo(C& c) +{ + return c.get(); // Need not go via vtable pointer as class C is final +} + +int foo(B& b2) +{ + return b2.get(); // This has to go via vtable as most derived class can change the location of A +} diff --git a/gcc/testsuite/g++.dg/tree-ssa/final3.C b/gcc/testsuite/g++.dg/tree-ssa/final3.C new file mode 100644 index 00000000000..9489fc12c8c --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/final3.C @@ -0,0 +1,23 @@ +// PR c++/65143 +// { dg-do compile { target c++11 } } +// { dg-additional-options -fdump-tree-gimple } +// { dg-final { scan-tree-dump-not "vptr" gimple } } + +struct A +{ + int j; +}; + +struct B : public virtual A +{ +}; + +struct C final : public B +{ + int get(); +}; + +int C::get() +{ + return A::j; +} -- 2.30.2