Commit efc00a88 by Patrick Bernardi Committed by Pierre-Marie de Rodat

[Ada] New pragma Aggregate_Individually_Assign

Where possible GNAT will store the binary representation of a record
aggregate in memory for space and performance reasons. This
configuration pragma changes this behaviour so that record aggregates
are instead always converted into individual assignment statements.

The following package pack.ads:

-- pack.ads

pragma Aggregate_Individually_Assign;
pragma Restrictions (No_Multiple_Elaboration);

package Pack is
   type A_Rec is record
      A, B, C, D : Boolean;
   end record;

   A : A_Rec := (True, False, True, True);
end Pack;

when compiled with

gcc -c -gnatdg pack.ads

should produce the following output:

Source recreated from tree for Pack (spec)
------------------------------------------

pragma aggregate_individually_assign;
pragma restrictions (no_multiple_elaboration);

package pack is
   type pack__a_rec is record
      a : boolean;
      b : boolean;
      c : boolean;
      d : boolean;
   end record;
   freeze pack__a_rec [
      procedure pack__a_recIP (_init : out pack__a_rec) is
      begin
         %push_constraint_error_label ()
         %push_program_error_label ()
         %push_storage_error_label ()
         null;
         %pop_constraint_error_label
         %pop_program_error_label
         %pop_storage_error_label
         return;
      end pack__a_recIP;
   ]
   pack__a : pack__a_rec := (
      a => true,
      b => false,
      c => true,
      d => true);
   pack__a.a := true;
   pack__a.b := false;
   pack__a.c := true;
   pack__a.d := true;
   null;
end pack;

2019-08-20  Patrick Bernardi  <bernardi@adacore.com>

gcc/ada/

	* exp_aggr.adb (Expand_Record_Aggregate): Always convert a
	record Aggregate to assignment statements if the option
	Aggregate_Individually_Assign is set.
	* opt.ads (Aggregate_Individually_Assign): New option.
	* par-prag.adb (Prag): Add Pragma_Aggregate_Individually_Assign.
	* sem_prag.adb (Analyze_Pragma): Likewise.
	* snames.ads-tmpl: Add Pragma_Aggregate_Individually_Assign and
	Name_Aggregate_Individually_Assign.
	* doc/gnat_rm/implementation_defined_pragmas.rst: Document
	pragma Aggregate_Individually_Assign.
	* gnat_rm.texi: Regenerate.

From-SVN: r274730
parent 32501d71
2019-08-20 Patrick Bernardi <bernardi@adacore.com>
* exp_aggr.adb (Expand_Record_Aggregate): Always convert a
record Aggregate to assignment statements if the option
Aggregate_Individually_Assign is set.
* opt.ads (Aggregate_Individually_Assign): New option.
* par-prag.adb (Prag): Add Pragma_Aggregate_Individually_Assign.
* sem_prag.adb (Analyze_Pragma): Likewise.
* snames.ads-tmpl: Add Pragma_Aggregate_Individually_Assign and
Name_Aggregate_Individually_Assign.
* doc/gnat_rm/implementation_defined_pragmas.rst: Document
pragma Aggregate_Individually_Assign.
* gnat_rm.texi: Regenerate.
2019-08-20 Bob Duff <duff@adacore.com>
* par-ch4.adb: Minor wording change in error messages.
......
......@@ -371,6 +371,21 @@ Syntax:
This configuration pragma is a synonym for pragma Ada_12 and has the
same syntax and effect.
Pragma Aggregate_Individually_Assign
====================================
Syntax:
.. code-block:: ada
pragma Aggregate_Individually_Assign;
Where possible GNAT will store the binary representation of a record aggregate
in memory for space and performance reasons. This configuration pragma changes
this behaviour so that record aggregates are instead always converted into
individual assignment statements.
Pragma Allow_Integer_Address
============================
......
......@@ -7478,6 +7478,12 @@ package body Exp_Aggr is
return;
end if;
-- If the pramga Aggregate_Individually_Assign is set always convert to
-- assignments.
if Aggregate_Individually_Assign then
Convert_To_Assignments (N, Typ);
-- Ada 2005 (AI-318-2): We need to convert to assignments if components
-- are build-in-place function calls. The assignments will each turn
-- into a build-in-place function call. If components are all static,
......@@ -7486,7 +7492,7 @@ package body Exp_Aggr is
-- Extension aggregates, aggregates in extended return statements, and
-- aggregates for C++ imported types must be expanded.
if Ada_Version >= Ada_2005 and then Is_Limited_View (Typ) then
elsif Ada_Version >= Ada_2005 and then Is_Limited_View (Typ) then
if not Nkind_In (Parent (N), N_Component_Association,
N_Object_Declaration)
then
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -191,6 +191,11 @@ package Opt is
-- GNAT, GNATBIND
-- Set True if package System has the line "type Address is private;"
Aggregate_Individually_Assign : Boolean := False;
-- GNAT
-- Set True if record aggregates are to be always converted into assignment
-- statements. Set through the corresponding pragma.
All_Errors_Mode : Boolean := False;
-- GNAT
-- Flag set to force display of multiple errors on a single line and
......
......@@ -1319,6 +1319,7 @@ begin
| Pragma_Acc_Kernels
| Pragma_Acc_Loop
| Pragma_Acc_Parallel
| Pragma_Aggregate_Individually_Assign
| Pragma_Async_Readers
| Pragma_Async_Writers
| Pragma_Assertion_Policy
......
......@@ -12979,6 +12979,18 @@ package body Sem_Prag is
Ada_Version_Explicit := Ada_2020;
Ada_Version_Pragma := N;
-------------------------------------
-- Aggregate_Individually_Assign --
-------------------------------------
-- pragma Aggregate_Individually_Assign;
when Pragma_Aggregate_Individually_Assign =>
GNAT_Pragma;
Check_Arg_Count (0);
Check_Valid_Configuration_Pragma;
Aggregate_Individually_Assign := True;
----------------------
-- All_Calls_Remote --
----------------------
......@@ -30890,6 +30902,7 @@ package body Sem_Prag is
Pragma_Ada_12 => -1,
Pragma_Ada_2012 => -1,
Pragma_Ada_2020 => -1,
Pragma_Aggregate_Individually_Assign => 0,
Pragma_All_Calls_Remote => -1,
Pragma_Allow_Integer_Address => -1,
Pragma_Annotate => 93,
......@@ -389,6 +389,7 @@ package Snames is
Name_Ada_12 : constant Name_Id := N + $; -- GNAT
Name_Ada_2012 : constant Name_Id := N + $; -- GNAT
Name_Ada_2020 : constant Name_Id := N + $; -- GNAT
Name_Aggregate_Individually_Assign : constant Name_Id := N + $; -- GNAT
Name_Allow_Integer_Address : constant Name_Id := N + $; -- GNAT
Name_Annotate : constant Name_Id := N + $; -- GNAT
Name_Assertion_Policy : constant Name_Id := N + $; -- Ada 05
......@@ -1847,6 +1848,7 @@ package Snames is
Pragma_Ada_2020,
-- Note that there is no Pragma_Ada_20. Pragma_Ada_05/12 are for
-- compatibility reasons only; the full year names are preferred.
Pragma_Aggregate_Individually_Assign,
Pragma_Allow_Integer_Address,
Pragma_Annotate,
Pragma_Assertion_Policy,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment