This is the mail archive of the gcc-cvs@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]

r260645 - in /trunk/gcc/ada: ChangeLog freeze.adb


Author: pmderodat
Date: Thu May 24 13:04:34 2018
New Revision: 260645

URL: https://gcc.gnu.org/viewcvs?rev=260645&root=gcc&view=rev
Log:
[Ada] Spurious error on imported subprogram with precondition

This patch modifies the generation of wrappers for imported subprograms which
are subject to contracts. In the case of an imported function, the original
function is relocated within the wrapper, and the wrapper simply invokes the
imported subprogram, returning its value. When the result type of the imported
subprogram is anonymous access, the relocation creates a new anonymous access
type, but with a different accessibility level. Since both return types are
essentially the same type, eliminate the accessibility level inconsistency by
unchecked converting the result of calling the imported function to the return
type.

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

--  pack.ads

package Pack is
   type Integer_Ptr is access all Integer;
   type Typ is null record;

   function Predicate (Val : Typ) return Boolean is (True);

   function Imported_1 (Val : Typ) return access Integer
     with Pre => Predicate (Val), Import;

   function Imported_2 (Val : Typ) return Integer_Ptr
     with Pre => Predicate (Val), Import;
end Pack;

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

$ gcc -c pack.ads

2018-05-24  Hristian Kirtchev  <kirtchev@adacore.com>

gcc/ada/

	* freeze.adb (Wrap_Imported_Subprogram): Generate an unchecked
	conversion to the return type to avoid a side effect where an imported
	relocated function generates a new anonymous access type, whose
	accessibility level does not agree with with that of the wrapper.

Modified:
    trunk/gcc/ada/ChangeLog
    trunk/gcc/ada/freeze.adb


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