http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60965
--- Comment #6 from Jan Hubicka <hubicka at gcc dot gnu.org> --- I am testing the attached patch. Index: ipa-devirt.c =================================================================== --- ipa-devirt.c (revision 209913) +++ ipa-devirt.c (working copy) @@ -1137,6 +1159,17 @@ context->outer_type = expected_type; context->offset = 0; context->maybe_derived_type = true; + context->maybe_in_construction = true; + /* Non-POD can be changed to instance of polymorphic type by + placement new. Here we play safe and assume that any + non-polymorphic type is non-POD. */ + if ((TREE_CODE (type) != RECORD_TYPE + || !TYPE_BINFO (type) + || !polymorphic_type_binfo_p (TYPE_BINFO (type))) + && (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST + || (offset + tree_to_uhwi (TYPE_SIZE (expected_type)) <= + tree_to_uhwi (TYPE_SIZE (type))))) + return true; return false; } Can you, please, double check that it fixes the Java issues? It is a bit questionable on how precisely define what type transitions are allowed by placement new. This is quite conservative definition except for the requirement that type needs to be large enough to contain the newly built type. This condition may need relaxation for open ended types (ones having arrays at end, I think that is rule used by aliasing code in simliar case), but I believe at least for 4.9 this is non-issue: we only care non-heap decls and this is not a problem here.