[Ada] Generated name of task that is a record component

Arnaud Charlet charlet@adacore.com
Wed Jan 29 15:19:00 GMT 2014

This patch removes a spurious initialization on the string that builds the
name of task that is a record component, when Initialize_Scalars is enabled.
This is both efficient, and prevents anomalies in the handling of dynamic
objects on the secondary stack, that would result in a mangled name for such
a task.

The following commands:

   gnatmake -q -O1 p.adb

must yield:


with Alloc;
procedure P is
   Alloc.Alloc_One (1);
package Alloc is
   procedure Alloc_One (Index : Integer);
with CC; use CC;
package body Alloc is
   type Container_Pointer is access all Container;

   type Container_With_Ref_Count_Type is record
      Container : Container_Pointer;
      Ref_Count : Natural;
   end record;

   Containers : array (1 .. 3) of Container_With_Ref_Count_Type
     := (others => (null, 0));

   procedure Alloc_One (Index : Integer) is
      Where : Container_With_Ref_Count_Type renames Containers (Index);
      Where.Container := new Container;
with Ada.Task_Identification; use Ada.Task_Identification;
with Ada.Text_IO; use Ada.Text_IO;
package body CC is
   task body TT is
      Put_Line (Image (Current_Task));
      delay 1.0;
package CC is
   type Container;
   task type TT (C : not null access Container); 
   type Container is limited record
      A_TT : TT (Container'Access);
   end record;
pragma Initialize_Scalars;

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

2014-01-29  Ed Schonberg  <schonberg@adacore.com>

	* exp_util.adb (Build_Task_Image_Prefix): Indicate that the
	resulting string is an internal entity. and thus requires no
	initialization. This is relevant when Initialize_ Scalars is
	enabled, because the resultant spurious initialization may lead to
	secondary stack anomalies that produce a mangled name for a task.

-------------- next part --------------
Index: exp_util.adb
--- exp_util.adb	(revision 207241)
+++ exp_util.adb	(working copy)
@@ -1403,6 +1403,12 @@
                          Low_Bound => Make_Integer_Literal (Loc, 1),
                          High_Bound => New_Occurrence_Of (Len, Loc)))))));
+      --  Indicate that the result is an internal temporary, so it does not
+      --  receive a bogus initialization when declaration is expanded. This
+      --  is both efficient, and prevents anomalies in the handling of
+      --  dynamic objects on the secondary stack.
+      Set_Is_Internal (Res);
       Pos := Make_Temporary (Loc, 'P');
       Append_To (Decls,

More information about the Gcc-patches mailing list