From patchwork Tue May 21 07:30:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 90545 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B61D3858427 for ; Tue, 21 May 2024 07:38:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 910933858C60 for ; Tue, 21 May 2024 07:31:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 910933858C60 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 910933858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::332 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716276667; cv=none; b=S/BcC+l98WEk8X9FwAjE2Xa7V3cz54kNxKzyCwm8Z90K3tYb9pOwZn6i57uX5R+LYB0vGkHYu7fD/cqw3yCHElmiQqjvO/nK2lTwFc1VwDVYyV6Tt6F6Z7QT808+kat7iarSlrHuq66xoYEg4u3ORV2HoWX2rsAnFCk4Ia6AVrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716276667; c=relaxed/simple; bh=rkyb0GeaLFDrwV00ouhKyWQfH0xDuqlSD7QyP3bcqCw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Hrp9GD5vUNhtBYMHAshFozbhT9QJacx09rEEHq0HP6oQqn5K+dkBgZ/PBaQbP/3OIjERwxK4LXaMA6qS7H14V3AZVX3F4ouhP/Lkuwj/FGoqNqiGd8kjJk2o7GAyeqNAfSqpcsDdzdVz7U5w0r5oBTS5+JEGUU2m7kPbYwMPGFU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-41f9ce16ed8so39180555e9.0 for ; Tue, 21 May 2024 00:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1716276662; x=1716881462; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2UUHjj3ez5iIp0vFuqvvFdUk/o/jtVJMao3rxFX2RQc=; b=UdPPqUJPhL3JNI5UwDAB+vB7t94QPNzwhplIlyu0gcetmCYPbdjq+zThYdh98IRD9A zc3oTlYm071XDUbRAtD5ss+c2fhAkwzTOkaI958DxHLkD0Kl20rERPEpEnOUSxwKHF5/ 9DDhe9SAyCRcGihUqlPfqCjwAkJ3ySSWA8alh1eBSZDjKkYh+rZ/nmBORhAvYaqYUSOx PWCIe05kMJBFV9qJ6u5JWdkyn9SsToda4NXhaN5TdJIrtQGMQYRqzzHh1scuMj7yJO6z pzxEhhroO+ngp7DwCGEwuU9mEilV3E5P9VXCa5dDSeedVqhn/bdBKaipGA42vN7++0Kb QNgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716276662; x=1716881462; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2UUHjj3ez5iIp0vFuqvvFdUk/o/jtVJMao3rxFX2RQc=; b=xNYG43lHV1/QxUry8FSZRzXIjjHIOcm5AdW7chOjBwSVKlD8ubiuRVrNjdOkIuv7Wh xRtT4d75MJ6vlrPPS9t8vyNLJdGz5IxmWQYoWOYeGlnAjjSROpWgmeEknb6GSy2GYToI YOyuqpltbpfpbORC1PrOz9obkP6j2MZa+UEBYjoymbTTRj9+90UE1CALKpomMaZKANOQ SJFUpiztx4JXGkjW8NpGn4dWnVIlkC/Ueq6wr1jnSi3YKp8OPPUWmYV+93+qiECwspzu 2tFdYXS6Knlm820GFucubSM+3xJ51ceS2Jo0vMmvWkcCHxX6QbxEu0BzoPJcIIQTJQrO puyQ== X-Gm-Message-State: AOJu0YyiEKg8vOa2wZY+mg4bpzfps1Z40XvkvbAa7jPpsxgZoMbUB/1L vMOUuTcy4BqQGDoZZhJEkgpTcr1h/V/hCqwfYgQsdbkxeEAWYSEL269nFKlLPube0G4GPJ+vn80 = X-Google-Smtp-Source: AGHT+IFULkz79uGVKtOlyuoAXDUBKqB6mWA/WoJ1PF64YPfwQTCxHBnsw6cv09SNsy4f5AskZol9WA== X-Received: by 2002:a05:600c:3508:b0:41b:f116:8868 with SMTP id 5b1f17b1804b1-41feaa38a79mr340252565e9.12.1716276661896; Tue, 21 May 2024 00:31:01 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:de37:8b1c:1f33:2610]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccee9292sm453333645e9.37.2024.05.21.00.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 00:31:01 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED 18/31] ada: Fix small inaccuracy for Size attribute applied to objects Date: Tue, 21 May 2024 09:30:21 +0200 Message-ID: <20240521073035.314024-18-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240521073035.314024-1-poulhies@adacore.com> References: <20240521073035.314024-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org From: Eric Botcazou This reverts a change made some time ago in lvalue_required_for_attribute_p whereby the Size attribute applied to objects would no longer be considered as requiring an lvalue. While not wrong in principle, this turns out to be problematic because the implementation in Attribute_to_gnu needs to look at the translated prefix to spot particular cases and not only at the actual type of its value. This of course requires a small adjustment in gnat_to_gnu to compensate. gcc/ada/ * gcc-interface/trans.cc (access_attribute_p): New predicate. (lvalue_required_for_attribute_p): Return again 1 for Size and add the missing terminating call to gcc_unreachable. (gnat_to_gnu): Return the result unmodified for a reference to an unconstrained array only if it is the prefix of an access attribute. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/gcc-interface/trans.cc | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc index 8c7ffbf5687..6f761766559 100644 --- a/gcc/ada/gcc-interface/trans.cc +++ b/gcc/ada/gcc-interface/trans.cc @@ -745,6 +745,26 @@ build_raise_check (int check, enum exception_info_kind kind) return result; } +/* Return true if GNAT_NODE, which is an N_Attribute_Reference, is one of the + access attributes. */ + +static bool +access_attribute_p (Node_Id gnat_node) +{ + switch (Get_Attribute_Id (Attribute_Name (gnat_node))) + { + case Attr_Access: + case Attr_Unchecked_Access: + case Attr_Unrestricted_Access: + return true; + + default: + return false; + } + + gcc_unreachable (); +} + /* Return a positive value if an lvalue is required for GNAT_NODE, which is an N_Attribute_Reference. */ @@ -760,7 +780,6 @@ lvalue_required_for_attribute_p (Node_Id gnat_node) 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: @@ -786,11 +805,14 @@ lvalue_required_for_attribute_p (Node_Id gnat_node) case Attr_First_Bit: case Attr_Last_Bit: case Attr_Bit: + case Attr_Size: case Attr_Asm_Input: case Attr_Asm_Output: default: return 1; } + + gcc_unreachable (); } /* Return a positive value if an lvalue is required for GNAT_NODE. GNU_TYPE @@ -8472,7 +8494,7 @@ gnat_to_gnu (Node_Id gnat_node) return slot optimization in this case. 5. If this is a reference to an unconstrained array which is used either - as the prefix of an attribute reference that requires an lvalue or in + as the prefix of an attribute reference for an access attribute or in a return statement without storage pool, return the result unmodified because we want to return the original bounds. @@ -8539,7 +8561,7 @@ gnat_to_gnu (Node_Id gnat_node) else if (TREE_CODE (TREE_TYPE (gnu_result)) == UNCONSTRAINED_ARRAY_TYPE && Present (Parent (gnat_node)) && ((Nkind (Parent (gnat_node)) == N_Attribute_Reference - && lvalue_required_for_attribute_p (Parent (gnat_node))) + && access_attribute_p (Parent (gnat_node))) || (Nkind (Parent (gnat_node)) == N_Simple_Return_Statement && No (Storage_Pool (Parent (gnat_node)))))) ;