aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2009-10-02 19:10:40 +0000
committerEric Botcazou <ebotcazou@gcc.gnu.org>2009-10-02 19:10:40 +0000
commitc2ce8cdc82051800c389c16725365e91986f89c5 (patch)
tree63e22ba3f204afbed0e53ba188e4962beac2933a /gcc
parent7d45fb9420c0d23774e3e34730cd6d847d78a90a (diff)
downloadgcc-c2ce8cdc82051800c389c16725365e91986f89c5.zip
gcc-c2ce8cdc82051800c389c16725365e91986f89c5.tar.gz
gcc-c2ce8cdc82051800c389c16725365e91986f89c5.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/stor-layout.c19
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gnat.dg/array10.adb25
-rw-r--r--gcc/testsuite/gnat.dg/object_overflow.adb7
5 files changed, 51 insertions, 10 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f16eff0..a118f8c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index f34f2ab..5967fb5 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -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,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index dcd5114..9245417 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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.
diff --git a/gcc/testsuite/gnat.dg/array10.adb b/gcc/testsuite/gnat.dg/array10.adb
new file mode 100644
index 0000000..37ee8ff
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/array10.adb
@@ -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;
diff --git a/gcc/testsuite/gnat.dg/object_overflow.adb b/gcc/testsuite/gnat.dg/object_overflow.adb
index 820e936..597b796 100644
--- a/gcc/testsuite/gnat.dg/object_overflow.adb
+++ b/gcc/testsuite/gnat.dg/object_overflow.adb
@@ -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;