From b9e67f8b4b38059390c4ccc0f12285544618feec Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Sat, 22 Sep 2007 09:39:41 +0000 Subject: [PATCH] re PR tree-optimization/33146 (ICE in build_polynomial_chrec, at tree-chrec.h:136) 2007-09-22 Richard Guenther PR tree-optimization/33146 * fold-const.c (fold_binary): Use the original tree for negating. * tree.h (STRIP_SIGN_NOPS): Converting from or to pointer also changes "sign". * gcc.c-torture/compile/pr33146.c: New testcase. From-SVN: r128666 --- gcc/ChangeLog | 8 ++++++++ gcc/fold-const.c | 6 ++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.c-torture/compile/pr33146.c | 19 +++++++++++++++++++ gcc/tree.h | 4 +++- 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr33146.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 20bf0529736..6f3cc5f8e12 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2007-09-22 Richard Guenther + + PR tree-optimization/33146 + * fold-const.c (fold_binary): Use the original tree + for negating. + * tree.h (STRIP_SIGN_NOPS): Converting from or to pointer + also changes "sign". + 2007-09-22 Eric Botcazou PR target/32325 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index fb664fee8be..426aad4ced1 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -10240,9 +10240,11 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) return omit_one_operand (type, arg1, arg0); if (integer_onep (arg1)) return non_lvalue (fold_convert (type, arg0)); - /* Transform x * -1 into -x. */ + /* Transform x * -1 into -x. Make sure to do the negation + on the original operand with conversions not stripped + because we can only strip non-sign-changing conversions. */ if (integer_all_onesp (arg1)) - return fold_convert (type, negate_expr (arg0)); + return fold_convert (type, negate_expr (op0)); /* Transform x * -C into -x * C if x is easily negatable. */ if (TREE_CODE (arg1) == INTEGER_CST && tree_int_cst_sgn (arg1) == -1 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 710d8df6ee3..5b5a36f2f9e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-09-22 Richard Guenther + + PR tree-optimization/33146 + * gcc.c-torture/compile/pr33146.c: New testcase. + 2007-09-22 Richard Sandiford * lib/target-supports.exp (check_cached_effective_target): New diff --git a/gcc/testsuite/gcc.c-torture/compile/pr33146.c b/gcc/testsuite/gcc.c-torture/compile/pr33146.c new file mode 100644 index 00000000000..6741fcf5d0f --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr33146.c @@ -0,0 +1,19 @@ +typedef struct +{ + int end; + int term; +} +jpc_enc_pass_t; +void foo(int numpasses, jpc_enc_pass_t *p) +{ + jpc_enc_pass_t *pass; + jpc_enc_pass_t *termpass; + for (pass = p; pass != termpass; ++pass) + if (!pass->term) + { + termpass = pass; + while (termpass - pass < numpasses && !termpass->term) + ++termpass; + pass->end = termpass->end; + } +} diff --git a/gcc/tree.h b/gcc/tree.h index 11a74f3c224..d7ca0b2a78d 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -1019,7 +1019,9 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int, && (TYPE_MODE (TREE_TYPE (EXP)) \ == TYPE_MODE (TREE_TYPE (TREE_OPERAND (EXP, 0)))) \ && (TYPE_UNSIGNED (TREE_TYPE (EXP)) \ - == TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (EXP, 0))))) \ + == TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (EXP, 0)))) \ + && (POINTER_TYPE_P (TREE_TYPE (EXP)) \ + == POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (EXP, 0))))) \ (EXP) = TREE_OPERAND (EXP, 0) /* Like STRIP_NOPS, but don't alter the TREE_TYPE either. */