r273130 - in /trunk/gcc/ada: ChangeLog checks.a...

pmderodat@gcc.gnu.org pmderodat@gcc.gnu.org
Fri Jul 5 07:03:00 GMT 2019


Author: pmderodat
Date: Fri Jul  5 07:03:58 2019
New Revision: 273130

URL: https://gcc.gnu.org/viewcvs?rev=273130&root=gcc&view=rev
Log:
[Ada] Incorrect accessibility check

This patch fixes an issue whereby anonymous access result types were
treated as having the same accessibility level as typed results instead
of having the level determined by the "master of the call" as per RM
3.10.2 (10).

------------
-- Source --
------------

--  main.adb

with Pack_12; use Pack_12;
with Pack_05; use Pack_05;

procedure Main is
   Obj : aliased Integer;
begin
   Test_Alloc
     (new Rec_T'(Disc => Id_A (Obj'Access))); --  OK

   Id_A (Obj'Access).all := 0;                --  OK
   Id_B (Obj'Access).all := 0;                --  OK
   Id_C (Obj'Access).all := 0;                --  ERROR
end Main;

--  pack_12.ads

pragma Ada_2012;

with Ada.Unchecked_Conversion;

package Pack_12 is
   function Id_A (I : access Integer)
     return access Integer
     is (I);

   type Obj_Ptr is access all Integer;

   function Id_C (I : access Integer)
     return Obj_Ptr
     is (I.all'Access);

   type Rec_T (Disc : access Integer) is null record;

   procedure Test_Alloc (Access_Param : access Rec_T);
end Pack_12;

--  pack_12.adb

package body Pack_12 is
   Dummy : Integer;

   procedure Test_Alloc (Access_Param : access Rec_T) is
   begin
      Dummy := Access_Param.Disc.all;
   end Test_Alloc;
end Pack_12;

--  pack_05.ads

pragma Ada_2005;

with Pack_12; use Pack_12;

package Pack_05 is
   function Id_B (I : access Integer)
     return access Integer
     renames Id_A;
end Pack_05;

-----------------
-- Compilation --
-----------------

$ gnatmake -q main.adb
$ main
raised PROGRAM_ERROR : pack_12.ads:14 accessibility check failed

2019-07-05  Justin Squirek  <squirek@adacore.com>

gcc/ada/

	* checks.adb (Apply_Accessibility_Check): Add logic to fetch the
	function result accessibility level if one is required within
	the generated check.
	* exp_ch6.adb (Needs_Result_Accessibility_Level): Modify
	controlling elsif block to handle more cases such as anonymous
	access results and disable checking for coextensions.

Modified:
    trunk/gcc/ada/ChangeLog
    trunk/gcc/ada/checks.adb
    trunk/gcc/ada/exp_ch6.adb



More information about the Gcc-cvs mailing list