From: Prathamesh Kulkarni Date: Wed, 23 Nov 2016 18:04:14 +0000 (+0000) Subject: re PR middle-end/78153 (strlen return value can be assumed to be less than PTRDIFF_MAX) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cfe3d6538850d8e247995f2119b71f5dd04d1981;p=gcc.git re PR middle-end/78153 (strlen return value can be assumed to be less than PTRDIFF_MAX) 2016-11-23 Prathamesh Kulkarni PR middle-end/78153 * gimple-fold.c (fold_stmt_1): Handle case for GIMPLE_RETURN. * tree-vrp.c (extract_range_basic): Handle case for CFN_BUILT_IN_STRLEN. testsuite/ * gcc.dg/tree-ssa/pr78153-1.c: New test. * gcc.dg/tree-ssa/pr78153-2.c: Likewise. From-SVN: r242786 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 62e354c1a00..db002f7ae0e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2016-11-23 Prathamesh Kulkarni + + PR middle-end/78153 + * gimple-fold.c (fold_stmt_1): Handle case for GIMPLE_RETURN. + * tree-vrp.c (extract_range_basic): Handle case for + CFN_BUILT_IN_STRLEN. + 2016-11-23 Jeff Law * config/ia64/ia64.c (ia64_emit_insn_before): Fix prototype. diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index aabc8ff2a71..68423016118 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -4406,6 +4406,23 @@ fold_stmt_1 (gimple_stmt_iterator *gsi, bool inplace, tree (*valueize) (tree)) } break; + case GIMPLE_RETURN: + { + greturn *ret_stmt = as_a (stmt); + tree ret = gimple_return_retval(ret_stmt); + + if (ret && TREE_CODE (ret) == SSA_NAME && valueize) + { + tree val = valueize (ret); + if (val && val != ret) + { + gimple_return_set_retval (ret_stmt, val); + changed = true; + } + } + } + break; + default:; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0b5c3059214..084f3663562 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-11-23 Prathamesh Kulkarni + + PR middle-end/78153 + * gcc.dg/tree-ssa/pr78153-1.c: New test. + * gcc.dg/tree-ssa/pr78153-2.c: Likewise. + 2016-11-23 James Greenhalgh PR target/63250 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr78153-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr78153-1.c new file mode 100644 index 00000000000..2530ba08e1c --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr78153-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-evrp-slim" } */ + +void f(const char *s) +{ + if (__PTRDIFF_MAX__ <= __builtin_strlen (s)) + __builtin_abort (); +} + +/* { dg-final { scan-tree-dump-not "__builtin_abort" "evrp" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr78153-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr78153-2.c new file mode 100644 index 00000000000..de70450f1c9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr78153-2.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-evrp-slim" } */ + +void f(const char *s) +{ + __PTRDIFF_TYPE__ n = __builtin_strlen (s); + if (n < 0) + __builtin_abort (); +} + +/* { dg-final { scan-tree-dump-not "__builtin_abort" "evrp" } } */ diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 5bd4418eea3..33e0a755cfe 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -4027,6 +4027,16 @@ extract_range_basic (value_range *vr, gimple *stmt) : vrp_val_max (type), NULL); } return; + case CFN_BUILT_IN_STRLEN: + { + tree type = TREE_TYPE (gimple_call_lhs (stmt)); + tree max = vrp_val_max (ptrdiff_type_node); + wide_int wmax = wi::to_wide (max, TYPE_PRECISION (TREE_TYPE (max))); + tree range_min = build_zero_cst (type); + tree range_max = wide_int_to_tree (type, wmax - 1); + set_value_range (vr, VR_RANGE, range_min, range_max, NULL); + } + return; default: break; }