https://gcc.gnu.org/g:85b6344379e7463c7cca0d731a09e122467dc1b6

commit r16-5001-g85b6344379e7463c7cca0d731a09e122467dc1b6
Author: Piotr Trojanek <[email protected]>
Date:   Wed Oct 22 17:38:04 2025 +0200

    ada: Guard compile-time evaluator against rewritten if-expressions
    
    A hopefully temporary fix for if-expression that has been rewritten into an
    if-statement, where a object reference has the if-statement as its parent,
    but is not part of the condition, then statements or else statements.
    
    gcc/ada/ChangeLog:
    
            * exp_util.adb (Get_Current_Value_Condition): Guard against orphaned
            references in rewritten if-expressions.

Diff:
---
 gcc/ada/exp_util.adb | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index f1893c26e3a8..e2d2554d3a1f 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -7663,9 +7663,12 @@ package body Exp_Util is
                   if Previous = Condition (If_Stmt) then
                      return;
 
-                  else
-                     pragma Assert
-                       (List_Containing (Previous)
+                  --  Guard against if-statements coming from if-statements
+                  --  with broken chain of parents.
+
+                  elsif Is_List_Member (Previous) then
+                     pragma Assert (
+                       List_Containing (Previous)
                           in Then_Statements (If_Stmt)
                            | Elsif_Parts (If_Stmt)
                            | Else_Statements (If_Stmt));
@@ -7674,6 +7677,9 @@ package body Exp_Util is
                        (if CV = If_Stmt
                         then List_Containing (Previous) = Then_Statements (CV)
                         else Previous = CV);
+                  else
+                     pragma Assert (From_Conditional_Expression (If_Stmt));
+                     return;
                   end if;
                else
                   return;

Reply via email to