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

[Ada] Fix alignment warning on aliased formal parameter


This eliminates the alignment warning wrongly issued on an address clause 
applied to a formal parameter, even though the type of the parameter has the 
appropriate alignment clause.

Tested on x86_64-suse-linux, applied on the mainline.


2015-02-08  Eric Botcazou  <ebotcazou@adacore.com>

	* 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  <ebotcazou@adacore.com>

	* gnat.dg/addr7.ad[sb]: New test.
	* gnat.dg/addr8.ad[sb]: Likewise.


-- 
Eric Botcazou
Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 220512)
+++ gcc-interface/decl.c	(working copy)
@@ -5659,15 +5659,17 @@ gnat_to_gnu_param (Entity_Id gnat_param,
     }
 
   /* 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;
     }
 
-- { 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;
package Addr7 is

   type Bytes is array (1 .. 4) of Character;
   for Bytes'Alignment use 4;

   procedure Proc (B: aliased Bytes);

end Addr7;
-- { 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;
package Addr8 is

   type Bytes is array (1 .. 4) of Character;
   for Bytes'Alignment use 4;

   procedure Proc (B: Bytes);

end Addr8;

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