From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by sourceware.org (Postfix) with ESMTPS id ADFDC385771B for ; Thu, 15 Jun 2023 08:04:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ADFDC385771B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-4f766777605so2447905e87.1 for ; Thu, 15 Jun 2023 01:04:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1686816257; x=1689408257; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PxhUq07cxbhv5phf4CoQUzqOd6uEG6DNU25F6EN63HU=; b=DLhmf1sggc0wWFbPSj8VtotP3vAdpaoDmgwKZHXdnQa6yNerDgNErGL2ab06SieKYy okxyPjSgXcrr7fk3fvw8edTD4188sr/Q+Bm7VMneaWemY4o0P7xUx2tHHqpjR8hFjUau mMAxlslK58tlF10tvawL1LtXdRX8M+tTlZrKUj6ziPJ4fdNjgAfWVAi3XL8MVdKo5CIS dq6pR3125aExapPLRVF1OT6j79+Dvd1m0t3IE48QQvuIfYOg3LUQCDE3C7teOT6DW6fh YjBmnacs7lLw5Zm0ePdbllMvoVXpq+rWwQNDYXL/RSVLTGrVIdUDKLGW8ER9WGKIgBVb /DHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686816257; x=1689408257; 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=PxhUq07cxbhv5phf4CoQUzqOd6uEG6DNU25F6EN63HU=; b=FJstz6xF+1K0uHjhAXiawJy18pJp3TF/3reo4XArZThqznI/1apSxT2mshrPbMJNke LwJ7yK6ftJcEZ6w7rJy9HfsMT+WWdMC/wBT0xY7cLFItxRKaD1YbIS1cQoH+mE5pLNNm TGwIxNfVGwEAJwCyUbIUtnJ+AH9w81kYbjtGK2Cd5G5GR4f5rXWA4Ckma6dKiqUMMpjt Xf+ThV2bhCJIBh/LxAW+2BFtYhXktKA4lCkmh6KdYF/aeM3I/10h6nUZdsY474IK6fuH Jhxj3zeGepKFZY9k27N+Gk4tsO7+luIf9GTAMYwxjI8/DxVjxuQ0zr2my6k7acYde54L rPiQ== X-Gm-Message-State: AC+VfDylGVmr7fiN/DZ1j6FGb22ikixzBtMTlhkysBtvwedjvffm94ri CLREKs2ADyOOR4p67+Xm162E///0Dn85SqdTGSLBTA== X-Google-Smtp-Source: ACHHUZ6p4id/O4IZ0oyJZPxbPtl/mr/sWlihNeoevIikmnUE2tlyCIACJDvmrLeCh11pa5WqLZVWGQ== X-Received: by 2002:ac2:4842:0:b0:4f3:f98c:77fc with SMTP id 2-20020ac24842000000b004f3f98c77fcmr9267770lfy.8.1686816257359; Thu, 15 Jun 2023 01:04:17 -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 y19-20020a05600c365300b003f7f60203ffsm19639863wmq.25.2023.06.15.01.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jun 2023 01:04:16 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix missing finalization for aggregates nested in conditional expressions Date: Thu, 15 Jun 2023 10:04:15 +0200 Message-Id: <20230615080415.939740-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 List-Id: From: Eric Botcazou The finalization actions for the components of the aggregates are blocked by Expand_Ctrl_Function_Call, which sets Is_Ignored_Transient on all the temporaries generated from within a conditional expression whatever the intermediate constructs. Now aggregates and their expansion in the form of block and loop statements are "impenetrable" as far as temporaries are concerned, i.e. the lifetime of temporaries generated within them does not extend beyond them, so their finalization must not be blocked there. gcc/ada/ * exp_util.ads (Within_Case_Or_If_Expression): Adjust description. * exp_util.adb (Find_Hook_Context): Stop the search for the topmost conditional expression, if within one, at contexts where temporaries may be contained. (Within_Case_Or_If_Expression): Return false upon first encoutering contexts where temporaries may be contained. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_util.adb | 20 ++++++++++++++++++++ gcc/ada/exp_util.ads | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb index b032336523d..a4aa5f64447 100644 --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -6500,6 +6500,16 @@ package body Exp_Util is then Top := Par; + -- Stop at contexts where temporaries may be contained + + elsif Nkind (Par) in N_Aggregate + | N_Delta_Aggregate + | N_Extension_Aggregate + | N_Block_Statement + | N_Loop_Statement + then + exit; + -- Prevent the search from going too far elsif Is_Body_Or_Package_Declaration (Par) then @@ -14222,6 +14232,16 @@ package body Exp_Util is then return True; + -- Stop at contexts where temporaries may be contained + + elsif Nkind (Par) in N_Aggregate + | N_Delta_Aggregate + | N_Extension_Aggregate + | N_Block_Statement + | N_Loop_Statement + then + return False; + -- Prevent the search from going too far elsif Is_Body_Or_Package_Declaration (Par) then diff --git a/gcc/ada/exp_util.ads b/gcc/ada/exp_util.ads index 66c4dc6be4c..24065b6f7b6 100644 --- a/gcc/ada/exp_util.ads +++ b/gcc/ada/exp_util.ads @@ -1240,7 +1240,9 @@ package Exp_Util is -- extension to verify legality rules on inherited conditions. function Within_Case_Or_If_Expression (N : Node_Id) return Boolean; - -- Determine whether arbitrary node N is within a case or an if expression + -- Determine whether arbitrary node N is immediately within a case or an if + -- expression. The criterion is whether temporaries created by the actions + -- attached to N need to outlive an enclosing case or if expression. private pragma Inline (Duplicate_Subexpr); -- 2.40.0