aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2019-09-19 08:12:39 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-09-19 08:12:39 +0000
commit5d66b937e3d1bbdbaace1da7bc5fac8a94793108 (patch)
tree4f2ebfa5a4a67a2c20f5e99859462cfa214adb31
parentf4437882fe972b14eb5f4163de34fa9c909b5fb6 (diff)
downloadgcc-5d66b937e3d1bbdbaace1da7bc5fac8a94793108.zip
gcc-5d66b937e3d1bbdbaace1da7bc5fac8a94793108.tar.gz
gcc-5d66b937e3d1bbdbaace1da7bc5fac8a94793108.tar.bz2
[Ada] Improve handling of explicit by-reference mechanism
This improves the handling of an explicit by-reference passing mechanism specified by means of the GNAT pragma Export_Function. This device sort of circumvents the rules of the language for the by-reference passing mechanism and it's then up to the programmer to ensure that the actual parameter is addressable; if it is not, the compiler will generate a temporary around the call, thus effectively passing the actual by copy. It turns out that the compiler was too conservative when determining whether the actual parameter is addressable, in particular if it's a component of a record type subject to a representation clause. The change effectively moves this computation from the front-end to the back-end, which has much more information on the layout and alignment of types and thus can be less conservative. 2019-09-19 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * exp_ch6.adb (Is_Legal_Copy): Also return false for an aliased formal and a formal passed by reference in convention Ada. Add missing guard to the existing test on Is_Valued_Procedure. From-SVN: r275931
-rw-r--r--gcc/ada/ChangeLog6
-rw-r--r--gcc/ada/exp_ch6.adb11
2 files changed, 14 insertions, 3 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 7b4bb47..b0fdcf9 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,9 @@
+2019-09-19 Eric Botcazou <ebotcazou@adacore.com>
+
+ * exp_ch6.adb (Is_Legal_Copy): Also return false for an aliased
+ formal and a formal passed by reference in convention Ada. Add
+ missing guard to the existing test on Is_Valued_Procedure.
+
2019-09-19 Bob Duff <duff@adacore.com>
* rtsfind.ads (RTE_Available): Improve comment.
diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index 78a1496..d3540c3 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -1859,12 +1859,16 @@ package body Exp_Ch6 is
-- An attempt to copy a value of such a type can only occur if
-- representation clauses give the actual a misaligned address.
- if Is_By_Reference_Type (Etype (Formal)) then
+ if Is_By_Reference_Type (Etype (Formal))
+ or else Is_Aliased (Formal)
+ or else (Mechanism (Formal) = By_Reference
+ and then not Has_Foreign_Convention (Subp))
+ then
-- The actual may in fact be properly aligned but there is not
-- enough front-end information to determine this. In that case
- -- gigi will emit an error if a copy is not legal, or generate
- -- the proper code.
+ -- gigi will emit an error or a warning if a copy is not legal,
+ -- or generate the proper code.
return False;
@@ -1875,6 +1879,7 @@ package body Exp_Ch6 is
-- be lurking.
elsif Mechanism (Formal) = By_Reference
+ and then Ekind (Scope (Formal)) = E_Procedure
and then Is_Valued_Procedure (Scope (Formal))
then
Error_Msg_N