From patchwork Tue Dec 11 12:55:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 205207 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 461062C0082 for ; Tue, 11 Dec 2012 23:56:02 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1355835363; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=kFFgsEOyAYyYrKLwiwj0 YS9nQHc=; b=p8oGLn/ACCAUf7j+BRG2lMkp1cGXx06FC6AROhMriVDGVGQtRzCj Suu9QK5Gnjcj94TGs7qm0ar/yl3hnm6G8ovCTxCs/xYB0snSQ7d4GMtfrhAig5RW cO9vVn1j6isV1TqUrRhPaMQNXKXMNC7GUIO7dfILxlb7va2Cf4J6tTc= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=pjNXmeHgbd5krA6rHHWfOlCU+UM9yFVYNa9U7gtbPGSUqVe4BoVY91KLHNNDNp kGDe12t0GCsWKbVfIVE1hBz/7Fej6I0t6sllXg295gy4olCJH+500jmDFkxQGjvT KJpt3+8ZbbVL+si6nReEbZj/5zOclXCLWZMZCDFqC+Ub8=; Received: (qmail 17255 invoked by alias); 11 Dec 2012 12:55:58 -0000 Received: (qmail 17245 invoked by uid 22791); 11 Dec 2012 12:55:57 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_CP 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; Tue, 11 Dec 2012 12:55:42 +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 qBBCtcW6007113 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 Dec 2012 07:55:38 -0500 Received: from zalov.redhat.com (vpn1-5-246.ams2.redhat.com [10.36.5.246]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qBBCtbAJ029877 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 11 Dec 2012 07:55:38 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id qBBCta99027122; Tue, 11 Dec 2012 13:55:36 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id qBBCtZb5027121; Tue, 11 Dec 2012 13:55:35 +0100 Date: Tue, 11 Dec 2012 13:55:35 +0100 From: Jakub Jelinek To: Ian Lance Taylor Cc: Greta Yorsh , gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up undefined signed overflows in FIXED_SSNEG (PR libgcc/55451) Message-ID: <20121211125535.GO2315@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 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! This routine, besides aspiring to win obfuscated C contest (not trying to address that) contains two undefined signed overflows, which presumably show up in arm testing. One overflow is on z = x - y; line, where the x looks just like obfuscation (it is always 0), for input equal to INT_MIN bits (from what I understand, the routine wants to return normal negation of all values but INT_MIN, which is instead replaced with INT_MAX). Fixed by doing the subtraction (== negation) in UINT_C_TYPE instead. Another issue is that ((INT_C_TYPE) 1) << I_F_BITS, if it is equal to INT_MIN, overflows on z-- (x >= 0 is always true, another obfuscation). Untested, Greta, can you please test this on arm? Ok for trunk? 2012-12-11 Jakub Jelinek PR libgcc/55451 * fixed-bit.c (FIXED_SSNEG): Avoid undefined signed overflows. Jakub --- gcc/fixed-bit.c.jj 2011-11-04 07:49:37.000000000 +0100 +++ gcc/fixed-bit.c 2012-12-11 13:16:53.701767571 +0100 @@ -1,5 +1,5 @@ /* This is a software fixed-point library. - Copyright (C) 2007, 2009, 2011 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2011, 2012 Free Software Foundation, Inc. This file is part of GCC. @@ -569,16 +569,11 @@ FIXED_SSNEG (FIXED_C_TYPE a) INT_C_TYPE x, y, z; memcpy (&y, &a, FIXED_SIZE); x = 0; - z = x - y; + z = x - (UINT_C_TYPE) y; if (((x ^ y) >> I_F_BITS) & 1) { if (((z ^ x) >> I_F_BITS) & 1) - { - z = 1; - z = z << I_F_BITS; - if (x >= 0) - z--; - } + z = (((UINT_C_TYPE) 1) << I_F_BITS) - 1; } #if HAVE_PADDING_BITS z = z << PADDING_BITS;