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 ICE on address clause


This patch fixes an ICE on an assignment of an object with both an alignment 
clause and an address clause.  This doesn't make much sense, at least with 
the implementation we have, so the alignment clause is effectively ditched.


2009-05-23  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/decl.c (gnat_to_gnu_entity) <object>: Do not modify the
	original type because of the alignment when there is an address clause.


2009-05-23  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/addr6.adb: New test.


-- 
Eric Botcazou
Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 147814)
+++ gcc-interface/decl.c	(working copy)
@@ -608,17 +608,22 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 	    return error_mark_node;
 	  }
 
-	/* If an alignment is specified, use it if valid.   Note that
-	   exceptions are objects but don't have alignments.  We must do this
-	   before we validate the size, since the alignment can affect the
-	   size.  */
+	/* If an alignment is specified, use it if valid.  Note that exceptions
+	   are objects but don't have an alignment.  We must do this before we
+	   validate the size, since the alignment can affect the size.  */
 	if (kind != E_Exception && Known_Alignment (gnat_entity))
 	  {
 	    gcc_assert (Present (Alignment (gnat_entity)));
 	    align = validate_alignment (Alignment (gnat_entity), gnat_entity,
 					TYPE_ALIGN (gnu_type));
-	    gnu_type = maybe_pad_type (gnu_type, NULL_TREE, align, gnat_entity,
-				       "PAD", false, definition, true);
+	    /* No point in changing the type if there is an address clause
+	       as the final type of the object will be a reference type.  */
+	    if (Present (Address_Clause (gnat_entity)))
+	      align = 0;
+	    else
+	      gnu_type
+		= maybe_pad_type (gnu_type, NULL_TREE, align, gnat_entity,
+				  "PAD", false, definition, true);
 	  }
 
 	/* If we are defining the object, see if it has a Size value and
-- { dg-do compile }

procedure Addr6 is

   type Byte is mod 2**8;

   type Byte_Arr1 is array (Positive range <>) of Byte;
   for Byte_Arr1'Alignment use 4;

   type Byte_Arr2 is array (Positive range <>) of Byte;

   function Length return Natural is
   begin
     return 1;
   end;

   function Empty return Byte_Arr2 is
     Null_Arr : Byte_Arr2 (1 .. 0);
   begin
     return Null_Arr;
   end;

   A1 : Byte_Arr1 (1 .. Length);

   A2 : Byte_Arr2 (A1'Range);
   for A2'Alignment use 4;
   for A2'Address use A1'Address;

begin
   A2 := Empty;
end;

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