From patchwork Mon May 27 11:07:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1105748 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-501714-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 45CDhm3fL5z9sB8 for ; Mon, 27 May 2019 21:07:34 +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=su30e2xCkIYs8Jzw P9HMTVxgwr/1Bdj2FgAMlBywbfZEQqHBiMWihdxEZ55feJ479yaGDgAfu5WYtKmQ eF5MbwCXnz/tlJMJ583wwjkPkB5yXQVLc6DAcU39dDbH1dTWOchCXlbTk18SUvNF 3vWA2aDOTV3NkY/v0KorjpBqYS0= 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=ZH4pPtR8P2bfOxuqAmbGrr QEkIQ=; b=cpkBHdmqD4QS298yxXBLUPvuxoDW3jG6EwH1PnvX8n8mVW3qE6+ESY KtMdlhoqGM2wu+tHtn8jWP5O9zH3IIVfX/H9FgmUi08gyiJp45PmB+J8F+Oc6avh J//UF2yZNi+xt0RndrGNYHxh/iZyjVIHhWeaCRKbpmtthepqYme+w= Received: (qmail 25443 invoked by alias); 27 May 2019 11:07:27 -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 25435 invoked by uid 89); 27 May 2019 11:07:26 -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=unmodified, sk:return_, void_type_node, bypass 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; Mon, 27 May 2019 11:07:25 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 33C8581369 for ; Mon, 27 May 2019 13:07:23 +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 fHJt-25wjhyF for ; Mon, 27 May 2019 13:07:23 +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 1040881368 for ; Mon, 27 May 2019 13:07:22 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Do not generate dangling references to bounds Date: Mon, 27 May 2019 13:07:22 +0200 Message-ID: <1946860.3htyPdm6oa@polaris> MIME-Version: 1.0 This prevents gigi from generating dangling references to the bounds of an aliased parameter of an unconstrained array type. This cannot happen in strict Ada but you can bypass the rules by means of 'Unchecked_Access. Tested on x86_64-suse-linux, applied on the mainline and 9 branch. 2019-05-27 Eric Botcazou * gcc-interface/trans.c (Identifier_to_gnu): Minor tweaks. (gnat_to_gnu): Do not convert the result if it is a reference to an unconstrained array used as the prefix of an attribute reference that requires an lvalue. 2019-05-27 Eric Botcazou * gnat.dg/aliased2.adb: New test. Index: gcc-interface/trans.c =================================================================== --- gcc-interface/trans.c (revision 271650) +++ gcc-interface/trans.c (working copy) @@ -1110,11 +1110,12 @@ Identifier_to_gnu (Node_Id gnat_node, tr } else { - /* We want to use the Actual_Subtype if it has already been elaborated, - otherwise the Etype. Avoid using Actual_Subtype for packed arrays to - simplify things. */ + /* 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. */ if ((Ekind (gnat_entity) == E_Constant - || Ekind (gnat_entity) == E_Variable || Is_Formal (gnat_entity)) + || Ekind (gnat_entity) == E_Variable + || Is_Formal (gnat_entity)) && !(Is_Array_Type (Etype (gnat_entity)) && Present (Packed_Array_Impl_Type (Etype (gnat_entity)))) && Present (Actual_Subtype (gnat_entity)) @@ -8685,7 +8686,11 @@ gnat_to_gnu (Node_Id gnat_node) declaration, return the result unmodified because we want to use the return slot optimization in this case. - 5. Finally, if the type of the result is already correct. */ + 5. If this is a reference to an unconstrained array which is used as the + prefix of an attribute reference that requires an lvalue, return the + result unmodified because we want return the original bounds. + + 6. Finally, if the type of the result is already correct. */ if (Present (Parent (gnat_node)) && (lhs_or_actual_p (gnat_node) @@ -8734,13 +8739,19 @@ gnat_to_gnu (Node_Id gnat_node) else if (gnu_result == error_mark_node || gnu_result_type == void_type_node) gnu_result = error_mark_node; - else if (Present (Parent (gnat_node)) + else if (TREE_CODE (gnu_result) == CALL_EXPR + && Present (Parent (gnat_node)) && (Nkind (Parent (gnat_node)) == N_Object_Declaration || Nkind (Parent (gnat_node)) == N_Object_Renaming_Declaration) - && TREE_CODE (gnu_result) == CALL_EXPR && return_type_with_variable_size_p (TREE_TYPE (gnu_result))) ; + else if (TREE_CODE (gnu_result) == UNCONSTRAINED_ARRAY_REF + && Present (Parent (gnat_node)) + && Nkind (Parent (gnat_node)) == N_Attribute_Reference + && lvalue_required_for_attribute_p (Parent (gnat_node))) + ; + else if (TREE_TYPE (gnu_result) != gnu_result_type) gnu_result = convert (gnu_result_type, gnu_result);