From patchwork Mon Apr 4 03:28:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 605727 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 3qdcsW3JXwz9sC4 for ; Mon, 4 Apr 2016 13:29:02 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=BM2vb1ID; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:content-transfer-encoding; q=dns; s= default; b=lqf42/DI2l0eYiAZPNkTLosSd3QAWYTMl+5AcABflxiiQMynQZg9M +JfRIsK3GZuHCOxQStlRAK6+PSSHqJ+DzqxxN+jeV0sTPQWAb43VWpDNA0f0MZcz 6ZS871yMf+jepSWrHiXT0+NnR5XT1nLKMMKUsxNkqCte5M9y3TlzIU= 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 :subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:content-transfer-encoding; s=default; bh=s3rbDkoWLXW4xcg2gZnkGiIxRcA=; b=BM2vb1IDLsf3YPf3TfZqO5J3fFua w1u/ike6AwEG/nxbCGCILlpZaMuNjXOriAENF5Tm/AuMy1fkPYvG6JkF/rXzlpZc oi6bW4GT1SD8nTpwf3U+G2aIPZfM0RTvM3trrwaYdpleZ8KSZNrZnaN4HIUeCYk8 2In7UiMH8muZRpE= Received: (qmail 23619 invoked by alias); 4 Apr 2016 03:28:53 -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 23601 invoked by uid 89); 4 Apr 2016 03:28:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.3 required=5.0 tests=AWL, BAYES_50, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=formerly, iced, TREE_REAL_CST, U*wschmidt X-HELO: e38.co.us.ibm.com Received: from e38.co.us.ibm.com (HELO e38.co.us.ibm.com) (32.97.110.159) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Mon, 04 Apr 2016 03:28:51 +0000 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 3 Apr 2016 21:28:48 -0600 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 3 Apr 2016 21:28:45 -0600 X-IBM-Helo: d03dlp03.boulder.ibm.com X-IBM-MailFrom: wschmidt@linux.vnet.ibm.com X-IBM-RcptTo: gcc-patches@gcc.gnu.org Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 9B17319D8040 for ; Sun, 3 Apr 2016 21:16:37 -0600 (MDT) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u343SiN145023358 for ; Sun, 3 Apr 2016 20:28:45 -0700 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u343SiIp018135 for ; Sun, 3 Apr 2016 21:28:44 -0600 Received: from [9.77.154.91] (sig-9-77-154-91.ibm.com [9.77.154.91]) by d03av04.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u343ShJk018095; Sun, 3 Apr 2016 21:28:44 -0600 Subject: Re: [PATCH] Fix PR70457 (ICE on incompatible call to built-in pow) From: Bill Schmidt To: gcc-patches@gcc.gnu.org Cc: jakub@redhat.com In-Reply-To: <1459727027.6430.52.camel@oc8801110288.ibm.com> References: <1459727027.6430.52.camel@oc8801110288.ibm.com> Date: Sun, 03 Apr 2016 22:28:43 -0500 Message-ID: <1459740523.6430.56.camel@oc8801110288.ibm.com> Mime-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16040403-0029-0000-0000-000019B61A71 X-IsSubscribed: yes On Sun, 2016-04-03 at 18:43 -0500, Bill Schmidt wrote: > Hi, > > PR70457 shows that we ICE if a call to pow() has only one argument, or > more generally doesn't match its expected signature. This can happen > both during the widen-mult phase and the tree-inline phase. As > suggested by Jakub, this patch uses gimple_call_combined_fn to test for > this, similarly to what is done elsewhere in tree-ssa-math-opts.c. > > Bootstrapped and tested on powerpc64le-unknown-linux-gnu, with no > regressions. Is this ok for trunk, as well as for backport to 5 and > 4.9? For GCC 5 and GCC 4.9, a slightly different patch is required, since gimple_call_combined_fn doesn't exist in previous releases. Also, the sin, cos, etc., functions are also vulnerable: [gcc] 2016-04-03 Bill Schmidt Jakub Jelinek * tree-inline.c (estimate_num_insn): Use gimple_call_builtin_p to ensure a call statement is compatible with a built-in's prototype. * tree-ssa-math-opts.c (execute_cse_sincos): Likewise. (pass_optimize_windening_mul::execute): Likewise. [gcc/testsuite] 2016-04-03 Bill Schmidt Jakub Jelinek * gcc.dg/torture/pr70457.c: New. Index: gcc/testsuite/gcc.dg/torture/pr70457.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr70457.c (revision 0) +++ gcc/testsuite/gcc.dg/torture/pr70457.c (working copy) @@ -0,0 +1,32 @@ +/* { dg-do compile } */ + +/* This formerly ICEd when trying to expand pow as a built-in with + the wrong number of arguments. */ + +extern double pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__)); +extern double __pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__)); + +typedef int int64_t __attribute__ ((__mode__ (__DI__))); + +typedef struct { + int64_t data; + int tag; +} Object; + +extern Object Make_Flonum (double); +extern Object P_Pow (Object, Object); + +Object General_Function (Object x, Object y, double (*fun)()) { + double d, ret; + + d = 1.0; + + if (y.tag >> 1) + ret = (*fun) (d); + else + ret = (*fun) (d, 0.0); + + return Make_Flonum (ret); +} + +Object P_Pow (Object x, Object y) { return General_Function (x, y, pow); } Index: gcc/tree-inline.c =================================================================== --- gcc/tree-inline.c (revision 234702) +++ gcc/tree-inline.c (working copy) @@ -3860,6 +3860,8 @@ estimate_num_insns (gimple stmt, eni_weights *weig case BUILT_IN_POW: case BUILT_IN_POWF: case BUILT_IN_POWL: + if (!gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) + break; if (TREE_CODE (gimple_call_arg (stmt, 1)) == REAL_CST && REAL_VALUES_EQUAL (TREE_REAL_CST (gimple_call_arg (stmt, 1)), dconst2)) Index: gcc/tree-ssa-math-opts.c =================================================================== --- gcc/tree-ssa-math-opts.c (revision 234702) +++ gcc/tree-ssa-math-opts.c (working copy) @@ -1437,7 +1437,7 @@ execute_cse_sincos (void) if (is_gimple_call (stmt) && gimple_call_lhs (stmt) && (fndecl = gimple_call_fndecl (stmt)) - && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL) + && gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) { tree arg, arg0, arg1, result; HOST_WIDE_INT n; @@ -2867,6 +2867,8 @@ execute_optimize_widening_mul (void) case BUILT_IN_POWF: case BUILT_IN_POW: case BUILT_IN_POWL: + if (!gimple_call_builtin_p (stmt)) + break; if (TREE_CODE (gimple_call_arg (stmt, 1)) == REAL_CST && REAL_VALUES_EQUAL (TREE_REAL_CST (gimple_call_arg (stmt, 1)),