https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65475
--- Comment #3 from Jan Hubicka <hubicka at gcc dot gnu.org> --- The following should help: Index: ipa-devirt.c =================================================================== --- ipa-devirt.c (revision 221528) +++ ipa-devirt.c (working copy) @@ -1412,9 +1412,18 @@ add_type_duplicate (odr_type val, tree t if (!val->types_set) val->types_set = new hash_set<tree>; + /* Chose polymorphic type as leader (this happens only in case of ODR + violations. */ + if ((TREE_CODE (type) == RECORD_TYPE && TYPE_BINFO (type) + && polymorphic_type_binfo_p (TYPE_BINFO (type))) + && (TREE_CODE (val->type) != RECORD_TYPE || !TYPE_BINFO (val->type) + || !polymorphic_type_binfo_p (TYPE_BINFO (val->type)))) + { + prevail = true; + build_bases = true; + } /* Always prefer complete type to be the leader. */ - - if (!COMPLETE_TYPE_P (val->type) && COMPLETE_TYPE_P (type)) + else if (!COMPLETE_TYPE_P (val->type) && COMPLETE_TYPE_P (type)) { prevail = true; build_bases = TYPE_BINFO (type);