From patchwork Sun Apr 14 08:05:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 236412 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 D2D252C00AB for ; Sun, 14 Apr 2013 18:06:03 +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=V1/pfJnquz43DHMi ufE7WZwuWnPPJDRB4XebDeRkRfgMPhuiC0BuC5AvpcHX+G6OpF/mQ+ZK/II0YM0m ucc8/FZFVzirlzjJBSmZU+wZPJhNSOMGd4jWX3sLJN/vEUrsOd4orWOf6uHs8mql JXWto7qvEXDUd3sQKuPFsNb+SDk= 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=6YQpDxeRszv8C6sTnKcsmy NM1/A=; b=oOnCChHEq+FWmDj4m2ITzqNZLEre/85HPC11mb9i5BkUYJz0FqlqJI ahGz9zjAJSQ6CLoNs1fypCwNVv4YPqhyh5Ndr7NSlw36HC2p0tORZQ5EZpIOgZL1 NQQL09u9N+IzfZaYeDhsz68N+jjEgvQ3eJLOb7TKG39QeaAL+i4+w= Received: (qmail 27894 invoked by alias); 14 Apr 2013 08:05:57 -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 27883 invoked by uid 89); 14 Apr 2013 08:05:56 -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 mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sun, 14 Apr 2013 08:05:52 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 78569290016 for ; Sun, 14 Apr 2013 10:05:50 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id z6brxEmz9KAq for ; Sun, 14 Apr 2013 10:05:50 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 48F6929000E for ; Sun, 14 Apr 2013 10:05:50 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Fix PR middle-end/56474 Date: Sun, 14 Apr 2013 10:05:07 +0200 Message-ID: <1630485.0zg5rbKfGZ@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 Hi, 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. The proposed fix is to disable overflow detection in sizetype for one special case (0 - 1) in size_binop_loc. An equivalent kludge was added to layout_type to disable overflow detection for the size expression of [0, -1] arrays. Tested on x86_64-suse-linux, OK for the mainline and 4.8 branch? 2013-04-14 Eric Botcazou PR middle-end/56474 * fold-const.c (size_binop_loc): Disable overflow detection for 0 - 1. 2013-04-14 Eric Botcazou * gnat.dg/specs/array3.ads: New test. Index: fold-const.c =================================================================== --- fold-const.c (revision 197926) +++ fold-const.c (working copy) @@ -1422,9 +1422,13 @@ size_binop_loc (location_t loc, enum tre gcc_assert (int_binop_types_match_p (code, TREE_TYPE (arg0), TREE_TYPE (arg1))); - /* Handle the special case of two integer constants faster. */ + /* Handle general case of two integer constants. For sizetype constant + calculations, we always want to know about overflow, even in the + unsigned case. */ if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST) { + int overflowable = -1; + /* And some specific cases even faster than that. */ if (code == PLUS_EXPR) { @@ -1437,6 +1441,11 @@ size_binop_loc (location_t loc, enum tre { if (integer_zerop (arg1) && !TREE_OVERFLOW (arg1)) return arg0; + + /* ??? We make an exception for 0 - 1 because it's an idiom + used in length calculations for zero-based arrays. */ + if (integer_zerop (arg0) && integer_onep (arg1)) + overflowable = 1; } else if (code == MULT_EXPR) { @@ -1444,10 +1453,7 @@ size_binop_loc (location_t loc, enum tre return arg1; } - /* Handle general case of two integer constants. For sizetype - constant calculations we always want to know about overflow, - even in the unsigned case. */ - return int_const_binop_1 (code, arg0, arg1, -1); + return int_const_binop_1 (code, arg0, arg1, overflowable); } return fold_build2_loc (loc, code, type, arg0, arg1);