From: Richard Stallman Date: Thu, 31 Dec 1992 08:32:47 +0000 (+0000) Subject: (build_index_type): Leave TYPE_MAX_VALUE as -1 if it was; X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cdc5a032d9dd6e37b1f7678897199dc13a7d6ea0;p=gcc.git (build_index_type): Leave TYPE_MAX_VALUE as -1 if it was; don't truncate the high bits. (size_in_bytes): Call force_fit_type with end result. (int_size_in_bytes): Avoid overflow as long as result fits. Return type is now unsigned int. From-SVN: r3006 --- diff --git a/gcc/tree.c b/gcc/tree.c index 3ce46f6e3a4..f2ea2e481b8 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -1692,6 +1692,8 @@ tree size_in_bytes (type) tree type; { + tree t; + if (type == error_mark_node) return integer_zero_node; type = TYPE_MAIN_VARIANT (type); @@ -1700,18 +1702,20 @@ size_in_bytes (type) incomplete_type_error (NULL_TREE, type); return integer_zero_node; } - return size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), - size_int (BITS_PER_UNIT)); + t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), + size_int (BITS_PER_UNIT)); + force_fit_type (t); + return t; } /* Return the size of TYPE (in bytes) as an integer, or return -1 if the size can vary. */ -int +unsigned int int_size_in_bytes (type) tree type; { - int size; + unsigned int size; if (type == error_mark_node) return 0; type = TYPE_MAIN_VARIANT (type); @@ -1719,6 +1723,12 @@ int_size_in_bytes (type) return -1; if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) return -1; + if (TREE_INT_CST_HIGH (TYPE_SIZE (type)) != 0) + { + tree t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), + size_int (BITS_PER_UNIT)); + return TREE_INT_CST_LOW (t); + } size = TREE_INT_CST_LOW (TYPE_SIZE (type)); return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT; } @@ -2676,6 +2686,13 @@ build_index_type (maxval) if (TREE_CODE (maxval) == INTEGER_CST) { int maxint = (int) TREE_INT_CST_LOW (maxval); + /* If the domain should be empty, make sure the maxval + remains -1 and is not spoiled by truncation. */ + if (INT_CST_LT (maxval, integer_zero_node)) + { + TYPE_MAX_VALUE (itype) = build_int_2 (-1, -1); + TREE_TYPE (TYPE_MAX_VALUE (itype)) = sizetype; + } return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype); } else