===================================================================
@@ -1959,16 +1959,14 @@ layout_type (tree type)
if (integer_zerop (element_size))
length = size_zero_node;
- /* The computation should happen in the original type so
+ /* The computation should happen in the original signedness so
that (possible) negative values are handled appropriately. */
else
length
= fold_convert (sizetype,
- fold_build2 (PLUS_EXPR, TREE_TYPE (lb),
- build_int_cst (TREE_TYPE (lb), 1),
- fold_build2 (MINUS_EXPR,
- TREE_TYPE (lb),
- ub, lb)));
+ size_binop (PLUS_EXPR,
+ build_int_cst (TREE_TYPE (lb), 1),
+ size_binop (MINUS_EXPR, ub, lb)));
TYPE_SIZE (type) = size_binop (MULT_EXPR, element_size,
fold_convert (bitsizetype,
===================================================================
@@ -1248,7 +1248,7 @@ copy_type (tree type)
return new_type;
}
-/* Return a subtype of sizetype with range MIN to MAX and whose
+/* Return a subtype of [s]sizetype with range MIN to MAX and whose
TYPE_INDEX_TYPE is INDEX. GNAT_NODE is used for the position
of the associated TYPE_DECL. */
@@ -1256,7 +1256,8 @@ tree
create_index_type (tree min, tree max, tree index, Node_Id gnat_node)
{
/* First build a type for the desired range. */
- tree type = build_nonshared_range_type (sizetype, min, max);
+ tree type = build_nonshared_range_type (TYPE_UNSIGNED (index)
+ ? sizetype : ssizetype, min, max);
/* Then set the index type. */
SET_TYPE_INDEX_TYPE (type, index);