From patchwork Thu Jun 15 08:04:34 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: 108343 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp472820vqr; Thu, 15 Jun 2023 01:20:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4CTGqxMP8nmbJFdFp+rPL54SPtKH+9GC8JBE/zQ0Ls/LQ3igQ5m4FJxAu71XIPQXSTf0TQ X-Received: by 2002:a17:907:972a:b0:982:781e:ba13 with SMTP id jg42-20020a170907972a00b00982781eba13mr3880634ejc.39.1686817224272; Thu, 15 Jun 2023 01:20:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686817224; cv=none; d=google.com; s=arc-20160816; b=oKSZdmGd9EtKoPLdPorTmE/OFYuPnsMcUeBezIDYPvq4UeU6xAmzFsLcWYoXwiyYMW MOo/fSE40OouFKmQxNASCw1eTPzNCKtnYAdxR0sHNb4P6uOMBLQizbM9LRyW5ckAbI5H aC9jXh52v4+CsnVZsmyBakZVgAHb6x5E+rBxNV1JS4Aw1p9yocHjORJvzW9SgFrgDQsP Ohn+O6Slak4iB4t5P6euSztyuxAQJq6b4QN+WfBMMrgklM6kI0bW2E4VkuHKbL52rhFN by+0X87LQAZoWLkXxgoNN3EIiCr/BrDyajpgwf2dHEVbiQfYi894O79drGCM5caqaVxR Cy1Q== 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=kA85GIaAqJvWW7RyyiC9GoWPiHvNiF9wGJ0nwHOBfp8=; b=J25c4/lff2aTRowTkJlfFBt1yz7i1R4Lg0NI7ngMA56zlxyxOh/vWEDxNcegX5S8go 0LBl4q7idIcHuk6xby65+0c5r4k+lX74Mmwy9caktfPY3alvmjjP8hlp3juyg+8nryCe lUSaqLon1yrkkRazL6YJ5zQhbm5D2uUf3kE13UKEJCKjFM6/UMHsoXvJ0ub/+lvpiYhs eOGLpPHAedBMO3bwY9mAQUEUbbZlTopWojtun0Pjnm+6DqAHVqVPP0LBPgksouKRyhfy y/ITV8bXCyqwgOOzNicZw+g/wUy+CkH/doAXJDUdDHpWPRnFKE/6uRZhUXeVrOYw+Rk5 vo4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gw6YfrG3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h6-20020a170906718600b009750bc1cb30si8702805ejk.946.2023.06.15.01.20.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jun 2023 01:20:24 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gw6YfrG3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 07020385701C for ; Thu, 15 Jun 2023 08:12:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 07020385701C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686816773; bh=kA85GIaAqJvWW7RyyiC9GoWPiHvNiF9wGJ0nwHOBfp8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=gw6YfrG3dO3knshW3RdAznbpahy5jSK07rN80rlVRlLmYGcq4XFA+sSb5iRj2AVqg d/3IvbNftmDOujKclFPnCLwsa7W0+P+V6aY6djgPz59lmtdXhSBXoC3MAojriiuZFZ VJKIKzT1hC/iyWkhrOPwtY+ZkO67dunYWkFAhZRE= 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 764F13857711 for ; Thu, 15 Jun 2023 08:04:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 764F13857711 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-310b631c644so1753042f8f.0 for ; Thu, 15 Jun 2023 01:04:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686816276; x=1689408276; 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=kA85GIaAqJvWW7RyyiC9GoWPiHvNiF9wGJ0nwHOBfp8=; b=NvGPuXQsTcOcFoFWKda5THkQXr/hoiCvoxvxLtJhCtTeffDTgv2iaq0u+h8yj3C+Ru Yhodfa1W7LJGqArwLJXifcGLSby7jVgK1hGk6feso8a/kxeyByzLDDmDzMRjKilhGD+E VzTjVLG7x+Z7hdjQVSZDdrWXpuW89a9S9tYuQ2QGjJuUAX7JoIQImGTigQe/iWAVdnaw nT7GrVZsh2iS9KeIGiQU1kxd6h2j0pCWZC3ttP2rXsnSqzXRElIxFZ+8qJczBSIBJcsM tlCwLZdPaAysWeL0tZxACjnGH+G9YAdjjwYvyxppkbt6ma4u0vssRyHjbn4fz38GVN4t rq/w== X-Gm-Message-State: AC+VfDwPx2lvsFFB3n2utq+ZvZP/l0q5tYDKjVCbfxkGsSGsUtFox8AH hME/H/qb400Uu+aTIf9/RGJRnhjfu/85lLwJUl4uyQ== X-Received: by 2002:adf:f489:0:b0:30a:e619:3a71 with SMTP id l9-20020adff489000000b0030ae6193a71mr12646265wro.23.1686816276243; Thu, 15 Jun 2023 01:04:36 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id y3-20020a5d6203000000b003062c0ef959sm20276632wru.69.2023.06.15.01.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jun 2023 01:04:35 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix wrong finalization for double subtype of bounded vector Date: Thu, 15 Jun 2023 10:04:34 +0200 Message-Id: <20230615080434.940329-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?1768756057685984452?= X-GMAIL-MSGID: =?utf-8?q?1768756057685984452?= From: Eric Botcazou The special handling of temporaries created for return values and subject to a renaming needs to be restricted to the top level, where it is needed to prevent dangling references to the frame of the elaboration routine from being created, because, at a lower level, the front-end may create implicit renamings of objects as these temporaries, so a copy is not allowed. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) : Restrict the special handling of temporaries created for return values and subject to a renaming to the top level. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/gcc-interface/decl.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc index e5e04ddad93..b2b77787bc0 100644 --- a/gcc/ada/gcc-interface/decl.cc +++ b/gcc/ada/gcc-interface/decl.cc @@ -1076,9 +1076,13 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) || EXPRESSION_CLASS_P (inner) /* We need to detect the case where a temporary is created to hold the return value, since we cannot safely rename it at - top level as it lives only in the elaboration routine. */ + top level because it lives only in the elaboration routine. + But, at a lower level, an object initialized by a function + call may be (implicitly) renamed as this temporary by the + front-end and, in this case, we cannot make a copy. */ || (VAR_P (inner) - && DECL_RETURN_VALUE_P (inner)) + && DECL_RETURN_VALUE_P (inner) + && global_bindings_p ()) /* We also need to detect the case where the front-end creates a dangling 'reference to a function call at top level and substitutes it in the renaming, for example: @@ -1092,12 +1096,14 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) q__b : boolean renames q__R1s.all.e (1); We cannot safely rename the rewritten expression since the - underlying object lives only in the elaboration routine. */ + underlying object lives only in the elaboration routine but, + as above, this cannot be done at a lower level. */ || (INDIRECT_REF_P (inner) && (inner = remove_conversions (TREE_OPERAND (inner, 0), true)) && VAR_P (inner) - && DECL_RETURN_VALUE_P (inner))) + && DECL_RETURN_VALUE_P (inner) + && global_bindings_p ())) ; /* Otherwise, this is an lvalue being renamed, so it needs to be