stor-layout.c (layout_type): Make sure that an array of zero-sized element is zero-sized regardless of its...

* stor-layout.c (layout_type) <ARRAY_TYPE>: Make sure that an array
	of zero-sized element is zero-sized regardless of its extent.

From-SVN: r152415
This commit is contained in:
Eric Botcazou 2009-10-02 19:10:40 +00:00 committed by Eric Botcazou
parent 7d45fb9420
commit c2ce8cdc82
5 changed files with 51 additions and 10 deletions

View File

@ -1,3 +1,8 @@
2009-10-02 Eric Botcazou <ebotcazou@adacore.com>
* stor-layout.c (layout_type) <ARRAY_TYPE>: Make sure that an array
of zero-sized element is zero-sized regardless of its extent.
2009-10-02 Jakub Jelinek <jakub@redhat.com>
PR debug/40521

View File

@ -1959,14 +1959,21 @@ layout_type (tree type)
tree element_size = TYPE_SIZE (element);
tree length;
/* Make sure that an array of zero-sized element is zero-sized
regardless of its extent. */
if (integer_zerop (element_size))
length = size_zero_node;
/* The initial subtraction should happen in the original type so
that (possible) negative values are handled appropriately. */
length = size_binop (PLUS_EXPR, size_one_node,
fold_convert (sizetype,
fold_build2_loc (input_location,
MINUS_EXPR,
TREE_TYPE (lb),
ub, lb)));
else
length
= size_binop (PLUS_EXPR, size_one_node,
fold_convert (sizetype,
fold_build2_loc (input_location,
MINUS_EXPR,
TREE_TYPE (lb),
ub, lb)));
TYPE_SIZE (type) = size_binop (MULT_EXPR, element_size,
fold_convert (bitsizetype,

View File

@ -1,3 +1,8 @@
2009-10-02 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/array10.adb: New test.
* gnat.dg/object_overflow.adb: Tweak.
2009-10-02 Jack Howarth <howarth@bromo.med.uc.edu>
* gcc.dg/guality/guality.exp: Disable on darwin.

View File

@ -0,0 +1,25 @@
-- { dg-do run }
-- Verify that an array of non-aliased zero-sized element is zero-sized
procedure Array10 is
type Rec is null record;
type Arr1 is array (1..8) of Rec;
type Arr2 is array (Long_Integer) of Rec;
R : Rec;
A1 : Arr1;
A2 : Arr2;
begin
if Rec'Size /= 0 then
raise Program_Error;
end if;
if Arr1'Size /= 0 then
raise Program_Error;
end if;
if Arr2'Size /= 0 then
raise Program_Error;
end if;
end;

View File

@ -2,13 +2,12 @@
procedure Object_Overflow is
type Rec is null record;
procedure Proc (x : Boolean) is begin null; end;
procedure Proc (x : Rec) is begin null; end;
type Arr is array(Long_Integer) of Rec;
type Arr is array(Long_Integer) of Boolean;
Obj : Arr; -- { dg-warning "Storage_Error will be raised" }
begin
Obj(1) := True;
Proc (Obj(1));
end;