@@ -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:;
}
new file mode 100644
@@ -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" } } */
new file mode 100644
@@ -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" } } */
@@ -4013,6 +4013,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;
}