From patchwork Fri Dec 14 11:08:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1013475 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-492470-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="OJLa54Na"; dkim-atps=neutral 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 43GSTy22dGz9s4s for ; Fri, 14 Dec 2018 22:08: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=nczOXZunSVDzV6Cm JJvMMykPMz3k4Q94bvVsttdNwHd8bdX9U6JUF1OxW4cqxcBkY8pSsatWNOSo0TBl ZsGzzVWKKD+dXy9VIKt0XJG9PFF8ctRqGf5U8h0ZO/FGH9Ewns3vgEjYdl25fdKH Zau4h1kk1P/VlnHUaCcUpUOzHIg= 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=/hus4nEqCscmmj5ybTLHEU acGBU=; b=OJLa54NaGDYIOsqN3bYsGq/pdzwhDRNjncXF6bUeXijHyECJgjAqPd s6XOMwpKzlhzEiwm9QlR0TVnbPLW++kch+hJp8qEiNeq4swKhtp8zpGObyTGXQbN J34AvK6+caxgnSfy4udW0dF3CzZGWMfSLzI0xJ+dE5EvcJIikoePc= Received: (qmail 48999 invoked by alias); 14 Dec 2018 11:08:46 -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 48989 invoked by uid 89); 14 Dec 2018 11:08:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS, TVD_PH_BODY_ACCOUNTS_PRE autolearn=ham version=3.3.2 spammy= 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 ESMTP; Fri, 14 Dec 2018 11:08:44 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 3744C81395 for ; Fri, 14 Dec 2018 12:08:42 +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 LWweecH0bYYp for ; Fri, 14 Dec 2018 12:08:42 +0100 (CET) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 060D281393 for ; Fri, 14 Dec 2018 12:08:42 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix Max_Size_In_Storage_Elements for unconstrained array types Date: Fri, 14 Dec 2018 12:08:41 +0100 Message-ID: <2478632.0aPzeAe4HX@polaris> MIME-Version: 1.0 It appears that GNAT was not fully compliant with the intent of the RM here because it wouldn't include the size of the bounds added in front of the data in an allocation in the value of Max_Size_In_Storage_Elements. Tested on x86_64-suse-linux, applied on the mainline. 2018-12-14 Eric Botcazou * gcc-interface/decl.c (rm_size): Take into account the padding in the case of a record type containing a template. * gcc-interface/trans.c (Attribute_to_gnu) : Likewise. Do not subtract the padded size for Max_Size_In_Storage_Elements. : Tweak comment. 2018-12-14 Eric Botcazou * gnat.dg/max_size.adb: New test. * gnat.dg/max_size_pkg.ads: Likewise. Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 267130) +++ gcc-interface/decl.c (working copy) @@ -10049,13 +10049,14 @@ rm_size (tree gnu_type) if (INTEGRAL_TYPE_P (gnu_type) && TYPE_RM_SIZE (gnu_type)) return TYPE_RM_SIZE (gnu_type); - /* Return the RM size of the actual data plus the size of the template. */ + /* If the type contains a template, return the padded size of the template + plus the RM size of the actual data. */ if (TREE_CODE (gnu_type) == RECORD_TYPE && TYPE_CONTAINS_TEMPLATE_P (gnu_type)) return size_binop (PLUS_EXPR, - rm_size (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (gnu_type)))), - DECL_SIZE (TYPE_FIELDS (gnu_type))); + bit_position (DECL_CHAIN (TYPE_FIELDS (gnu_type))), + rm_size (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (gnu_type))))); /* For record or union types, we store the size explicitly. */ if (RECORD_OR_UNION_TYPE_P (gnu_type) Index: gcc-interface/trans.c =================================================================== --- gcc-interface/trans.c (revision 267062) +++ gcc-interface/trans.c (working copy) @@ -2308,10 +2308,8 @@ Attribute_to_gnu (Node_Id gnat_node, tre gnu_type = TREE_TYPE (gnu_prefix); /* Replace an unconstrained array type with the type of the underlying - array. We can't do this with a call to maybe_unconstrained_array - since we may have a TYPE_DECL. For 'Max_Size_In_Storage_Elements, - use the record type that will be used to allocate the object and its - template. */ + array, except for 'Max_Size_In_Storage_Elements because we need to + return the (maximum) size requested for an allocator. */ if (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE) { gnu_type = TYPE_OBJECT_RECORD_TYPE (gnu_type); @@ -2375,11 +2373,15 @@ Attribute_to_gnu (Node_Id gnat_node, tre gnu_result = substitute_placeholder_in_expr (gnu_result, gnu_expr); } - /* If the type contains a template, subtract its size. */ + /* If the type contains a template, subtract the padded size of the + template, except for 'Max_Size_In_Storage_Elements because we need + to return the (maximum) size requested for an allocator. */ if (TREE_CODE (gnu_type) == RECORD_TYPE - && TYPE_CONTAINS_TEMPLATE_P (gnu_type)) - gnu_result = size_binop (MINUS_EXPR, gnu_result, - DECL_SIZE (TYPE_FIELDS (gnu_type))); + && TYPE_CONTAINS_TEMPLATE_P (gnu_type) + && attribute != Attr_Max_Size_In_Storage_Elements) + gnu_result + = size_binop (MINUS_EXPR, gnu_result, + bit_position (DECL_CHAIN (TYPE_FIELDS (gnu_type)))); /* For 'Max_Size_In_Storage_Elements, adjust the unit. */ if (attribute == Attr_Max_Size_In_Storage_Elements) @@ -2856,8 +2858,7 @@ Attribute_to_gnu (Node_Id gnat_node, tre gnu_type = TREE_TYPE (gnu_prefix); gcc_assert (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE); - /* What we want is the offset of the ARRAY field in the record - that the thin pointer designates. */ + /* Return the padded size of the template in the object record type. */ gnu_type = TYPE_OBJECT_RECORD_TYPE (gnu_type); gnu_result = bit_position (DECL_CHAIN (TYPE_FIELDS (gnu_type))); gnu_result_type = get_unpadded_type (Etype (gnat_node));