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:
parent
7d45fb9420
commit
c2ce8cdc82
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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.
|
||||
|
25
gcc/testsuite/gnat.dg/array10.adb
Normal file
25
gcc/testsuite/gnat.dg/array10.adb
Normal 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;
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user