From patchwork Mon Oct 27 10:53:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 403523 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 8B457140082 for ; Mon, 27 Oct 2014 21:59:54 +1100 (AEDT) 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=ByFn2TgBNr8tqXgv GVThk/juv5ULBjhOjje0OacLtoWsXWq+p9/zQ9RmAzrQhYPntX5FVAQYeCao46Sk 3sGIbUA6Rvn+WNl+EB1NgrvVsubwwkRhxVWtvU/yd/i2ogoNoNj8AtdJaP8YEcsn qBAsxT+MfyJh423Dmc5QxONcud8= 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=86LfumIm/649WvMgX2Spr4 K1YVQ=; b=PHxp/0hZRUFh1GgclQPghfL1UGirj55xAY333w+gOElbatHhuG10DP LVFujk643PB8YaO6jcSm4XqvkNxT9FWyW6A/9En7kzgw45pYUNyzUyheQdzqPZMF s3mwU6p7h32DFiEuZ+c9Yv0rZlUfVc49ycYXpx63yTFztuIxsqZPI= Received: (qmail 16048 invoked by alias); 27 Oct 2014 10:59:47 -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 16028 invoked by uid 89); 27 Oct 2014 10:59:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 27 Oct 2014 10:59:45 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 139D22B0B2AC for ; Mon, 27 Oct 2014 11:59:39 +0100 (CET) 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 Qe6H55mBuwzN for ; Mon, 27 Oct 2014 11:59:39 +0100 (CET) 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 CA0E62B0A4BE for ; Mon, 27 Oct 2014 11:59:38 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix overflow with entry queue Date: Mon, 27 Oct 2014 11:53:39 +0100 Message-ID: <8576824.eZ3OSOCuUO@polaris> User-Agent: KMail/4.7.2 (Linux/3.1.10-1.29-desktop; KDE/4.7.2; x86_64; ; ) MIME-Version: 1.0 This is a regression present on the mainline and 4.9 branch: declaring an array of entries of a protected object results in an size overflow for the array. There is a known overflow issue with entry families for protected objects, which is papered over in the FE (see the top of Exp_Ch9), but the trick has been silently disabled. Tested on x86_64-suse-linux, applied on mainline and 4.9 branch. 2014-10-27 Eric Botcazou * gcc-interface/decl.c (gnat_to_gnu_entity) : Remove superfluous computation for the max size. : Likewise. Make sure that the max size calculation does not overflow at compile time. 2014-10-27 Eric Botcazou * gnat.dg/entry_queues2.adb: New test. Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 216612) +++ gcc-interface/decl.c (working copy) @@ -2127,11 +2127,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entit tree gnu_max = convert (sizetype, TYPE_MAX_VALUE (gnu_index_type)); tree gnu_this_max - = size_binop (MAX_EXPR, - size_binop (PLUS_EXPR, size_one_node, - size_binop (MINUS_EXPR, - gnu_max, gnu_min)), - size_zero_node); + = size_binop (PLUS_EXPR, size_one_node, + size_binop (MINUS_EXPR, gnu_max, gnu_min)); if (TREE_CODE (gnu_this_max) == INTEGER_CST && TREE_OVERFLOW (gnu_this_max)) @@ -2464,20 +2461,26 @@ gnat_to_gnu_entity (Entity_Id gnat_entit gnu_max_size = NULL_TREE; else { - tree gnu_this_max - = size_binop (MAX_EXPR, - size_binop (PLUS_EXPR, size_one_node, - size_binop (MINUS_EXPR, - gnu_base_max, - gnu_base_min)), - size_zero_node); + tree gnu_this_max; - if (TREE_CODE (gnu_this_max) == INTEGER_CST - && TREE_OVERFLOW (gnu_this_max)) - gnu_max_size = NULL_TREE; + /* Use int_const_binop if the bounds are constant to + avoid any unwanted overflow. */ + if (TREE_CODE (gnu_base_min) == INTEGER_CST + && TREE_CODE (gnu_base_max) == INTEGER_CST) + gnu_this_max + = int_const_binop (PLUS_EXPR, size_one_node, + int_const_binop (MINUS_EXPR, + gnu_base_max, + gnu_base_min)); else - gnu_max_size - = size_binop (MULT_EXPR, gnu_max_size, gnu_this_max); + gnu_this_max + = size_binop (PLUS_EXPR, size_one_node, + size_binop (MINUS_EXPR, + gnu_base_max, + gnu_base_min)); + + gnu_max_size + = size_binop (MULT_EXPR, gnu_max_size, gnu_this_max); } }