(build_array_ref): Force array to be allocated on the stack if...
authorJim Wilson <wilson@gcc.gnu.org>
Sun, 8 Aug 1993 21:38:20 +0000 (14:38 -0700)
committerJim Wilson <wilson@gcc.gnu.org>
Sun, 8 Aug 1993 21:38:20 +0000 (14:38 -0700)
(build_array_ref): Force array to be allocated on the
stack if it is accessed by out-of-bound constant integer subscript.

From-SVN: r5111

gcc/c-typeck.c

index 64d51e1ded09c00b21abc446427039e230301155..c748a562cd5da25a886bc232543b5523b86167b5 100644 (file)
@@ -1252,6 +1252,17 @@ build_array_ref (array, index)
          if (mark_addressable (array) == 0)
            return error_mark_node;
        }
+      /* An array that is indexed by a constant value which is not within
+        the array bounds cannot be stored in a register either; because we
+        would get a crash in store_bit_field/extract_bit_field when trying
+        to access a non-existent part of the register.  */
+      if (TREE_CODE (index) == INTEGER_CST
+         && TYPE_VALUES (TREE_TYPE (array))
+         && ! int_fits_type_p (index, TYPE_VALUES (TREE_TYPE (array))))
+       {
+         if (mark_addressable (array) == 0)
+           return error_mark_node;
+       }
 
       if (pedantic && !lvalue_p (array))
        {