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: 70295 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 6F0C3387159C for ; Tue, 30 May 2023 07:28:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F0C3387159C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685431694; 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=qGXpVVWd6Mbf9QVVMXEEszeKeugGUul2GZsTw95ZWgfPWtGjDdEfTupg1caxoabHp RpkNszSKh77/cqN1P4YRr146bLV5HzUwZaV8RNP4vkJCEfA5TzNlmJWjiulMYfQ/zy cQ9v9pmJmSPuxOSJ1Z8sebD1M5GNrOQJ+BCqX9MY= 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-Google-Smtp-Source: ACHHUZ4tGCSyQcpRuk/XTSR7onAR73I8iuQsbiEV6x56zLaTjjZZ6nCWckThj4YUevnCjfyxwPi9Cg== 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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);