https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68220
--- Comment #5 from Jan Hubicka <hubicka at gcc dot gnu.org> --- I am testing the following. This bug crept in when adding the dynamic types: Index: ipa-polymorphic-call.c =================================================================== --- ipa-polymorphic-call.c (revision 229820) +++ ipa-polymorphic-call.c (working copy) @@ -154,6 +154,8 @@ ipa_polymorphic_call_context::restrict_t && tree_to_shwi (TYPE_SIZE (outer_type)) >= 0 && tree_to_shwi (TYPE_SIZE (outer_type)) <= offset) { + bool der = maybe_derived_type; /* clear_outer_type will reset it. */ + bool dyn = dynamic; clear_outer_type (otr_type); type = otr_type; cur_offset = 0; @@ -162,7 +164,7 @@ ipa_polymorphic_call_context::restrict_t For dynamic types, we really do not have information about size of the memory location. It is possible that completely different type is stored after outer_type. */ - if (!maybe_derived_type && !dynamic) + if (!der && !dyn) { clear_speculation (); invalid = true; @@ -467,6 +469,7 @@ contains_type_p (tree outer_type, HOST_W context.offset = offset; context.outer_type = TYPE_MAIN_VARIANT (outer_type); context.maybe_derived_type = false; + context.dynamic = false; return context.restrict_to_inner_class (otr_type, consider_placement_new, consider_bases); }