From patchwork Mon Sep 15 13:01:18 2025 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: 120270 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 869C03858C36 for ; Mon, 15 Sep 2025 13:21:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 869C03858C36 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=NIJaig6/ X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id E5D1D38560BE for ; Mon, 15 Sep 2025 13:02:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E5D1D38560BE 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 E5D1D38560BE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757941321; cv=none; b=SwnJMjRdqdQtp4ltsQydldu27C83T6Myu6pNLhZIhRbEZ1+QpgqzTtvKz7BPHX/ESfXU+9HHt4vZIdGPLMTcSrXIZi3ikEt4QPt71em2qvwUFDPazNwsEkMtBSN72CeNNILnHBcKZwBZrwDaeGnu1SimeUCPjMVR5JW6D+p/GNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757941321; c=relaxed/simple; bh=DW9XuVNXRSuKvO3b3hSFdoE1qIbFAJawSfYDqHWv3F0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nvedsNhnCOxIKVEvRwTw4q9X4dMmO5CRmBiNNO74O6wlL7lCxGFhg6MAwiWeLc213a3+SDOsS2hrcqNYQQCfYG0hUdQ9FnmgMzKbtNmtn4VhxFPvq6oXT3O3cte928TVW9t2yewqIq6GeTkjzEmltXsTx+ga8cJGwOVnvY5qBig= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E5D1D38560BE Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-45f29e5e89bso18808715e9.2 for ; Mon, 15 Sep 2025 06:02:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1757941319; x=1758546119; 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=NcUEhWSKrg7m1g/y3mmcd/VBD2BsqRh1qkX6B51AJZ4=; b=NIJaig6/bk8PHiux9nfJ8qrGHCAG6VPwaiZoi+iWDWxdD8/w+24f0lhkvI+HkmSyZe 0RX7ogiehAxbajcwJirTCCCAYEFMHunD6xQxB3BwzHvuG4lVoWJtBV/4aD8iKODiCNlA ym55CgjLZMKP3qSB7I+45W2Be3LIK7o20H6ktetyK0rZx86jQPQVXqvKlQ/d05Zjy6XL N5Qd9tL7fIWHKPxlf2RPKYc0sPT1rgpcJPa1UAOoNn+SI39aT6rBw1u14tL8K7skBXrv EEtie5ZmZ5VFUCNVwTwioGeiZwCwXUQMGibVgX5tGGrLunxklOajEYzgx9b1MGuS6v4w xOXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757941319; x=1758546119; 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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1buEwT3SUBwTGm+5Lx92wtlwbDyWbRW9nnNbrGC1VspkgA0lnLve/Z9mfeUus/g2F5Q== X-Received: by 2002:a05:600c:45c4:b0:45b:5f3d:aa3d with SMTP id 5b1f17b1804b1-45f211e6832mr106297775e9.21.1757941319205; Mon, 15 Sep 2025 06:01:59 -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 ffacd0b85a97d-3ea4b52b7fcsm5428733f8f.33.2025.09.15.06.01.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 06:01:58 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED 12/27] ada: Fix missing finalization for qualified expression in conditional expression Date: Mon, 15 Sep 2025 15:01:18 +0200 Message-ID: <20250915130135.2720894-12-poulhies@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250915130135.2720894-1-poulhies@adacore.com> References: <20250915130135.2720894-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 A qualified expression around a function call may cause a temporary to be created and, therefore, cannot be bypassed in Expand_Ctrl_Function_Call. gcc/ada/ChangeLog: * exp_util.ads (Unqualified_Unconditional_Parent): New function. * exp_util.adb (Unconditional_Parent): Do not look through qualified expressions. (Unqualified_Unconditional_Parent): New function identical to the original Unconditional_Parent. * exp_aggr.adb (Convert_To_Assignments): Replace Unconditional_Parent with Unqualified_Unconditional_Parent. (Expand_Array_Aggregate): Likewse. * exp_ch4.adb (Expand_N_Case_Expression): Likewise. (Expand_N_If_Expression): Likewise. * exp_ch6.adb (Expand_Ctrl_Function_Call): Do not bypass an enclosing qualified expression in the parent chain. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_aggr.adb | 4 ++-- gcc/ada/exp_ch4.adb | 6 ++++-- gcc/ada/exp_ch6.adb | 5 ++++- gcc/ada/exp_util.adb | 33 ++++++++++++++++++++++++++++++++- gcc/ada/exp_util.ads | 4 ++++ 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index 6b4f4a19d1f9..d62b7351e862 100644 --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -4283,7 +4283,7 @@ package body Exp_Aggr is -- Set the Expansion_Delayed flag in the cases where the transformation -- will be done top down from above. - Parent_Node := Unconditional_Parent (N); + Parent_Node := Unqualified_Unconditional_Parent (N); if -- Internal aggregates (transformed when expanding the parent), @@ -6254,7 +6254,7 @@ package body Exp_Aggr is -- Set the Expansion_Delayed flag in the cases where the transformation -- will be done top down from above. - Parent_Node := Unconditional_Parent (N); + Parent_Node := Unqualified_Unconditional_Parent (N); if -- Internal aggregates (transformed when expanding the parent), diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 23a59de6f872..8fba1c4e71fa 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -5198,7 +5198,8 @@ package body Exp_Ch4 is if not Expansion_Delayed (N) then declare - Uncond_Par : constant Node_Id := Unconditional_Parent (N); + Uncond_Par : constant Node_Id := + Unqualified_Unconditional_Parent (N); begin if Nkind (Uncond_Par) = N_Simple_Return_Statement or else Is_Optimizable_Declaration (Uncond_Par) @@ -5807,7 +5808,8 @@ package body Exp_Ch4 is if not Expansion_Delayed (N) then declare - Uncond_Par : constant Node_Id := Unconditional_Parent (N); + Uncond_Par : constant Node_Id := + Unqualified_Unconditional_Parent (N); begin if Nkind (Uncond_Par) = N_Simple_Return_Statement or else Is_Optimizable_Declaration (Uncond_Par) diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index 32e96bed2349..5056b1f990fa 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -5793,11 +5793,14 @@ package body Exp_Ch6 is is Par : constant Node_Id := Parent (N); Uncond_Par : constant Node_Id := Unconditional_Parent (N); + -- Beware that a qualified expression around a function call cannot be + -- considered as transparent (like around an aggregate) because it may + -- cause a temporary to be created. begin -- Optimization: if the returned value is returned again, then no need -- to copy/readjust/finalize, we can just pass the value through (see - -- Expand_N_Simple_Return_Statement), and thus no attachment is needed. + -- Expand_Simple_Function_Return), and thus no attachment is needed. -- Note that simple return statements are distributed into conditional -- expressions, but we may be invoked before this distribution is done. diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb index 6ce6c0cd81d6..4135e24424d3 100644 --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -14903,6 +14903,37 @@ package body Exp_Util is Node : Node_Id := N; Parent_Node : Node_Id := Parent (Node); + begin + loop + case Nkind (Parent_Node) is + when N_Case_Expression_Alternative => + null; + + when N_Case_Expression => + exit when Node = Expression (Parent_Node); + + when N_If_Expression => + exit when Node = First (Expressions (Parent_Node)); + + when others => + exit; + end case; + + Node := Parent_Node; + Parent_Node := Parent (Node); + end loop; + + return Parent_Node; + end Unconditional_Parent; + + -------------------------------------- + -- Unqualified_Unconditional_Parent -- + -------------------------------------- + + function Unqualified_Unconditional_Parent (N : Node_Id) return Node_Id is + Node : Node_Id := N; + Parent_Node : Node_Id := Parent (Node); + begin loop case Nkind (Parent_Node) is @@ -14927,7 +14958,7 @@ package body Exp_Util is end loop; return Parent_Node; - end Unconditional_Parent; + end Unqualified_Unconditional_Parent; ------------------------------- -- Update_Primitives_Mapping -- diff --git a/gcc/ada/exp_util.ads b/gcc/ada/exp_util.ads index 4226fcc93777..b7d8a185f4bd 100644 --- a/gcc/ada/exp_util.ads +++ b/gcc/ada/exp_util.ads @@ -1344,6 +1344,10 @@ package Exp_Util is function Unconditional_Parent (N : Node_Id) return Node_Id; -- Return the first parent of arbitrary node N that is not a conditional + -- expression, one of whose dependent expressions is N, recursively. + + function Unqualified_Unconditional_Parent (N : Node_Id) return Node_Id; + -- Return the first parent of arbitrary node N that is not a conditional -- expression, one of whose dependent expressions is N, and that is not -- a qualified expression, whose expression is N, recursively.