public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] New pragma Aggregate_Individually_Assign
@ 2019-08-20  9:51 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2019-08-20  9:51 UTC (permalink / raw)
  To: gcc-patches; +Cc: Patrick Bernardi

[-- Attachment #1: Type: text/plain, Size: 2185 bytes --]

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;

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

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.

[-- Attachment #2: patch.diff.gz --]
[-- Type: application/gzip, Size: 68257 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-08-20  9:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-20  9:51 [Ada] New pragma Aggregate_Individually_Assign Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).