From 9abd8e8b634af19867783e19c17b2ee7bf1d35d4 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sat, 17 Nov 2012 23:00:32 +0100 Subject: [PATCH] re PR tree-optimization/55236 (gcc.c-torture/execute/pr22493-1.c FAILs with -fPIC) PR tree-optimization/55236 * fold-const.c (make_range_step) : For -fwrapv and signed ARG0_TYPE, force low and high to be non-NULL. * gcc.dg/pr55236.c: New test. From-SVN: r193591 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 11 +++++++++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.dg/pr55236.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr55236.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index eb01532c656..935e3c0f908 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2012-11-17 Jakub Jelinek + + PR tree-optimization/55236 + * fold-const.c (make_range_step) : For -fwrapv + and signed ARG0_TYPE, force low and high to be non-NULL. + 2012-11-17 H.J. Lu * common.opt (static-libasan): New option. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 2e908648451..56e0554737e 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -3880,6 +3880,17 @@ make_range_step (location_t loc, enum tree_code code, tree arg0, tree arg1, return arg0; case NEGATE_EXPR: + /* If flag_wrapv and ARG0_TYPE is signed, make sure + low and high are non-NULL, then normalize will DTRT. */ + if (!TYPE_UNSIGNED (arg0_type) + && !TYPE_OVERFLOW_UNDEFINED (arg0_type)) + { + if (low == NULL_TREE) + low = TYPE_MIN_VALUE (arg0_type); + if (high == NULL_TREE) + high = TYPE_MAX_VALUE (arg0_type); + } + /* (-x) IN [a,b] -> x in [-b, -a] */ n_low = range_binop (MINUS_EXPR, exp_type, build_int_cst (exp_type, 0), diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 955546e5a6e..245b6ef2a9e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2012-11-17 Jakub Jelinek + PR tree-optimization/55236 + * gcc.dg/pr55236.c: New test. + PR testsuite/55188 * gcc.dg/pr19105.c: Accept also optimizing -[2, 2] and -[3, 3] and -[4, 4] range tests together. diff --git a/gcc/testsuite/gcc.dg/pr55236.c b/gcc/testsuite/gcc.dg/pr55236.c new file mode 100644 index 00000000000..dc66c04c327 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr55236.c @@ -0,0 +1,31 @@ +/* PR tree-optimization/55236 */ +/* { dg-do run } */ +/* { dg-options "-O2 -fwrapv" } */ + +extern void abort (); + +__attribute__((noinline, noclone)) void +foo (int i) +{ + if (i > 0) + abort (); + i = -i; + if (i < 0) + return; + abort (); +} + +__attribute__((noinline, noclone)) void +bar (int i) +{ + if (i > 0 || (-i) >= 0) + abort (); +} + +int +main () +{ + foo (-__INT_MAX__ - 1); + bar (-__INT_MAX__ - 1); + return 0; +} -- 2.30.2