[Ada] Check if- and case-expressions for unset references
authorPiotr Trojanek <trojanek@adacore.com>
Thu, 20 Jan 2022 23:33:06 +0000 (00:33 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 10 May 2022 08:19:25 +0000 (08:19 +0000)
Detection of references to unset (uninitialized) objects requires calls
to Check_Unset_Reference on every subexpression of a composite statement
and expression. This was missing for if-expressions and incomplete for
case-expressions.

gcc/ada/

* sem_res.adb (Resolve_Case_Expression): Check alternative
expressions for references to unset objects.
(Resolve_If_Expression): Check condition, then and else
expressions for references to unset objects.

gcc/ada/sem_res.adb

index 26da4ff..7d30f15 100644 (file)
@@ -7394,6 +7394,7 @@ package body Sem_Res is
          end if;
 
          Resolve (Alt_Expr, Typ);
+         Check_Unset_Reference (Alt_Expr);
          Alt_Typ := Etype (Alt_Expr);
 
          --  When the expression is of a scalar subtype different from the
@@ -9317,6 +9318,9 @@ package body Sem_Res is
 
       Resolve (Condition, Any_Boolean);
       Resolve (Then_Expr, Result_Type);
+      Check_Unset_Reference (Condition);
+      Check_Unset_Reference (Then_Expr);
+
       Apply_Check (Then_Expr);
 
       --  If ELSE expression present, just resolve using the determined type
@@ -9333,6 +9337,8 @@ package body Sem_Res is
             Resolve (Else_Expr, Result_Type);
          end if;
 
+         Check_Unset_Reference (Else_Expr);
+
          Apply_Check (Else_Expr);
 
          --  Apply RM 4.5.7 (17/3): whether the expression is statically or