--- a/gcc/ipa-devirt.c 2014-04-08 07:35:11.000000000 +0200 +++ b/gcc/ipa-devirt.c 2014-05-10 16:46:14.502859179 +0200 @@ -987,6 +987,17 @@ context->outer_type = expected_type; context->offset = 0; context->maybe_derived_type = true; + context->maybe_in_construction = true; + /* POD can be changed to an instance of a polymorphic type by + placement new. Here we play safe and assume that any + non-polymorphic type is 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; } --- a/gcc/testsuite/g++.dg/ipa/devirt-11.C 2013-09-08 18:42:21.000000000 +0200 +++ b/gcc/testsuite/g++.dg/ipa/devirt-11.C 2014-05-10 16:46:14.503859198 +0200 @@ -45,5 +45,5 @@ /* While inlining function called once we should devirtualize a new call to fn2 and two to fn3. While doing so the new symbol for fn2 needs to be introduced. */ -/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target" 3 "inline" } } */ +/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target" 1 "inline" } } */ /* { dg-final { cleanup-ipa-dump "inline" } } */ --- a/gcc/testsuite/g++.dg/ipa/devirt-31.C 1970-01-01 01:00:00.000000000 +0100 +++ b/gcc/testsuite/g++.dg/ipa/devirt-31.C 2014-05-10 16:46:14.503859198 +0200 @@ -0,0 +1,23 @@ +/* { dg-options "-O2 -std=c++11 -fdump-ipa-inline" } */ +#include + +class EmbeddedObject { +public: + virtual int val() { return 2; } +}; + +class Container { + alignas(EmbeddedObject) char buffer[sizeof(EmbeddedObject)]; +public: + EmbeddedObject *obj() { return (EmbeddedObject*)buffer; } + Container() { new (buffer) EmbeddedObject(); } +}; + +Container o; + +int main() +{ + __builtin_printf("%d\n", o.obj()->val()); +} +/* { dg-final { scan-ipa-dump-not "__builtin_unreachable" "inline" } } */ +/* { dg-final { cleanup-ipa-dump "inline" } } */