aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.c
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2010-09-10 13:44:07 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2010-09-10 13:44:07 +0000
commit8c4353b7c50bc8855a0abdd9d9514477de715a33 (patch)
tree95b9637b447d189f3b6b054784820287a5fe2aa4 /gcc/tree.c
parenta7c764a96ca48293b863196a073eb119453e1a3b (diff)
downloadgcc-8c4353b7c50bc8855a0abdd9d9514477de715a33.zip
gcc-8c4353b7c50bc8855a0abdd9d9514477de715a33.tar.gz
gcc-8c4353b7c50bc8855a0abdd9d9514477de715a33.tar.bz2
tree.c (type_hash_eq): For ARRAY_TYPEs also compare TYPE_SIZE.
2010-09-10 Richard Guenther <rguenther@suse.de> * tree.c (type_hash_eq): For ARRAY_TYPEs also compare TYPE_SIZE. (build_index_type): Implement in terms of build_range_type. (build_range_type): Do not allow NULL_TREE type, improve hashing to cover more cases. Set TYPE_STRUCTURAL_EQUALITY_P if we didn't hash. * c-decl.c (grokdeclarator): When modifying TYPE_SIZE manually create a distinct copy of the type. From-SVN: r164174
Diffstat (limited to 'gcc/tree.c')
-rw-r--r--gcc/tree.c75
1 files changed, 31 insertions, 44 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index 7ea69c8..bc21491 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -7034,41 +7034,6 @@ build_type_no_quals (tree t)
}
}
-/* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
- MAXVAL should be the maximum value in the domain
- (one less than the length of the array).
-
- The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
- We don't enforce this limit, that is up to caller (e.g. language front end).
- The limit exists because the result is a signed type and we don't handle
- sizes that use more than one HOST_WIDE_INT. */
-
-tree
-build_index_type (tree maxval)
-{
- tree itype = make_node (INTEGER_TYPE);
-
- TREE_TYPE (itype) = sizetype;
- TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
- TYPE_MIN_VALUE (itype) = size_zero_node;
- TYPE_MAX_VALUE (itype) = fold_convert (sizetype, maxval);
- SET_TYPE_MODE (itype, TYPE_MODE (sizetype));
- TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
- TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
- TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
- TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (sizetype);
-
- if (host_integerp (maxval, 1))
- return type_hash_canon (tree_low_cst (maxval, 1), itype);
- else
- {
- /* Since we cannot hash this type, we need to compare it using
- structural equality checks. */
- SET_TYPE_STRUCTURAL_EQUALITY (itype);
- return itype;
- }
-}
-
#define MAX_INT_CACHED_PREC \
(HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
static GTY(()) tree nonstandard_integer_type_cache[2 * MAX_INT_CACHED_PREC + 2];
@@ -7111,16 +7076,15 @@ build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
/* Create a range of some discrete type TYPE (an INTEGER_TYPE,
ENUMERAL_TYPE or BOOLEAN_TYPE), with low bound LOWVAL and
- high bound HIGHVAL. If TYPE is NULL, sizetype is used. */
+ high bound HIGHVAL. */
tree
build_range_type (tree type, tree lowval, tree highval)
{
tree itype = make_node (INTEGER_TYPE);
+ hashval_t hash;
TREE_TYPE (itype) = type;
- if (type == NULL_TREE)
- type = sizetype;
TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
@@ -7132,12 +7096,35 @@ build_range_type (tree type, tree lowval, tree highval)
TYPE_ALIGN (itype) = TYPE_ALIGN (type);
TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
- if (host_integerp (lowval, 0) && highval != 0 && host_integerp (highval, 0))
- return type_hash_canon (tree_low_cst (highval, 0)
- - tree_low_cst (lowval, 0),
- itype);
- else
- return itype;
+ if ((TYPE_MIN_VALUE (itype)
+ && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST)
+ || (TYPE_MAX_VALUE (itype)
+ && TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST))
+ {
+ /* Since we cannot reliably merge this type, we need to compare it using
+ structural equality checks. */
+ SET_TYPE_STRUCTURAL_EQUALITY (itype);
+ return itype;
+ }
+ hash = iterative_hash_expr (TYPE_MIN_VALUE (itype), 0);
+ hash = iterative_hash_expr (TYPE_MAX_VALUE (itype), hash);
+ hash = iterative_hash_hashval_t (TYPE_HASH (type), hash);
+ return type_hash_canon (hash, itype);
+}
+
+/* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
+ MAXVAL should be the maximum value in the domain
+ (one less than the length of the array).
+
+ The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
+ We don't enforce this limit, that is up to caller (e.g. language front end).
+ The limit exists because the result is a signed type and we don't handle
+ sizes that use more than one HOST_WIDE_INT. */
+
+tree
+build_index_type (tree maxval)
+{
+ return build_range_type (sizetype, size_zero_node, maxval);
}
/* Return true if the debug information for TYPE, a subtype, should be emitted