https://gcc.gnu.org/g:81645c63e925e5fafb6e0836e0cd5585a0bec1d0

commit r15-9910-g81645c63e925e5fafb6e0836e0cd5585a0bec1d0
Author: Ronan Desplanques <desplanq...@adacore.com>
Date:   Tue Jun 10 12:51:26 2025 +0200

    ada: Refine sanity check in Insert_Actions
    
    Insert_Actions performs a sanity check when it goes through an
    expression with actions while going up the three. That check was not
    perfectly right before this patch and spuriously failed when inserting
    range checks in some situation. This patch makes the check more robust.
    
    gcc/ada/ChangeLog:
    
            * exp_util.adb (Insert_Actions): Fix check.

Diff:
---
 gcc/ada/exp_util.adb | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 4fc0135e0bde..f225e179b234 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -8057,21 +8057,21 @@ package body Exp_Util is
             --  never climb up as far as the N_Expression_With_Actions itself.
 
             when N_Expression_With_Actions =>
-               if N = Expression (P) then
-                  if Is_Empty_List (Actions (P)) then
-                     Append_List_To (Actions (P), Ins_Actions);
-                     Analyze_List (Actions (P));
-                  else
-                     Insert_List_After_And_Analyze
-                       (Last (Actions (P)), Ins_Actions);
-                  end if;
-
-                  return;
+               if Is_List_Member (N) and then List_Containing (N) = Actions (P)
+               then
+                  raise Program_Error;
+               end if;
 
+               if Is_Empty_List (Actions (P)) then
+                  Append_List_To (Actions (P), Ins_Actions);
+                  Analyze_List (Actions (P));
                else
-                  raise Program_Error;
+                  Insert_List_After_And_Analyze
+                    (Last (Actions (P)), Ins_Actions);
                end if;
 
+               return;
+
             --  Case of appearing in the condition of a while expression or
             --  elsif. We insert the actions into the Condition_Actions field.
             --  They will be moved further out when the while loop or elsif

Reply via email to