+/* If the array TYPE has static bounds calculate and update its
+ size, then return true. Otherwise return false and leave TYPE
+ unchanged. */
+
+static bool
+update_static_array_size (struct type *type)
+{
+ gdb_assert (type->code () == TYPE_CODE_ARRAY);
+
+ struct type *range_type = type->index_type ();
+
+ if (type->dyn_prop (DYN_PROP_BYTE_STRIDE) == nullptr
+ && has_static_range (range_type->bounds ())
+ && (!type_not_associated (type)
+ && !type_not_allocated (type)))
+ {
+ LONGEST low_bound, high_bound;
+ int stride;
+ struct type *element_type;
+
+ /* If the array itself doesn't provide a stride value then take
+ whatever stride the range provides. Don't update BIT_STRIDE as
+ we don't want to place the stride value from the range into this
+ arrays bit size field. */
+ stride = TYPE_FIELD_BITSIZE (type, 0);
+ if (stride == 0)
+ stride = range_type->bit_stride ();
+
+ if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
+ low_bound = high_bound = 0;
+ element_type = check_typedef (TYPE_TARGET_TYPE (type));
+ /* Be careful when setting the array length. Ada arrays can be
+ empty arrays with the high_bound being smaller than the low_bound.
+ In such cases, the array length should be zero. */
+ if (high_bound < low_bound)
+ TYPE_LENGTH (type) = 0;
+ else if (stride != 0)
+ {
+ /* Ensure that the type length is always positive, even in the
+ case where (for example in Fortran) we have a negative
+ stride. It is possible to have a single element array with a
+ negative stride in Fortran (this doesn't mean anything
+ special, it's still just a single element array) so do
+ consider that case when touching this code. */
+ LONGEST element_count = std::abs (high_bound - low_bound + 1);
+ TYPE_LENGTH (type)
+ = ((std::abs (stride) * element_count) + 7) / 8;
+ }
+ else
+ TYPE_LENGTH (type) =
+ TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
+
+ return true;
+ }
+
+ return false;
+}
+