From patchwork Mon Dec 30 16:47:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 305792 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 495F42C00CF for ; Tue, 31 Dec 2013 03:47:35 +1100 (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:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=ZnT3qCXEXnj2SICFTfceuEDgKwTbw pcpFN88MTraBeZSMLXZv9glgChNjiHB7pif3BPX1k7j2Rbz2w2Cmy/T0BOfzwPtV gkfM+ER/gzYfB53RRwicDWboOd8Hm5+EQPlWX/H26gE2F0tzw7fPaqvDf75T3m+H u4gakxqw5N+BQs= 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:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=LNAQd5is4Nz6S5UzyXhus5aV3ok=; b=ybR 8No5QO5u8TkFAKqm25wzxE5sGwjTV6G0iDvNIMvX/IYa//+1kQuz9zBRaiSKV+5D rFp78YGh03BnTMxHLcks7GyoWEY56md2v7+QAL1RvyqkTxvh2aON1B22tCWWxIP3 25MUmcuzcKcXY/Z3vEKXXRm1n2eYg5o0s4q8t0e8= Received: (qmail 32574 invoked by alias); 30 Dec 2013 16:47:28 -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 32563 invoked by uid 89); 30 Dec 2013 16:47:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Dec 2013 16:47:27 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rBUGlQDd031232 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 30 Dec 2013 11:47:26 -0500 Received: from tucnak.zalov.cz (vpn1-4-159.ams2.redhat.com [10.36.4.159]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id rBUGlPW5031842 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 30 Dec 2013 11:47:26 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.7/8.14.7) with ESMTP id rBUGlOCk010375; Mon, 30 Dec 2013 17:47:24 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.7/8.14.7/Submit) id rBUGlOvi010374; Mon, 30 Dec 2013 17:47:24 +0100 Date: Mon, 30 Dec 2013 17:47:24 +0100 From: Jakub Jelinek To: Richard Biener , Jan Hubicka Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622) Message-ID: <20131230164723.GD892@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi! Setting gimple_call_set_fndecl of a random method call to __bultin_unreachable can't work properly, the method call probably passes in arguments that __builtin_unreachable doesn't expect, and if the method call has LHS, we'll ICE, because __builtin_unreachable doesn't have a LHS. Fixed by not doing anything for fold_stmt_inplace and for fold_stmt just adding a new __buitin_unreachable () call before the method call, DCE will DTRT then and we don't have to bother with adding some dummy stmt to set up the lhs etc. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-12-30 Jakub Jelinek PR tree-optimization/59622 * gimple-fold.c (gimple_fold_call): Don't replace OBJ_TYPE_REF call fndecl with 0 possible targets with BUILT_IN_UNREACHABLE, instead only for !inplace add a __builtin_unreachable () call before the call. * g++.dg/opt/pr59622.C: New test. Jakub --- gcc/gimple-fold.c.jj 2013-12-18 17:32:59.000000000 +0100 +++ gcc/gimple-fold.c 2013-12-30 11:36:38.093211391 +0100 @@ -1184,13 +1184,19 @@ gimple_fold_call (gimple_stmt_iterator * = possible_polymorphic_call_targets (callee, &final); if (final && targets.length () <= 1) { - tree fndecl; if (targets.length () == 1) - fndecl = targets[0]->decl; - else - fndecl = builtin_decl_implicit (BUILT_IN_UNREACHABLE); - gimple_call_set_fndecl (stmt, fndecl); - changed = true; + { + gimple_call_set_fndecl (stmt, targets[0]->decl); + changed = true; + } + else if (!inplace) + { + tree fndecl = builtin_decl_implicit (BUILT_IN_UNREACHABLE); + gimple new_stmt = gimple_build_call (fndecl, 0); + gimple_set_location (new_stmt, gimple_location (stmt)); + gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT); + return true; + } } } } --- gcc/testsuite/g++.dg/opt/pr59622.C.jj 2013-12-30 11:44:04.934893747 +0100 +++ gcc/testsuite/g++.dg/opt/pr59622.C 2013-12-30 11:43:38.000000000 +0100 @@ -0,0 +1,19 @@ +// PR tree-optimization/59622 +// { dg-do compile } +// { dg-options "-O2" } + +namespace +{ + struct A + { + virtual int foo (); + int bar () { return foo (); } + }; +} + +int +baz () +{ + A a; + return a.bar (); +}