r263719 - in /trunk/gcc/ada: ChangeLog exp_aggr...

pmderodat@gcc.gnu.org pmderodat@gcc.gnu.org
Tue Aug 21 14:46:00 GMT 2018


Author: pmderodat
Date: Tue Aug 21 14:46:49 2018
New Revision: 263719

URL: https://gcc.gnu.org/viewcvs?rev=263719&root=gcc&view=rev
Log:
[Ada] Improper copying of limited arrays with default initialization

This patch fixes an improper expansion of aggregates for limited array
types in an object declaration. Prior to this patch, The presence of the
aggregate (which can only consist of box initializations) would create a
temporary that was then assigned to the object in the declaration.
Apart from a violation of the semantics of build-in-place limited
objects, this can also lead to out-of-scope access in LLVM.

Executing the following;

   gcc -c -gnatDG nocopy.adb
   grep quintet nocopy.adb.dg | wc -l

must yield:

   5

----
procedure NoCopy is

  --  Task used in this example to test that the limited component
  --  is properly initialized.

  task type T_Task (Disc : Natural);

  task body T_Task is
  begin
     null;
  end T_Task;

  type My_Rec (D : Natural := 9999) is record

     --  Components initialized by means of the current value
     --  of the record discriminant

     T : T_Task (D);
  end record;

  type TR is array (1 .. 5) of My_Rec;
  Quintet : TR := (others => (others => <>));
begin
   null;
end NoCopy;

2018-08-21  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* exp_aggr.adb (Expand_Array_Aggregate): If the component type
	is limited, the array must be constructed in place, so set flag
	In_Place_Assign_OK_For_Declaration accordingly. This prevents
	improper copying of an array of tasks during initialization.

Modified:
    trunk/gcc/ada/ChangeLog
    trunk/gcc/ada/exp_aggr.adb



More information about the Gcc-cvs mailing list