* stor-layout.c (layout_type) <ARRAY_TYPE>: Make sure that an array
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 2 Oct 2009 19:10:40 +0000 (19:10 +0000)
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 2 Oct 2009 19:10:40 +0000 (19:10 +0000)
of zero-sized element is zero-sized regardless of its extent.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@152415 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/stor-layout.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/array10.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/object_overflow.adb

index f16eff0..a118f8c 100644 (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
index f34f2ab..5967fb5 100644 (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,
index dcd5114..9245417 100644 (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.
diff --git a/gcc/testsuite/gnat.dg/array10.adb b/gcc/testsuite/gnat.dg/array10.adb
new file mode 100644 (file)
index 0000000..37ee8ff
--- /dev/null
@@ -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;
index 820e936..597b796 100644 (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;