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] Implement restriction No_Allocators_After_Elaboration


This patch implements AI 0189, which introduces a new restriction
No_Allocators_After_Elaboration. We do not implement any attempt
at run-time checks, but we perform the required static checks if
the restriction is active (no allocators in main program body,
and no allocators in task bodies).

The following program:

pragma Restrictions (No_Allocators_After_Elaboration);
with NAAE_Tasks;
procedure NAAE_Main is
   type R is access all Integer;
   B : R := new Integer'(12);  -- OK
   C : R;
begin
   C := new Integer'(12); -- FLAGGED BY BINDER
end;

package NAAE_Tasks is
   task type R;
end NAAE_Tasks;

pragma Restrictions (No_Allocators_After_Elaboration);
with NAAE_Tasks;
procedure NAAE_Main is
   type R is access all Integer;
   B : R := new Integer'(12);  -- OK
   C : R;
begin
   C := new Integer'(12); -- FLAGGED BY BINDER
end;

compiles without errors, but the binder complains about the
violations of the restriction as follows:

error: "naae_main.adb" has restriction No_Allocators_After_Elaboration
error: but the following files violate this restriction:
error:   "naae_tasks.adb"

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

2010-10-08  Robert Dewar  <dewar@adacore.com>

	* ali.adb: Set Allocator_In_Body if AB parameter present on M line
	* ali.ads (Allocator_In_Body): New flag
	* bcheck.adb (Check_Consistent_Restrictions): Handle case of main
	program violating No_Allocators_After_Elaboration restriction.
	* gnatbind.adb (No_Restriction_List): Add entries for
	No_Anonymous_Allocators, and No_Allocators_After_Elaboration.
	* lib-load.adb: Initialize Has_Allocator flag
	* lib-writ.adb: Initialize Has_Allocator flag
	(M_Parameters): Set AB switch if Has_Allocator flag set
	* lib-writ.ads: Document AB flag on M line
	* lib.adb (Has_Allocator): New function
	(Set_Has_Allocator): New procedure
	* lib.ads (Has_Allocator): New function
	(Set_Has_Allocator): New procedure
	(Has_Allocator): New flag in Unit_Record
	* sem_ch4.adb (Analyze_Allocator): Add processing for
	No_Allocators_After_Elaboration.

Attachment: difs
Description: Text document


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