[Ada] Check declare and qualified expressions for unset references
authorPiotr Trojanek <trojanek@adacore.com>
Sat, 22 Jan 2022 15:32:57 +0000 (16:32 +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. For declare and qualified expressions this was done only
when they occurred within another composite statement/expression.

gcc/ada/

* sem_res.adb (Resolve_Declare_Expression): Check expression for
references to unset objects.
(Resolve_Qualified_Expression): Likewise.
* sem_warn.adb (Check_Unset_Reference): Remove handling of
declare and qualified expressions; clarify comment for type
conversions.

gcc/ada/sem_res.adb
gcc/ada/sem_warn.adb

index 7d30f15..5a57d62 100644 (file)
@@ -7673,6 +7673,7 @@ package body Sem_Res is
       end if;
 
       Resolve (Expr, Typ);
+      Check_Unset_Reference (Expr);
    end Resolve_Declare_Expression;
 
    -----------------------------------------
@@ -10586,6 +10587,7 @@ package body Sem_Res is
 
    begin
       Resolve (Expr, Target_Typ);
+      Check_Unset_Reference (Expr);
 
       --  A qualified expression requires an exact match of the type, class-
       --  wide matching is not allowed. However, if the qualifying type is
index e02f6e0..8ca5c76 100644 (file)
@@ -2244,13 +2244,11 @@ package body Sem_Warn is
                Check_Unset_Reference (Pref);
             end;
 
-         --  For type conversions, qualifications, or expressions with actions,
-         --  examine the expression.
+         --  Type conversions can appear in assignment statements both
+         --  as variable names and as expressions. We examine their own
+         --  expressions only when processing their parent node.
 
-         when N_Expression_With_Actions
-            | N_Qualified_Expression
-            | N_Type_Conversion
-         =>
+         when N_Type_Conversion =>
             Check_Unset_Reference (Expression (N));
 
          --  For explicit dereference, always check prefix, which will generate