From 370f4759839b573d45ed86050d51564dcac629b7 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Tue, 16 Aug 2011 13:55:30 +0000 Subject: [PATCH] tree.h (ptrofftype_p): New helper function. 2011-08-16 Richard Guenther * tree.h (ptrofftype_p): New helper function. * tree-cfg.c (verify_expr): Use ptrofftype_p for POINTER_PLUS_EXPR offset verification. (verify_gimple_assign_binary): Likewise. * tree.c (build2_stat): Likewise. * tree-chrec.c (chrec_fold_plus_poly_poly): Likewise. (reset_evolution_in_loop): Likewise. * tree-chrec.h (build_polynomial_chrec): Likewise. From-SVN: r177784 --- gcc/ChangeLog | 11 +++++++++++ gcc/tree-cfg.c | 10 ++++------ gcc/tree-chrec.c | 6 +++--- gcc/tree-chrec.h | 2 +- gcc/tree.c | 3 +-- gcc/tree.h | 10 ++++++++++ 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a2f8a23af28..7b672d17162 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2011-08-16 Richard Guenther + + * tree.h (ptrofftype_p): New helper function. + * tree-cfg.c (verify_expr): Use ptrofftype_p for POINTER_PLUS_EXPR + offset verification. + (verify_gimple_assign_binary): Likewise. + * tree.c (build2_stat): Likewise. + * tree-chrec.c (chrec_fold_plus_poly_poly): Likewise. + (reset_evolution_in_loop): Likewise. + * tree-chrec.h (build_polynomial_chrec): Likewise. + 2011-08-16 Liang Wang * ggc.h (ggc_alloc_rtvec_sized): Change arguments of diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 12079081914..ea85959bf10 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -2772,13 +2772,11 @@ verify_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED) error ("invalid operand to pointer plus, first operand is not a pointer"); return t; } - /* Check to make sure the second operand is an integer with type of - sizetype. */ - if (!useless_type_conversion_p (sizetype, - TREE_TYPE (TREE_OPERAND (t, 1)))) + /* Check to make sure the second operand is a ptrofftype. */ + if (!ptrofftype_p (TREE_TYPE (TREE_OPERAND (t, 1)))) { error ("invalid operand to pointer plus, second operand is not an " - "integer with type of sizetype"); + "integer type of appropriate width"); return t; } /* FALLTHROUGH */ @@ -3525,7 +3523,7 @@ verify_gimple_assign_binary (gimple stmt) do_pointer_plus_expr_check: if (!POINTER_TYPE_P (rhs1_type) || !useless_type_conversion_p (lhs_type, rhs1_type) - || !useless_type_conversion_p (sizetype, rhs2_type)) + || !ptrofftype_p (rhs2_type)) { error ("type mismatch in pointer plus expression"); debug_generic_stmt (lhs_type); diff --git a/gcc/tree-chrec.c b/gcc/tree-chrec.c index f9bebee7fe6..9ceb6f0cf4d 100644 --- a/gcc/tree-chrec.c +++ b/gcc/tree-chrec.c @@ -95,14 +95,14 @@ chrec_fold_plus_poly_poly (enum tree_code code, tree left, right; struct loop *loop0 = get_chrec_loop (poly0); struct loop *loop1 = get_chrec_loop (poly1); - tree rtype = code == POINTER_PLUS_EXPR ? sizetype : type; + tree rtype = code == POINTER_PLUS_EXPR ? chrec_type (poly1) : type; gcc_assert (poly0); gcc_assert (poly1); gcc_assert (TREE_CODE (poly0) == POLYNOMIAL_CHREC); gcc_assert (TREE_CODE (poly1) == POLYNOMIAL_CHREC); if (POINTER_TYPE_P (chrec_type (poly0))) - gcc_assert (chrec_type (poly1) == sizetype); + gcc_assert (ptrofftype_p (chrec_type (poly1))); else gcc_assert (chrec_type (poly0) == chrec_type (poly1)); gcc_assert (type == chrec_type (poly0)); @@ -831,7 +831,7 @@ reset_evolution_in_loop (unsigned loop_num, struct loop *loop = get_loop (loop_num); if (POINTER_TYPE_P (chrec_type (chrec))) - gcc_assert (sizetype == chrec_type (new_evol)); + gcc_assert (ptrofftype_p (chrec_type (new_evol))); else gcc_assert (chrec_type (chrec) == chrec_type (new_evol)); diff --git a/gcc/tree-chrec.h b/gcc/tree-chrec.h index 9b971bde1af..bf9bff0f999 100644 --- a/gcc/tree-chrec.h +++ b/gcc/tree-chrec.h @@ -145,7 +145,7 @@ build_polynomial_chrec (unsigned loop_num, /* Types of left and right sides of a chrec should be compatible. */ if (POINTER_TYPE_P (TREE_TYPE (left))) - gcc_assert (sizetype == TREE_TYPE (right)); + gcc_assert (ptrofftype_p (TREE_TYPE (right))); else gcc_assert (TREE_TYPE (left) == TREE_TYPE (right)); diff --git a/gcc/tree.c b/gcc/tree.c index d20751a9c7b..3eaf2f90ea2 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -3784,8 +3784,7 @@ build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL) if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt) gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0)) - && INTEGRAL_TYPE_P (TREE_TYPE (arg1)) - && useless_type_conversion_p (sizetype, TREE_TYPE (arg1))); + && ptrofftype_p (TREE_TYPE (arg1))); t = make_node_stat (code PASS_MEM_STAT); TREE_TYPE (t) = tt; diff --git a/gcc/tree.h b/gcc/tree.h index c8d292a3d4f..139c27616fe 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -5313,6 +5313,16 @@ truth_value_p (enum tree_code code) || code == TRUTH_XOR_EXPR || code == TRUTH_NOT_EXPR); } +/* Return whether TYPE is a type suitable for an offset for + a POINTER_PLUS_EXPR. */ +static inline bool +ptrofftype_p (tree type) +{ + return (INTEGRAL_TYPE_P (type) + && TYPE_PRECISION (type) == TYPE_PRECISION (sizetype) + && TYPE_UNSIGNED (type) == TYPE_UNSIGNED (sizetype)); +} + /* Build and fold a POINTER_PLUS_EXPR at LOC offsetting PTR by OFF. */ static inline tree fold_build_pointer_plus_loc (location_t loc, tree ptr, tree off) -- 2.30.2