public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-1854] ada: Fix missing finalization for aggregates nested in conditional expressions
@ 2023-06-15  8:02 Marc Poulhi?s
  0 siblings, 0 replies; only message in thread
From: Marc Poulhi?s @ 2023-06-15  8:02 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:985d6045f66281bd3783523360375431ee343b08

commit r14-1854-g985d6045f66281bd3783523360375431ee343b08
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Sun May 14 11:49:09 2023 +0200

    ada: Fix missing finalization for aggregates nested in conditional expressions
    
    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.

Diff:
---
 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);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-15  8:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-15  8:02 [gcc r14-1854] ada: Fix missing finalization for aggregates nested in conditional expressions Marc Poulhi?s

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).