aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHristian Kirtchev <kirtchev@adacore.com>2018-05-24 13:04:34 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-05-24 13:04:34 +0000
commitd72099ebf764ad96452153de8a77ab52d4731e18 (patch)
tree708a3eb0682131c904a74f560fcc3aef2a61f763
parent0b5252ac694ea0393cc9443ef2cebcab60bab40d (diff)
downloadgcc-d72099ebf764ad96452153de8a77ab52d4731e18.zip
gcc-d72099ebf764ad96452153de8a77ab52d4731e18.tar.gz
gcc-d72099ebf764ad96452153de8a77ab52d4731e18.tar.bz2
[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. From-SVN: r260645
-rw-r--r--gcc/ada/ChangeLog7
-rw-r--r--gcc/ada/freeze.adb17
2 files changed, 21 insertions, 3 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index ea9a682..c25e026 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,10 @@
+2018-05-24 Hristian Kirtchev <kirtchev@adacore.com>
+
+ * 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.
+
2018-05-24 Javier Miranda <miranda@adacore.com>
* sem_util.adb (Abstract_Interface_List): Add missing support for
diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index 1e634e1..a95a367 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -5172,13 +5172,24 @@ package body Freeze is
-- Build the call
+ -- An imported function whose result type is anonymous access
+ -- creates a new anonynous access type when it is relocated into
+ -- the declarations of the body generated below. As a result, the
+ -- accessibility level of these two anonymous access types may not
+ -- be compatible even though they are essentially the same type.
+ -- Use an unchecked type conversion to reconcile this case. Note
+ -- that the conversion is safe because in the named access type
+ -- case, both the body and imported function utilize the same
+ -- type.
+
if Ekind_In (E, E_Function, E_Generic_Function) then
Stmt :=
Make_Simple_Return_Statement (Loc,
Expression =>
- Make_Function_Call (Loc,
- Name => Make_Identifier (Loc, CE),
- Parameter_Associations => Parms));
+ Unchecked_Convert_To (Etype (E),
+ Make_Function_Call (Loc,
+ Name => Make_Identifier (Loc, CE),
+ Parameter_Associations => Parms)));
else
Stmt :=