From patchwork Mon May 5 19:44:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 345857 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 13D73140317 for ; Tue, 6 May 2014 05:44:50 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=Uf8qRGHuJQTeesRO7tFbt/n+xLYWeaXt/U/C+ra0d1k/n2ZsgbZkX TqG5mCYiIQDEPzVI2n19u8xIVYLesM0JUR7jQTsT5avIhuTAqnuyu8oxgxJn6fez p4F6rgg7qRCJj0bJpMxNgDb/d6lMXzSliS7Z4gqSJcnsQPi0SaLfAI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=IXeRwNWRBeoEK5GCW8dCBsPXHqg=; b=okN61Y95Lhec3uAr7GJJ 1Atuxy2Pjf5NN1219QuVJBTP4JuE4TESx6W5Y5IHmq+whZ9a21PYIE1kW/IiTi7j cfWaey0eGexwQ9lhWm8/LRkpl+Lmp+/2tPqlKWRsJUq/NhUIZSrlAf0Ed6JJMtXf PYXSeoGdl9KmjX9gZLDx6uk= Received: (qmail 17762 invoked by alias); 5 May 2014 19:44:44 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 17748 invoked by uid 89); 5 May 2014 19:44:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 05 May 2014 19:44:42 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 904505404D4; Mon, 5 May 2014 21:44:38 +0200 (CEST) Date: Mon, 5 May 2014 21:44:38 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix PR ipa/60965 (placement new wrt ipa-devirt) Message-ID: <20140505194438.GB26890@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Hi, this patch fixes unfortunate thinko in get_class_context that invalidates transitions from non-POD type to a polymorphic type that may happen by virtue of placement new and apparently breaks openJDK and Qt. I really tried to keep placement new in mind when implementing ipa-devirt, so hope there are no similar negaitve surprises. The patch disables about 200 out of 30000 devirtualizations happening in Firefox. I have commited it to 4.9 and will commit to mainline once testing finishes. Honza PR ipa/60965 * g++.dg/ipa/devirt-31.C: New testcase. * g++.dg/ipa/devirt-11.C: Adjust testcase. * ipa-devirt.c (get_class_context): Allow POD to change to non-POD. Index: testsuite/g++.dg/ipa/devirt-31.C =================================================================== --- testsuite/g++.dg/ipa/devirt-31.C (revision 0) +++ testsuite/g++.dg/ipa/devirt-31.C (revision 0) @@ -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" } } */ Index: testsuite/g++.dg/ipa/devirt-11.C =================================================================== --- testsuite/g++.dg/ipa/devirt-11.C (revision 210049) +++ testsuite/g++.dg/ipa/devirt-11.C (working copy) @@ -45,5 +45,5 @@ bar () /* 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" } } */ Index: ipa-devirt.c =================================================================== --- ipa-devirt.c (revision 210049) +++ ipa-devirt.c (working copy) @@ -987,6 +987,17 @@ give_up: 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; }