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]

Fix PR ada/22418


As described in exp_dbug.ads, gigi creates internal objects with an _XVZ
suffix to store the size of some component types when it is variable.
The stored expression represents the size in bits, and the created variable
was assigned a sizetype instead of a bitsizetype, leading to various possible
compiler crashes or run-time memory overruns. The fix is to adjust the type
of the created variable to match the type of the expression assigned to it.

Bootstrapped/regtested on i586-suse-linux, applied to mainline and 4.0 branch 
as obvious.

As a testcase, the code below should compile and run silently:

procedure XVZ is

   subtype Range_T is Positive range 1..5;

   type Bound_T is record
      Value : Range_T := 2;
   end record;

   Bound : Bound_T;

   type Line_Width_T is new Natural range 0 .. Bound.Value;

   type Int_Line_T is array (Line_Width_T range <>) of Integer;

   type Matrix_Line_T (Max_Size : Line_Width_T := 1) is record
      Values : Int_Line_T (1 .. Max_Size);
   end record;

   type Matrix_Height_T is new Natural range 0 .. 2;
   type Matrix_Array_T is array (Matrix_Height_T range <>) of Matrix_Line_T;

   type Matrix_T (Height : Matrix_Height_T) is record
      Lines : Matrix_Array_T (1 .. Height);
   end record;

begin
   null;
end;


2005-09-21  Olivier Hainque  <hainque@adacore.com>

	PR ada/22418
	* decl.c (maybe_pad_type): Use proper bitsizetype for XVZ objects,
	as we create them to store a size in bits.


-- 
Eric Botcazou
Index: decl.c
===================================================================
RCS file: /gnat.dev/cvs/Dev/gnat/decl.c,v
retrieving revision 1.63.2.122
retrieving revision 1.63.2.123
diff -u -p -r1.63.2.122 -r1.63.2.123
--- decl.c	29 Aug 2005 10:48:01 -0000	1.63.2.122
+++ decl.c	6 Sep 2005 14:12:50 -0000	1.63.2.123
@@ -4985,7 +4985,7 @@ maybe_pad_type (tree type, tree size, un
 
       if (size && TREE_CODE (size) != INTEGER_CST && definition)
 	create_var_decl (concat_id_with_name (name, "XVZ"), NULL_TREE,
-			 sizetype, TYPE_SIZE (record), false, false, false,
+			 bitsizetype, TYPE_SIZE (record), false, false, false,
 			 false, NULL, gnat_entity);
     }
 

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