re PR middle-end/78153 (strlen return value can be assumed to be less than PTRDIFF_MAX)

2016-11-23  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

	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
This commit is contained in:
Prathamesh Kulkarni 2016-11-23 18:04:14 +00:00 committed by Prathamesh Kulkarni
parent 017fdefeb3
commit cfe3d65388
6 changed files with 61 additions and 0 deletions

View File

@ -1,3 +1,10 @@
2016-11-23 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
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 <law@redhat.com>
* config/ia64/ia64.c (ia64_emit_insn_before): Fix prototype.

View File

@ -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<greturn *> (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:;
}

View File

@ -1,3 +1,9 @@
2016-11-23 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
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 <james.greenhalgh@arm.com>
PR target/63250

View File

@ -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" } } */

View File

@ -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" } } */

View File

@ -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;
}