From: Jason Merrill Date: Tue, 25 Jun 2019 16:15:40 +0000 (-0400) Subject: class.c (resolves_to_fixed_type_p): Check CLASSTYPE_FINAL. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a4cc28287993320b4550a8a1d3842172d41b8d1c;p=gcc.git class.c (resolves_to_fixed_type_p): Check CLASSTYPE_FINAL. * class.c (resolves_to_fixed_type_p): Check CLASSTYPE_FINAL. If we have a pointer to final class, we know the dynamic type of the object must be that class, because it can't have any derived classes. From-SVN: r272656 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a0f61668559..dee69b87eba 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,7 @@ +2019-06-25 Jason Merrill + + * class.c (resolves_to_fixed_type_p): Check CLASSTYPE_FINAL. + 2019-06-25 Jakub Jelinek PR c++/90969 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index e0df9ef2b20..a679e651bbe 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -7477,10 +7477,12 @@ resolves_to_fixed_type_p (tree instance, int* nonnull) } fixed = fixed_type_or_null (instance, nonnull, &cdtorp); - if (fixed == NULL_TREE) - return 0; if (INDIRECT_TYPE_P (t)) t = TREE_TYPE (t); + if (CLASS_TYPE_P (t) && CLASSTYPE_FINAL (t)) + return 1; + if (fixed == NULL_TREE) + return 0; if (!same_type_ignoring_top_level_qualifiers_p (t, fixed)) return 0; return cdtorp ? -1 : 1; diff --git a/gcc/testsuite/g++.dg/tree-ssa/final1.C b/gcc/testsuite/g++.dg/tree-ssa/final1.C new file mode 100644 index 00000000000..43407f09675 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/final1.C @@ -0,0 +1,8 @@ +// { dg-do compile { target c++11 } } +// { dg-additional-options -fdump-tree-gimple } +// { dg-final { scan-tree-dump-not "vptr" gimple } } + +struct A { int i; }; +struct B final: public virtual A { int j; }; + +int f(B* b) { return b->i; }