This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Missing actual for generated initialization procedure


This patch fixes an issue whereby the use of an allocator with a
composite type containing null-excluding components may lead to a
compile time error due to incorrect code generation.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-07-04  Justin Squirek  <squirek@adacore.com>

gcc/ada/

	* exp_ch3.adb (Build_Initialization_Call): Fixup
	*_skip_null_excluding_check argument to handle new default.
	(Init_Formals): Make *_skip_null_excluding_check formal default
	to False
	* exp_ch4.adb (Expand_N_Allocator): Add comment to note heavy
	code duplication

gcc/testsuite/

	* gnat.dg/allocator.adb: New testcase.
--- gcc/ada/exp_ch3.adb
+++ gcc/ada/exp_ch3.adb
@@ -1555,23 +1555,19 @@ package body Exp_Ch3 is
 
       --  Handle the optionally generated formal *_skip_null_excluding_checks
 
-      if Needs_Conditional_Null_Excluding_Check (Full_Init_Type) then
-
-         --  Look at the associated node for the object we are referencing
-         --  and verify that we are expanding a call to an Init_Proc for an
-         --  internally generated object declaration before passing True and
-         --  skipping the relevant checks.
-
-         if Nkind (Id_Ref) in N_Has_Entity
-           and then Comes_From_Source (Associated_Node (Id_Ref))
-         then
-            Append_To (Args, New_Occurrence_Of (Standard_True, Loc));
-
-         --  Otherwise, we pass False to perform null-excluding checks
-
-         else
-            Append_To (Args, New_Occurrence_Of (Standard_False, Loc));
-         end if;
+      --  Look at the associated node for the object we are referencing and
+      --  verify that we are expanding a call to an Init_Proc for an internally
+      --  generated object declaration before passing True and skipping the
+      --  relevant checks.
+
+      if Needs_Conditional_Null_Excluding_Check (Full_Init_Type)
+        and then Nkind (Id_Ref) in N_Has_Entity
+        and then (Comes_From_Source (Id_Ref)
+                   or else (Present (Associated_Node (Id_Ref))
+                             and then Comes_From_Source
+                                        (Associated_Node (Id_Ref))))
+      then
+         Append_To (Args, New_Occurrence_Of (Standard_True, Loc));
       end if;
 
       --  Add discriminant values if discriminants are present
@@ -8695,6 +8691,7 @@ package body Exp_Ch3 is
                Make_Defining_Identifier (Loc,
                  New_External_Name (Chars
                    (Component_Type (Typ)), "_skip_null_excluding_check")),
+             Expression          => New_Occurrence_Of (Standard_False, Loc),
              In_Present          => True,
              Parameter_Type      =>
                New_Occurrence_Of (Standard_Boolean, Loc)));

--- gcc/ada/exp_ch4.adb
+++ gcc/ada/exp_ch4.adb
@@ -4751,6 +4751,9 @@ package body Exp_Ch4 is
 
          --  Case of initialization procedure present, must be called
 
+         --  NOTE: There is a *huge* amount of code duplication here from
+         --  Build_Initialization_Call. We should probably refactor???
+
          else
             Check_Restriction (No_Default_Initialization, N);
 

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/allocator.adb
@@ -0,0 +1,11 @@
+--  { dg-do compile }
+
+procedure Allocator is
+   type Object_Type      is not null access all Integer;
+   type Object_Array     is array (Positive range <>) of Object_Type;
+   type Object_Array_Ptr is access Object_Array;
+   type Data_Ptr         is access Object_Array_Ptr;
+   Copy : Data_Ptr := new Object_Array_Ptr;
+begin
+   Copy.all := new Object_Array (1..2);
+end;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]