]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Guard compile-time evaluator against rewritten if-expressions
authorPiotr Trojanek <trojanek@adacore.com>
Wed, 22 Oct 2025 15:38:04 +0000 (17:38 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 3 Nov 2025 14:15:18 +0000 (15:15 +0100)
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.

gcc/ada/exp_util.adb

index f1893c26e3a898595c2b7bc9c7a9a834205acc23..e2d2554d3a1f21a5c3b38d71296729a03693bed2 100644 (file)
@@ -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;