]> gcc.gnu.org Git - gcc.git/commitdiff
ada: Follow-up adjustment after fix to Default_Initialize_Object
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 12 Feb 2024 18:25:39 +0000 (19:25 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 14 May 2024 08:19:54 +0000 (10:19 +0200)
Now that Default_Initialize_Object honors the No_Initialization flag in all
cases, objects of an access type declared without initialization expression
can no longer be considered as being automatically initialized to null.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): Examine the Expression
field after the call to Default_Initialize_Object in order to set
Is_Known_Null, as well as Is_Known_Non_Null, on an access object.

gcc/ada/exp_ch3.adb

index e34cb8fb58f622f3c0f7415cef201a465b82fe30..9109d592690588c6f492445b7e1bd18a585b6400 100644 (file)
@@ -7604,6 +7604,16 @@ package body Exp_Ch3 is
 
          if not Special_Ret_Obj then
             Default_Initialize_Object (Init_After);
+
+            --  Check whether an access object has been initialized above
+
+            if Is_Access_Type (Typ) and then Present (Expression (N)) then
+               if Known_Non_Null (Expression (N)) then
+                  Set_Is_Known_Non_Null (Def_Id);
+               elsif Known_Null (Expression (N)) then
+                  Set_Is_Known_Null (Def_Id);
+               end if;
+            end if;
          end if;
 
          --  Generate attribute for Persistent_BSS if needed
@@ -7625,12 +7635,6 @@ package body Exp_Ch3 is
             end;
          end if;
 
-         --  If access type, then we know it is null if not initialized
-
-         if Is_Access_Type (Typ) then
-            Set_Is_Known_Null (Def_Id);
-         end if;
-
       --  Explicit initialization present
 
       else
This page took 0.074805 seconds and 5 git commands to generate.