From patchwork Tue May 7 07:55:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 242067 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 106DE2C0174 for ; Tue, 7 May 2013 18:03:35 +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:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=OoAVAt3NT/OJxw90 YqYPJB0i3Sq8+2yoHpjxK2wrLyUvCBw27NE3cAn98+2oYWlQUNYe3YdPanR8iWDx FFeO17MY+cgRfY261uokHFg+UtkP3pEazrl6F6NTFAHxXfWCo0Je2whtin0IS0gi CrZqaWbKSuP65nPFqsxXI3XmpXA= 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:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=IOAWIY7qeh5KAadSL2YUhl 9fQ3w=; b=fc8okbvooTodsqwbHSGklgC9O0Y+EYG8MIdtTSbu1Z2g0/N7tJ8r9g 8COd0X2txTR8ett0hW93wt55SbjhHj1U93powOPS5wIVqLdNvx7PjZdXK0JCrN3o LH5fn2nbeLQwbY2ZPqXjac6DRfHNHNGTwpqcbDxsef20ky+gY/yFw= Received: (qmail 18820 invoked by alias); 7 May 2013 08:03:28 -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 18808 invoked by uid 89); 7 May 2013 08:03:28 -0000 X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.1 Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 07 May 2013 08:03:26 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id A8D5B2642D5E for ; Tue, 7 May 2013 10:02:35 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id O52H92nS-1pI for ; Tue, 7 May 2013 10:02:35 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 831CB2642CBA for ; Tue, 7 May 2013 10:02:35 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: Fix PR ada/56474 Date: Tue, 07 May 2013 09:55:25 +0200 Message-ID: <3701408.PcyJoRTMoB@polaris> User-Agent: KMail/4.7.2 (Linux/3.1.10-1.19-desktop; KDE/4.7.2; x86_64; ; ) MIME-Version: 1.0 X-Virus-Found: No This is a regression present on the mainline and 4.8 branch and introduced by the latest series of sizetype changes. Associated adjustments were made in the various front-ends for it, most notably Ada which was the most affected, but this issue slipped through the cracks in the form of a bogus overflow detection for 0-based arrays with variable upper bound included in a record with discriminant. As suggested by Richard, we can use int_const_binop in lieu of size_binop when we don't want overflow detection for sizetype in gigi. Bootstrapped/regtested on x86_64-suse-linux, applied on mainline and branch. 2013-05-07 Eric Botcazou PR ada/56474 * gcc-interface/decl.c (gnat_to_gnu_entity) : Use int_const_binop to shift bounds by 1 when they are integer constants. 2013-05-07 Eric Botcazou * gnat.dg/specs/array3.ads: New test. Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 198517) +++ gcc-interface/decl.c (working copy) @@ -2447,15 +2447,17 @@ gnat_to_gnu_entity (Entity_Id gnat_entit gnu_orig_max, gnu_orig_min), gnu_min, - size_binop (PLUS_EXPR, gnu_max, - size_one_node)); + int_const_binop (PLUS_EXPR, gnu_max, + size_one_node)); } /* Finally we use (hb >= lb) ? hb : lb - 1 for the upper bound in all the other cases. Note that, here as well as above, the condition used in the comparison must be equivalent to the condition (length != 0). This is relied upon in order - to optimize array comparisons in compare_arrays. */ + to optimize array comparisons in compare_arrays. Moreover + we use int_const_binop for the shift by 1 if the bound is + constant to avoid any unwanted overflow. */ else gnu_high = build_cond_expr (sizetype, @@ -2464,8 +2466,11 @@ gnat_to_gnu_entity (Entity_Id gnat_entit gnu_orig_max, gnu_orig_min), gnu_max, - size_binop (MINUS_EXPR, gnu_min, - size_one_node)); + TREE_CODE (gnu_min) == INTEGER_CST + ? int_const_binop (MINUS_EXPR, gnu_min, + size_one_node) + : size_binop (MINUS_EXPR, gnu_min, + size_one_node)); /* Reuse the index type for the range type. Then make an index type with the size range in sizetype. */