stor-layout.c (layout_type): Handle arrays of bits, for Chill.
authorDave Brolley <brolley@cygnus.com>
Mon, 27 Jul 1998 14:37:00 +0000 (14:37 +0000)
committerDave Brolley <brolley@gcc.gnu.org>
Mon, 27 Jul 1998 14:37:00 +0000 (10:37 -0400)
Mon Jul 27 17:18:52 1998  Dave Brolley  <brolley@cygnus.com>
* stor-layout.c (layout_type): Handle arrays of bits, for Chill.
* expr.c (get_inner_reference): Handle zero-based, unsigned, array
index conversion.

From-SVN: r21416

gcc/ChangeLog
gcc/expr.c
gcc/stor-layout.c

index 37fc76e1180aa7c3c57d4c65a5507d2ad2b7e77a..964849e1c3c7a9bae2268fa5bcd76ae37de3d6c2 100644 (file)
@@ -1,3 +1,10 @@
+Mon Jul 27 17:18:52 1998  Dave Brolley  <brolley@cygnus.com>
+
+       * stor-layout.c (layout_type): Handle arrays of bits, for Chill.
+
+       * expr.c (get_inner_reference): Handle zero-based, unsigned, array
+       index conversion.
+
 Mon Jul 27 14:51:33 1998  Jeffrey A Law  (law@cygnus.com)
 
        * mn10300.h (DEBUGGER_AUTO_OFFSET): Define.
index fd43689724be5547822955188ce59ee1410187fe..208db5cb2d871cea3f1c330edf0398d45fdf8677 100644 (file)
@@ -4546,8 +4546,20 @@ get_inner_reference (exp, pbitsize, pbitpos, poffset, pmode,
              index_type = TREE_TYPE (index);
            }
 
+         /* Optimize the special-case of a zero lower bound.
+            
+            We convert the low_bound to sizetype to avoid some problems
+            with constant folding.  (E.g. suppose the lower bound is 1,
+            and its mode is QI.  Without the conversion,  (ARRAY
+            +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
+            +INDEX), which becomes (ARRAY+255+INDEX).  Oops!)
+            
+            But sizetype isn't quite right either (especially if
+            the lowbound is negative).  FIXME */
+
          if (! integer_zerop (low_bound))
-           index = fold (build (MINUS_EXPR, index_type, index, low_bound));
+           index = fold (build (MINUS_EXPR, index_type, index,
+                                convert (sizetype, low_bound)));
 
          if (TREE_CODE (index) == INTEGER_CST)
            {
index 043ad286be3f7217e3dfffbb071bb963655c378d..b44a411e9da5b9c56021dd49ac3249b4f8f7de8d 100644 (file)
@@ -783,6 +783,7 @@ layout_type (type)
            tree ub = TYPE_MAX_VALUE (index);
            tree lb = TYPE_MIN_VALUE (index);
            tree length;
+           tree element_size;
 
            /* If UB is max (lb - 1, x), remove the MAX_EXPR since the
               test for negative below covers it.  */
@@ -815,8 +816,19 @@ layout_type (type)
                && TREE_CODE (TYPE_MAX_VALUE (index)) != INTEGER_CST)
              length = size_binop (MAX_EXPR, length, size_zero_node);
 
-           TYPE_SIZE (type) = size_binop (MULT_EXPR, TYPE_SIZE (element),
-                                          length);
+           /* Special handling for arrays of bits (for Chill).  */
+           element_size = TYPE_SIZE (element);
+           if (TYPE_PACKED (type) && INTEGRAL_TYPE_P (element))
+             {
+               HOST_WIDE_INT maxvalue, minvalue;
+               maxvalue = TREE_INT_CST_LOW (TYPE_MAX_VALUE (element));
+               minvalue = TREE_INT_CST_LOW (TYPE_MIN_VALUE (element));
+               if (maxvalue - minvalue == 1
+                   && (maxvalue == 1 || maxvalue == 0))
+                 element_size = integer_one_node;
+             }
+
+           TYPE_SIZE (type) = size_binop (MULT_EXPR, element_size, length);
 
            /* If we know the size of the element, calculate the total
               size directly, rather than do some division thing below.