From 57f4f0d5f662eec0aa38ac0f554262ce072a8eeb Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Sun, 8 Feb 2015 10:12:38 +0000 Subject: [PATCH] decl.c (gnat_to_gnu_param): Do not strip the padding if the parameter either is passed by reference or if... * gcc-interface/decl.c (gnat_to_gnu_param): Do not strip the padding if the parameter either is passed by reference or if the alignment would be lowered. From-SVN: r220514 --- gcc/ada/ChangeLog | 6 ++++++ gcc/ada/gcc-interface/decl.c | 10 ++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gnat.dg/addr7.adb | 12 ++++++++++++ gcc/testsuite/gnat.dg/addr7.ads | 8 ++++++++ gcc/testsuite/gnat.dg/addr8.adb | 12 ++++++++++++ gcc/testsuite/gnat.dg/addr8.ads | 8 ++++++++ 7 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/addr7.adb create mode 100644 gcc/testsuite/gnat.dg/addr7.ads create mode 100644 gcc/testsuite/gnat.dg/addr8.adb create mode 100644 gcc/testsuite/gnat.dg/addr8.ads diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 59c6c3886eb..874779e44ea 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2015-02-08 Eric Botcazou + + * gcc-interface/decl.c (gnat_to_gnu_param): Do not strip the padding + if the parameter either is passed by reference or if the alignment + would be lowered. + 2015-02-08 Eric Botcazou * gcc-interface/decl.c (is_cplusplus_method): Use Is_Primitive flag to diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index c7d64aab449..94043b6a397 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -5659,15 +5659,17 @@ gnat_to_gnu_param (Entity_Id gnat_param, Mechanism_Type mech, } /* If this is either a foreign function or if the underlying type won't - be passed by reference, strip off possible padding type. */ + be passed by reference and is as aligned as the original type, strip + off possible padding type. */ if (TYPE_IS_PADDING_P (gnu_param_type)) { tree unpadded_type = TREE_TYPE (TYPE_FIELDS (gnu_param_type)); - if (mech == By_Reference - || foreign + if (foreign || (!must_pass_by_ref (unpadded_type) - && (mech == By_Copy || !default_pass_by_ref (unpadded_type)))) + && mech != By_Reference + && (mech == By_Copy || !default_pass_by_ref (unpadded_type)) + && TYPE_ALIGN (unpadded_type) >= TYPE_ALIGN (gnu_param_type))) gnu_param_type = unpadded_type; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dbe52cf0fd6..878338960ce 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-02-08 Eric Botcazou + + * gnat.dg/addr7.ad[sb]: New test. + * gnat.dg/addr8.ad[sb]: Likewise. + 2015-02-06 David Malcolm PR jit/64752 diff --git a/gcc/testsuite/gnat.dg/addr7.adb b/gcc/testsuite/gnat.dg/addr7.adb new file mode 100644 index 00000000000..982b50e3a1a --- /dev/null +++ b/gcc/testsuite/gnat.dg/addr7.adb @@ -0,0 +1,12 @@ +-- { dg-do compile } + +package body Addr7 is + + procedure Proc (B: aliased Bytes) is + O: Integer; + for O'Address use B'Address; + begin + null; + end; + +end Addr7; diff --git a/gcc/testsuite/gnat.dg/addr7.ads b/gcc/testsuite/gnat.dg/addr7.ads new file mode 100644 index 00000000000..19fbb0ea90c --- /dev/null +++ b/gcc/testsuite/gnat.dg/addr7.ads @@ -0,0 +1,8 @@ +package Addr7 is + + type Bytes is array (1 .. 4) of Character; + for Bytes'Alignment use 4; + + procedure Proc (B: aliased Bytes); + +end Addr7; diff --git a/gcc/testsuite/gnat.dg/addr8.adb b/gcc/testsuite/gnat.dg/addr8.adb new file mode 100644 index 00000000000..9105c22f77f --- /dev/null +++ b/gcc/testsuite/gnat.dg/addr8.adb @@ -0,0 +1,12 @@ +-- { dg-do compile } + +package body Addr8 is + + procedure Proc (B: Bytes) is + O: Integer; + for O'Address use B'Address; + begin + null; + end; + +end Addr8; diff --git a/gcc/testsuite/gnat.dg/addr8.ads b/gcc/testsuite/gnat.dg/addr8.ads new file mode 100644 index 00000000000..ab648e123c0 --- /dev/null +++ b/gcc/testsuite/gnat.dg/addr8.ads @@ -0,0 +1,8 @@ +package Addr8 is + + type Bytes is array (1 .. 4) of Character; + for Bytes'Alignment use 4; + + procedure Proc (B: Bytes); + +end Addr8; -- 2.30.2