From patchwork Wed Dec 5 10:30:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 203821 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 1E2FD2C00AC for ; Wed, 5 Dec 2012 21:30:34 +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=1355308235; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID: 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=Zra+tgB/EZhSpny0JpQy axL0A4s=; b=ZPRM+rNelACCszoBPNaDu74p0NEqgBfv5xzUmjbp9ghVAJIbxBSk UKXdgrojC/yp5Ap0XgmYa4OIDAg2YrX6bk/4HXmEEYVEWjyONn/U8TANvY8LJvwe BNiooSOt4VLNsh1a8awjeEiuVSzAfGHN+UtfS4wCzC1DpwgiNUYYfdE= 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:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=HvpkAXZ+BBCuceZkpCDbJ0H9MbOBUFpl95V3CApY6AUkfJxkTFJuyZiZxhxq+6 jxaf6AQ1VLU7+G3ODzbwY7MQaSvANhCgR9PHYCRsnmBcvila4UKOBoCPUFCRATuP KB9RUxZvrSkGEpvJtOY1pEXhROCQSs/aAQvImlWCRg2mM=; Received: (qmail 14912 invoked by alias); 5 Dec 2012 10:30:26 -0000 Received: (qmail 14867 invoked by uid 22791); 5 Dec 2012 10:30:24 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_NO X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 05 Dec 2012 10:30:14 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id D0AE82E2C7; Wed, 5 Dec 2012 05:30:13 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id oteFKHca+j1A; Wed, 5 Dec 2012 05:30:13 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id A849E2E0E6; Wed, 5 Dec 2012 05:30:13 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id A6FA9919E3; Wed, 5 Dec 2012 05:30:13 -0500 (EST) Date: Wed, 5 Dec 2012 05:30:13 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Robert Dewar Subject: [Ada] Remove junk overflow check on MOD/REM/unary "+" Message-ID: <20121205103013.GA4531@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) 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 This patch removes the setting of the overflow flag for MOD, REM, and unary "+" operators, since overflow is not possible. This does not have a functional effect for the compiler since overflow is not possible anyway, but it did affect some other tools (notably gnatprove, which had to do extra work dealing with these junk flags). The following program: 1. procedure BadRemOverflow (X, Y : Integer) is 2. Z1 : Integer := X rem Y; 3. Z2 : Integer := X mod Y; 4. Z3 : Integer := +X; 5. begin 6. null; 7. end BadRemOverflow; generates the following -gnatG output: procedure badremoverflow (x : integer; y : integer) is [constraint_error when y = 0 "divide by zero"] z1 : integer := (if y = -1 then 0 else x rem y); [constraint_error when y = 0 "divide by zero"] z2 : integer := (if y = -1 then 0 else x mod y); z3 : integer := +x; begin null; return; end badremoverflow; Prior to this patch, the rem, mod and + operators were surrounded with {} brackets indicating the presence of an overflow check. Tested on x86_64-pc-linux-gnu, committed on trunk 2012-12-05 Robert Dewar * checks.ads, checks.adb (Activate_Overflow_Check): No effect for MOD/REM/unary + * exp_ch4.adb (Expand_N_Op_Mod): Remove call to set Do_Overflow_Check. Index: checks.adb =================================================================== --- checks.adb (revision 194193) +++ checks.adb (working copy) @@ -387,8 +387,10 @@ procedure Activate_Overflow_Check (N : Node_Id) is begin - Set_Do_Overflow_Check (N, True); - Possible_Local_Raise (N, Standard_Constraint_Error); + if not Nkind_In (N, N_Op_Rem, N_Op_Mod, N_Op_Plus) then + Set_Do_Overflow_Check (N, True); + Possible_Local_Raise (N, Standard_Constraint_Error); + end if; end Activate_Overflow_Check; -------------------------- Index: checks.ads =================================================================== --- checks.ads (revision 194193) +++ checks.ads (working copy) @@ -93,6 +93,8 @@ -- Sets Do_Overflow_Check flag in node N, and handles possible local raise. -- Always call this routine rather than calling Set_Do_Overflow_Check to -- set an explicit value of True, to ensure handling the local raise case. + -- Note that this call has no effect for MOD, REM, and unary "+" for which + -- overflow is never possible in any case. procedure Activate_Range_Check (N : Node_Id); pragma Inline (Activate_Range_Check); Index: exp_ch4.adb =================================================================== --- exp_ch4.adb (revision 194193) +++ exp_ch4.adb (working copy) @@ -7910,7 +7910,6 @@ procedure Expand_N_Op_Mod (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Typ : constant Entity_Id := Etype (N); - DOC : constant Boolean := Do_Overflow_Check (N); DDC : constant Boolean := Do_Division_Check (N); Left : Node_Id; @@ -7975,7 +7974,6 @@ Set_Entity (N, Standard_Entity (S_Op_Rem)); Set_Etype (N, Typ); - Set_Do_Overflow_Check (N, DOC); Set_Do_Division_Check (N, DDC); Expand_N_Op_Rem (N); Set_Analyzed (N);