From patchwork Sun Feb 27 12:13:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 84686 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]) by ozlabs.org (Postfix) with SMTP id AD164B70F8 for ; Sun, 27 Feb 2011 23:14:03 +1100 (EST) Received: (qmail 30964 invoked by alias); 27 Feb 2011 12:14:02 -0000 Received: (qmail 30954 invoked by uid 22791); 27 Feb 2011 12:14:01 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 27 Feb 2011 12:13:55 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p1RCDr1v013510 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 27 Feb 2011 07:13:54 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p1RCDqp3031009 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 27 Feb 2011 07:13:53 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p1RCDqiM025263 for ; Sun, 27 Feb 2011 13:13:52 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p1RCDqSL025261 for gcc-patches@gcc.gnu.org; Sun, 27 Feb 2011 13:13:52 +0100 Date: Sun, 27 Feb 2011 13:13:52 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Avoid uninitialized padding bits in REAL_CST/CONST_DOUBLE (PR middle-end/47903) Message-ID: <20110227121351.GC30899@tyan-ft48-01.lab.bos.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 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 Hi! In some places CONST_DOUBLE bits are compared as the HWIs, thus it is undesirable to have uninitialized bits among them. At least on LP64 hosts there are 32 bits of padding between uexp and sign fields. Most of the places in gcc that work with REAL_VALUE_TYPE seem to actually either clear the whole REAL_VALUE_TYPE by memset, or start by copying to result one of the arguments. The exception seems to be real_arithmetic for PLUS/MINUS/MULT/RDIV, where the result might be the same as either of the operands, or might be completely different. Either real_arithmetic in those 4 cases could compare result ptr with both operands and if it is not equal to either of them, clear it, or the following patch adjusts the callers where they do it. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-02-27 Jakub Jelinek PR middle-end/47903 * fold-const.c (const_binop): Clear value first before doing real_arithmetic into it. * simplify-rtx.c (simplify_const_binary_operation): Likewise. * builtins.c (fold_builtin_cbrt): Clear dconstroot first before doing real_arithmetic into it. (fold_builtin_modf): Clear frac first before doing real_arithmetic into it. Jakub --- gcc/fold-const.c.jj 2011-02-15 15:25:53.000000000 +0100 +++ gcc/fold-const.c 2011-02-26 16:03:22.000000000 +0100 @@ -1163,6 +1163,8 @@ const_binop (enum tree_code code, tree a else if (REAL_VALUE_ISNAN (d2)) return arg2; + /* Make sure to clear any padding. */ + memset (&value, '\0', sizeof (value)); inexact = real_arithmetic (&value, code, &d1, &d2); real_convert (&result, mode, &value); --- gcc/simplify-rtx.c.jj 2010-12-02 11:51:31.000000000 +0100 +++ gcc/simplify-rtx.c 2011-02-26 16:06:38.000000000 +0100 @@ -3310,6 +3310,8 @@ simplify_const_binary_operation (enum rt /* Inf * 0 = NaN plus exception. */ return 0; + /* Make sure to clear any padding. */ + memset (&value, '\0', sizeof (value)); inexact = real_arithmetic (&value, rtx_to_tree_code (code), &f0, &f1); real_convert (&result, mode, &value); --- gcc/builtins.c.jj 2011-02-02 16:30:55.000000000 +0100 +++ gcc/builtins.c 2011-02-26 16:02:49.000000000 +0100 @@ -7335,6 +7335,8 @@ fold_builtin_cbrt (location_t loc, tree tree tree_root; REAL_VALUE_TYPE dconstroot; + /* Make sure to clear any padding. */ + memset (&dconstroot, '\0', sizeof (dconstroot)); real_arithmetic (&dconstroot, MULT_EXPR, dconst_third_ptr (), dconst_third_ptr ()); dconstroot = real_value_truncate (TYPE_MODE (type), dconstroot); @@ -9576,6 +9578,8 @@ fold_builtin_modf (location_t loc, tree case rvc_normal: /* Return (*arg1 = trunc(arg0), arg0-trunc(arg0)). */ real_trunc (&trunc, VOIDmode, value); + /* Make sure to clear any padding. */ + memset (&frac, '\0', sizeof (frac)); real_arithmetic (&frac, MINUS_EXPR, value, &trunc); /* If the original number was negative and already integral, then the fractional part is -0.0. */