From patchwork Tue May 30 07:21:22 2023 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: 100611 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1999815vqr; Tue, 30 May 2023 00:35:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ieFIO3W0ZDX5ar4tBY3EOpum/KoG28lQZoouAVD85W4Isr6DD/UOpfk/m9jvd8o5ssGld X-Received: by 2002:a17:907:2d27:b0:94e:4285:390c with SMTP id gs39-20020a1709072d2700b0094e4285390cmr1400919ejc.10.1685432110820; Tue, 30 May 2023 00:35:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685432110; cv=none; d=google.com; s=arc-20160816; b=ac9qEUbBriCjn/b2ARlgJwpnmjyL9/kG7BZY4tdWJBBGBjySpdmVlYgM2ELETTdN3c Zfg1L8E2svH9fsf8NIZyY1RMb/7SVrsKqsznJ06WQu7rWfUTt4PyCCdBonYl+GdVrKKX 0OfC71bPUWvbWB2cgrwX5JCNMAnjqupQtPqbnKZL7MbDZNLsYxA6dXk4EG4xw2WfttEq bLxmI24WegX0pZpP0WSYvrZKWpU6yY7LXD0gR2YLZqYbnzTWSdWUG1oi9VuxXZ5ZHm+4 0sibzRK6BE2FXEjHJk5KSGWkEw91FunvzCtwTUwZksA0DTQFUVijVaGjHuvFaFMedUG3 qQXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=7QpTJi3oamePJtDi8VEQgVUM+vDaWE3dDMRBBLxVELA=; b=swSoNPf8lMpNjWmBoU4Bm01himJBcye7al0JKRijyDzhETPSb9BI1pyVt+32h6ySP3 BYUCF+nAFd5DXDfOR+us3cRCq/0+/m3BbiEANx3NOcH/JRBeFr5O3KvNQluGbY4KTL0T jDaVOHqgJvhYaSf2TxT5X5iojARByp6VsjYue0MGAUtQqIt3igdxzARGjvue+HgsLylF 8xAopjxZF81Ze2aAIpS2fS+mk5n9varbmYxvaULHMrCPE54X7uGyGFBCEzRRPVbFbmR/ 4MBCH/PuqN8mzBlabhqWHB7/dlaTXvmPOE58zi2pfcgy58Pqvv+Fo0K08e0RMLdZvCF/ Rp7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wv12Xt4U; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e13-20020a170906314d00b0095ece5cf770si1155909eje.695.2023.05.30.00.35.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 00:35:10 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wv12Xt4U; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E71F383E8DA for ; Tue, 30 May 2023 07:28:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E71F383E8DA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685431710; bh=7QpTJi3oamePJtDi8VEQgVUM+vDaWE3dDMRBBLxVELA=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=wv12Xt4U63YZexs8DllWPR40W5OWO1YgN8J3/aS3W8oE7whK+++hrLO70AZss3Wv5 cW+EpwO+mAKEGwek1NUf7gf+py3cgpsAvsMKaNqlE1QfeY7T82LIN6YYQCC6HPcwni 6dRIa4mZy2XuNKMbjMUX61GjN6zfOjbFRhQij+ps= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 87D7A384F1D9 for ; Tue, 30 May 2023 07:21:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 87D7A384F1D9 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-30aeee7c8a0so1046716f8f.1 for ; Tue, 30 May 2023 00:21:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685431284; x=1688023284; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7QpTJi3oamePJtDi8VEQgVUM+vDaWE3dDMRBBLxVELA=; b=MM0PKAQ9hYL5Ba5FWcZS9qR+U6x/4rH1C5VPIkD8sB4Qy+5AhK+1krk1sqEZ/Ppu5w urPWi2tCA2dD9MR4rX746MkNmMPZVzSu7/rvm6gjEucZb1YdNJjkHNg4WpFdvkZVdS9E MsH6rhVsdhb59RouH2BGNZ8sGc8cL+pVn9n4/HZbKU/3SDAT2FW471OjaPccRN2hArct M6t7Bw/Dcagy/Yv6fVw/5VuzpURq1w1vzSlM1gTPWFkB1vgaeCdUMZXYeDBIjI5QugO9 Rl+VCq9S8mR08JkvuahWG2lIoDfUQtD9oZqbYR8R+4pEYzh9ESpNUSxedfjnVTPxXYKH acAw== X-Gm-Message-State: AC+VfDxfMtmS8Ic0lgyINbDIwp0VtgxCp8F46hNJBiARdiTt40DgaT0Z K2ucxjq8H1q2E8xOinPMq2YdgWLNLqsMzeFa2aUdXA== X-Received: by 2002:adf:f812:0:b0:2f6:661:c03c with SMTP id s18-20020adff812000000b002f60661c03cmr1108751wrp.28.1685431284506; Tue, 30 May 2023 00:21:24 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:7733:a608:a415:6b2a]) by smtp.gmail.com with ESMTPSA id b9-20020adfe309000000b003079986fd71sm2259172wrj.88.2023.05.30.00.21.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 00:21:24 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: =?utf-8?q?Marc_Poulhi=C3=A8s?= Subject: [COMMITTED] ada: Fix incorrect copies being used with 'Address Date: Tue, 30 May 2023 09:21:22 +0200 Message-Id: <20230530072122.2500875-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767303661063368034?= X-GMAIL-MSGID: =?utf-8?q?1767303661063368034?= When using 'Address on an object with a size clause, gigi would end up creating a copy and using its address instead of the one of the original object, leading to incorrect behavior. Remove the conversion (that triggers the copy) when 'Address is applied to a declaration. gcc/ada/ * gcc-interface/trans.cc (Attribute_to_gnu): Also strip conversion in case of DECL. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/gcc-interface/trans.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc index 1c3c6c0618e..57933ceb8a3 100644 --- a/gcc/ada/gcc-interface/trans.cc +++ b/gcc/ada/gcc-interface/trans.cc @@ -1714,12 +1714,17 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute) case Attr_Address: case Attr_Unrestricted_Access: /* Conversions don't change the address of references but can cause - build_unary_op to miss the references below, so strip them off. + build_unary_op to miss the references below so strip them off. + + Also remove the conversions applied to declarations as the intent is + to take the decls' address, not that of the copies that the + conversions may create. + On the contrary, if the address-of operation causes a temporary to be created, then it must be created with the proper type. */ gnu_expr = remove_conversions (gnu_prefix, !Must_Be_Byte_Aligned (gnat_node)); - if (REFERENCE_CLASS_P (gnu_expr)) + if (REFERENCE_CLASS_P (gnu_expr) || DECL_P (gnu_expr)) gnu_prefix = gnu_expr; /* If we are taking 'Address of an unconstrained object, this is the @@ -4575,7 +4580,7 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, /* The FUNCTION_TYPE node giving the GCC type of the subprogram. */ tree gnu_subprog_type = TREE_TYPE (gnu_subprog); /* The return type of the FUNCTION_TYPE. */ - tree gnu_result_type;; + tree gnu_result_type; const bool frontend_builtin = (TREE_CODE (gnu_subprog) == FUNCTION_DECL && DECL_BUILT_IN_CLASS (gnu_subprog) == BUILT_IN_FRONTEND); @@ -4657,7 +4662,7 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, } /* We must elaborate the entire profile now because, if it references types - that were initially incomplete,, their elaboration changes the contents + that were initially incomplete, their elaboration changes the contents of GNU_SUBPROG_TYPE and, in particular, may change the result type. */ elaborate_profile (gnat_formal, gnat_result_type);