From patchwork Fri May 2 19:20:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 345238 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 524E614013E for ; Sat, 3 May 2014 05:20:29 +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:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=kLcnBUNZca5Y5TcWpuxbeWXDXNkLFnQJk34hKDhdQYt1Q6XlCe U7Fj5iC+lslxiKgmxNC4qWofQ+gXbw/tN1ZP3cPhF9MRCUNxVpOt7kqMB7Ce0w9O FA44r2gAg0uHPGTEmxz/Fg8nQNLWUTdtjOGNDIPfVMzidRO4Fz4rRwD0s= 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:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=kzwBfpWROfRfizPbSxUyVY8z9cw=; b=GXaXirVpKBUTQWgQfbVJ e16B5RPJS5hLvPGpKFDWpuGfXQMDIpDhLEOTe0mopSHKAHflTq2Tv+qbVU/yaKhx 6VHEQfRKqzubdPJj7JI0oV+38bWLU/EfqpMXyQ6VawUoLiKQho6uRq0JA3I88DKB nQfetO6JK5rGQ/uh+ljztV4= Received: (qmail 16849 invoked by alias); 2 May 2014 19:20:22 -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 16836 invoked by uid 89); 2 May 2014 19:20:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f48.google.com Received: from mail-wg0-f48.google.com (HELO mail-wg0-f48.google.com) (74.125.82.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 02 May 2014 19:20:20 +0000 Received: by mail-wg0-f48.google.com with SMTP id x13so1431912wgg.31 for ; Fri, 02 May 2014 12:20:17 -0700 (PDT) X-Received: by 10.180.160.166 with SMTP id xl6mr4373590wib.42.1399058417759; Fri, 02 May 2014 12:20:17 -0700 (PDT) Received: from sandifor-thinkpad.stglab.manchester.uk.ibm.com ([2.26.169.52]) by mx.google.com with ESMTPSA id f11sm2611063wiv.1.2014.05.02.12.20.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 May 2014 12:20:17 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, zadeck@naturalbridge.com, mikestump@comcast.net, rdsandiford@googlemail.com Cc: zadeck@naturalbridge.com, mikestump@comcast.net Subject: [wide-int] Add more assertions Date: Fri, 02 May 2014 20:20:16 +0100 Message-ID: <87zjj0ng27.fsf@sandifor-thinkpad.stglab.manchester.uk.ibm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 This patch adds some assertions against sext (.., 0) and zext (..., 0). The former is undefined at the sext_hwi level and the latter is disallowed for consistency with the former. Also, set_bit (rightly IMO) can't handle bit >= precision. For precision <= HOST_BITS_PER_WIDE_INT it would invoke undefined behaviour while for other precisions I think it would crash. A case with precision <= HOST_BITS_PER_WIDE_INT showed up in java (fix posted separately). Tested on x86_64-linux-gnu and powerpc64-linux-gnu. OK to install? Thanks, Richard Index: gcc/wide-int.h =================================================================== --- gcc/wide-int.h 2014-05-02 16:28:09.561842842 +0100 +++ gcc/wide-int.h 2014-05-02 16:44:04.015463718 +0100 @@ -2046,6 +2046,8 @@ wi::sext (const T &x, unsigned int offse unsigned int precision = get_precision (result); WIDE_INT_REF_FOR (T) xi (x, precision); + gcc_checking_assert (offset != 0); + if (offset <= HOST_BITS_PER_WIDE_INT) { val[0] = sext_hwi (xi.ulow (), offset); @@ -2065,6 +2067,8 @@ wi::zext (const T &x, unsigned int offse unsigned int precision = get_precision (result); WIDE_INT_REF_FOR (T) xi (x, precision); + gcc_checking_assert (offset != 0); + /* This is not just an optimization, it is actually required to maintain canonization. */ if (offset >= precision) @@ -2102,6 +2106,9 @@ wi::set_bit (const T &x, unsigned int bi WI_UNARY_RESULT_VAR (result, val, T, x); unsigned int precision = get_precision (result); WIDE_INT_REF_FOR (T) xi (x, precision); + + gcc_checking_assert (bit < precision); + if (precision <= HOST_BITS_PER_WIDE_INT) { val[0] = xi.ulow () | ((unsigned HOST_WIDE_INT) 1 << bit);