From patchwork Tue May 28 08:26:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1106143 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-501749-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com 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 45Cn4t2DPjz9s5c for ; Tue, 28 May 2019 18:26:47 +1000 (AEST) 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=kG6mrUd0GFZV85eC wTAOoJrckMPuJo2Ok8kftieIqFrz3SrEbJYy2vPsVTeSVOyC7xbfkwUev4qdAraG OKi3j7b7mPAh/9Zy55eR8LK7P6Ipf4SAw0Hj2VP40Qy+AfH9u9GVDvRlaMcb++si KHmK0et2lqQnVxqBxGkG9RnLplE= 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=/4gd/vdwQf7UJ5pMifG5yw ZddZ4=; b=Vzs+L5ggFPsqb5wFrVwhgguku9J5qxIPv9ApPIcL20sAqAkwaPVR5X oPj0VaK3eXyOmn5Jy2cOicY2b9CdKPceCUgrbwK+p5lpJvnm4NIRWvTyo4JE7/5/ UuAD0R20npfW9c6Elr6hBeybPEK08IMqMDom6+HWizdOQF7sO1rvY= Received: (qmail 106809 invoked by alias); 28 May 2019 08:26:39 -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 106800 invoked by uid 89); 28 May 2019 08:26:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-6.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=tre 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; Tue, 28 May 2019 08:26:38 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id EAF1181386 for ; Tue, 28 May 2019 10:26: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 1o4SaQiloQdq for ; Tue, 28 May 2019 10:26:35 +0200 (CEST) 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 C703A81385 for ; Tue, 28 May 2019 10:26:35 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix minor issue with unconstrained packed arrays Date: Tue, 28 May 2019 10:26:34 +0200 Message-ID: <4890533.CJ0bhNnPZX@polaris> MIME-Version: 1.0 The compiler allocates the non-packed size for a function returning a parameter of an unconstrained packed array type. Tested on x86_64-suse-linux, applied on the mainline and 9 branch. 2019-05-28 Eric Botcazou * gcc-interface/trans.c (lvalue_required_for_attribute_p): Return 0 for 'Size too. (Identifier_to_gnu): Use the actual subtype for a reference to a packed array in a return statement. (Attribute_to_gnu) : Do not strip VIEW_CONVERT_EXPRs from the prefix in every case. Index: gcc-interface/trans.c =================================================================== --- gcc-interface/trans.c (revision 271690) +++ gcc-interface/trans.c (revision 271691) @@ -778,6 +778,7 @@ lvalue_required_for_attribute_p (Node_Id case Attr_Range_Length: case Attr_Length: case Attr_Object_Size: + case Attr_Size: case Attr_Value_Size: case Attr_Component_Size: case Attr_Descriptor_Size: @@ -797,7 +798,6 @@ lvalue_required_for_attribute_p (Node_Id case Attr_Unrestricted_Access: case Attr_Code_Address: case Attr_Pool_Address: - case Attr_Size: case Attr_Alignment: case Attr_Bit_Position: case Attr_Position: @@ -1112,12 +1112,15 @@ Identifier_to_gnu (Node_Id gnat_node, tr { /* We use the Actual_Subtype only if it has already been elaborated, as we may be invoked precisely during its elaboration, otherwise - the Etype. Avoid using it for packed arrays to simplify things. */ + the Etype. Avoid using it for packed arrays to simplify things, + except in a return statement because we need the actual size and + the front-end does not make it explicit in this case. */ if ((Ekind (gnat_entity) == E_Constant || Ekind (gnat_entity) == E_Variable || Is_Formal (gnat_entity)) && !(Is_Array_Type (Etype (gnat_entity)) - && Present (Packed_Array_Impl_Type (Etype (gnat_entity)))) + && Present (Packed_Array_Impl_Type (Etype (gnat_entity))) + && Nkind (Parent (gnat_node)) != N_Simple_Return_Statement) && Present (Actual_Subtype (gnat_entity)) && present_gnu_tree (Actual_Subtype (gnat_entity))) gnat_result_type = Actual_Subtype (gnat_entity); @@ -2314,21 +2317,24 @@ Attribute_to_gnu (Node_Id gnat_node, tre case Attr_Object_Size: case Attr_Value_Size: case Attr_Max_Size_In_Storage_Elements: - gnu_expr = gnu_prefix; - - /* Remove NOPs and conversions between original and packable version - from GNU_EXPR, and conversions from GNU_PREFIX. We use GNU_EXPR - to see if a COMPONENT_REF was involved. */ - while (TREE_CODE (gnu_expr) == NOP_EXPR - || (TREE_CODE (gnu_expr) == VIEW_CONVERT_EXPR - && TREE_CODE (TREE_TYPE (gnu_expr)) == RECORD_TYPE - && TREE_CODE (TREE_TYPE (TREE_OPERAND (gnu_expr, 0))) + /* Strip NOPs, conversions between original and packable versions, and + unpadding from GNU_PREFIX. Note that we cannot simply strip every + VIEW_CONVERT_EXPR because some of them may give the actual size, e.g. + for nominally unconstrained packed array. We use GNU_EXPR to see + if a COMPONENT_REF was involved. */ + while (CONVERT_EXPR_P (gnu_prefix) + || TREE_CODE (gnu_prefix) == NON_LVALUE_EXPR + || (TREE_CODE (gnu_prefix) == VIEW_CONVERT_EXPR + && TREE_CODE (TREE_TYPE (gnu_prefix)) == RECORD_TYPE + && TREE_CODE (TREE_TYPE (TREE_OPERAND (gnu_prefix, 0))) == RECORD_TYPE - && TYPE_NAME (TREE_TYPE (gnu_expr)) - == TYPE_NAME (TREE_TYPE (TREE_OPERAND (gnu_expr, 0))))) - gnu_expr = TREE_OPERAND (gnu_expr, 0); - - gnu_prefix = remove_conversions (gnu_prefix, true); + && TYPE_NAME (TREE_TYPE (gnu_prefix)) + == TYPE_NAME (TREE_TYPE (TREE_OPERAND (gnu_prefix, 0))))) + gnu_prefix = TREE_OPERAND (gnu_prefix, 0); + gnu_expr = gnu_prefix; + if (TREE_CODE (gnu_prefix) == COMPONENT_REF + && TYPE_IS_PADDING_P (TREE_TYPE (TREE_OPERAND (gnu_prefix, 0)))) + gnu_prefix = TREE_OPERAND (gnu_prefix, 0); prefix_unused = true; gnu_type = TREE_TYPE (gnu_prefix); @@ -2391,7 +2397,7 @@ Attribute_to_gnu (Node_Id gnat_node, tre /* Deal with a self-referential size by qualifying the size with the object or returning the maximum size for a type. */ if (TREE_CODE (gnu_prefix) != TYPE_DECL) - gnu_result = SUBSTITUTE_PLACEHOLDER_IN_EXPR (gnu_result, gnu_expr); + gnu_result = SUBSTITUTE_PLACEHOLDER_IN_EXPR (gnu_result, gnu_prefix); else if (CONTAINS_PLACEHOLDER_P (gnu_result)) gnu_result = max_size (gnu_result, true);