http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60600
--- Comment #2 from Martin Jambor <jamborm at gcc dot gnu.org> --- Well, this is ICE on code with undefined behavior. Function test calls itself with a parameter which is a reference to an object of type child2 and then static_casts it to a reference to child1. These are non-PODs, neither of these types is an ancestor of the other and thus the use of static_cast is not allowed by the C++ standard. ipa-prop based devirtualization does not see the cast, it thinks the object is of type child2, and therefore the virtual method it looks up is intermediate::topf. Then it does a consistency check to see whether type hierarchy based devirtualization has that function among its possible targets. However, this devirtualization starts with child1 as its outer type and thus it concludes the only possible target is top::topf. The consistency check fails and we get an ICE on assert. The assert has to go but I wonder whether we want to give up when possible_polymorphic_call_target_p returns false so that we don't try to optimize such undefined cases. We might even give a warning, although making the warning useful to the user might require some effort.