From bbc210abb5bc5dc9961f05af2187cfa7170d9916 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Thu, 7 Jul 2011 14:21:21 +0000 Subject: [PATCH] fold-const.c (fold_unary_loc): Do not strip sign-changes for NEGATE_EXPR. 2011-07-07 Richard Guenther * fold-const.c (fold_unary_loc): Do not strip sign-changes for NEGATE_EXPR. * gcc.dg/ftrapv-3.c: New testcase. From-SVN: r175976 --- gcc/ChangeLog | 5 +++++ gcc/fold-const.c | 2 +- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/ftrapv-3.c | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/ftrapv-3.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f3b7c1106c5..7a7c0ecdd53 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2011-07-07 Richard Guenther + + * fold-const.c (fold_unary_loc): Do not strip sign-changes + for NEGATE_EXPR. + 2011-07-07 Richard Guenther * tree-vrp.c (simplify_conversion_using_ranges): New function. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index e48aae9f4ce..44a8b6feaaa 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -7561,7 +7561,7 @@ fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0) if (arg0) { if (CONVERT_EXPR_CODE_P (code) - || code == FLOAT_EXPR || code == ABS_EXPR) + || code == FLOAT_EXPR || code == ABS_EXPR || code == NEGATE_EXPR) { /* Don't use STRIP_NOPS, because signedness of argument type matters. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 910a33368f6..1800d48f0f2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-07-07 Richard Guenther + + * gcc.dg/ftrapv-3.c: New testcase. + 2011-07-07 Richard Guenther * gcc.dg/tree-ssa/vrp58.c: New testcase. diff --git a/gcc/testsuite/gcc.dg/ftrapv-3.c b/gcc/testsuite/gcc.dg/ftrapv-3.c new file mode 100644 index 00000000000..e23059a078c --- /dev/null +++ b/gcc/testsuite/gcc.dg/ftrapv-3.c @@ -0,0 +1,16 @@ +/* { dg-do run } */ +/* { dg-options "-ftrapv" } */ + +extern void abort (void); +unsigned long +foo (long i, long j) +{ + /* We may not fold this to (unsigned long)(i * j). */ + return -(unsigned long)(i * -j); +} +int main() +{ + if (foo (-__LONG_MAX__ - 1, -1) != -(unsigned long)(-__LONG_MAX__ - 1)) + abort (); + return 0; +} -- 2.30.2