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 No_Standard_Allocators_After_Elaboration


This implements the final definition of the Ada 2012 restriction
No_Standard_Allocators_After_Elaboration. There are two static
cases. First appearence in task body, this one we already had
before (compiled with -gnatj55 -gnatld7)

     1. procedure Pmain2 is
     2.    type P is access all Integer;
     3.    PV : P;
     4.    task X;
     5.    task body X is
     6.    begin
     7.       PV := new Integer;
                    |
        >>> violation of restriction
            "No_Standard_Allocators_After_Elaboration"
            at gnat.adc:1

     8.    end;
     9. begin
    10.    null;
    11. end;

Second, also a static case, appearence in a parameterless
library level procedure (same switches)

     1. procedure Pmain is
     2.    type R is access all Integer;
     3.    RV : R;
     4. begin
     5.    RV := new Integer;
                 |
        >>> violation of restriction
            "No_Standard_Allocators_After_Elaboration"
            at gnat.adc:1

     6. end;

Finally the dynamic case tested at run-time:

     1. with Allocate_After_Elab;
     2. procedure Allocate_After_Elab_Test is
     3. begin
     4.    Allocate_After_Elab (42);
     5. end Allocate_After_Elab_Test;

     1. with Ada.Text_IO;
     2. procedure Allocate_After_Elab (X : Integer) is
     3.    type Int_Ptr_Type is access Integer;
     4.    My_Int_Ptr : Int_Ptr_Type;
     5. begin
     6.    My_Int_Ptr := new Integer'(X);
     7.    Ada.Text_IO.Put_Line ("Have used allocator");
     8. end Allocate_After_Elab;

If we run Allocate_After_Elab_Test, we get:

raised PROGRAM_ERROR : standard allocator after elaboration is complete is not allowed
(No_Standard_Allocators_After_Elaboration restriction active)

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

2014-07-18  Robert Dewar  <dewar@adacore.com>

	* gcc-interface/Make-lang.in: Add entry for s-elaall.o
	* bcheck.adb (Check_Consistent_Restrictions):
	Remove obsolete code checking for violation of
	No_Standard_Allocators_After_Elaboration (main program)
	* bindgen.adb (Gen_Adainit): Handle
	No_Standard_Allocators_After_Elaboration
	(Gen_Output_File_Ada): ditto.
	* exp_ch4.adb (Expand_N_Allocator): Handle
	No_Standard_Allocators_After_Elaboration.
	* Makefile.rtl: Add entry for s-elaall
	* rtsfind.ads: Add entry for Check_Standard_Allocator.
	* s-elaall.ads, s-elaall.adb: New files.
	* sem_ch4.adb (Analyze_Allocator): Handle
	No_Standard_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]