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] Proper handling of meaningless size clauses


This patch fixes an internal overflow when computing the alignment of a record
component whose size is improperly specified as larger than the largest integer
value.

Compiling the following must yield:

prob.adb:6:38: warning: 4294967168 bits of "Unsigned_Integer_4" unused
prob.adb:13:45: size for "Uint4" too small, minimum allowed is 16#1000_0000_0#

---
procedure prob is
   Int_Size : constant  := 4;
   Int_Size_Bit : constant  := 4 * Standard'Storage_Unit;

   type Unsigned_Integer_4 is mod 2 ** Int_Size_Bit;
   for Unsigned_Integer_4'Size use 2 ** Int_Size_Bit;

   type Rec is record
         Uint4 : Unsigned_Integer_4;
      end record;
   for Rec use
      record
         Uint4 at 0 range 0 .. Int_Size_Bit - 1;
      end record;
begin
   null;
end;

Tested on x86_64-pc-linux-gnu, committed on trunk

2012-07-09  Ed Schonberg  <schonberg@adacore.com>

	* layout.adb (Set_Elem_Alignment): Protect against meaningless
	size clause, to prevent overflow in internal computation of
	alignment.

Attachment: difs
Description: Text document


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