+2019-09-23 Martin Sebor <msebor@redhat.com>
+
+ PR tree-optimization/91570
+ * tree-ssa-strlen.c (get_range_strlen_dynamic): Handle null and
+ non-constant minlen, maxlen and maxbound.
+
2019-09-24 Richard Biener <rguenther@suse.de>
* tree-vectorizer.h (_stmt_vec_info::const_cond_reduc_code):
--- /dev/null
+/* PR tree-optimization/91570 - ICE in get_range_strlen_dynamic on
+ a conditional of two strings
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+extern char a[], b[];
+
+/* Test case from comment #0 on the bug. */
+
+void comment_0 (int i)
+{
+ a[0] = 0;
+ b[0] = '1';
+
+ const char *p = i ? b : a;
+
+ if (__builtin_snprintf (0, 0, "%s", p) < 4)
+ __builtin_abort ();
+}
+
+
+/* Test case from comment #2 on the bug. */
+
+void comment_2 (char *s)
+{
+ char *t = __builtin_strrchr (s, '/');
+ __builtin_strcat (s, ".SIF");
+ t = t ? t : s;
+ __builtin_printf ("%s", t);
+}
if (!argdata.minlen
|| (integer_zerop (argdata.minlen)
- && integer_all_onesp (argdata.maxbound)
+ && (!argdata.maxbound
+ || integer_all_onesp (argdata.maxbound))
&& integer_all_onesp (argdata.maxlen)))
{
/* Set the upper bound of the length to unbounded. */
|| tree_int_cst_lt (argdata.minlen, pdata->minlen))
pdata->minlen = argdata.minlen;
if (!pdata->maxlen
- || tree_int_cst_lt (pdata->maxlen, argdata.maxlen))
+ || (argdata.maxlen
+ && tree_int_cst_lt (pdata->maxlen, argdata.maxlen)))
pdata->maxlen = argdata.maxlen;
if (!pdata->maxbound
- || (tree_int_cst_lt (pdata->maxbound,
- argdata.maxbound)
+ || (argdata.maxbound
+ && tree_int_cst_lt (pdata->maxbound,
+ argdata.maxbound)
&& !integer_all_onesp (argdata.maxbound)))
pdata->maxbound = argdata.maxbound;
}
if (strinfo *si = get_strinfo (idx))
{
pdata->minlen = get_string_length (si);
- if (!pdata->minlen
- && si->nonzero_chars)
+ if (!pdata->minlen && si->nonzero_chars)
{
if (TREE_CODE (si->nonzero_chars) == INTEGER_CST)
pdata->minlen = si->nonzero_chars;
else
pdata->maxlen = build_all_ones_cst (size_type_node);
}
- else if (TREE_CODE (pdata->minlen) == SSA_NAME)
+ else if (pdata->minlen && TREE_CODE (pdata->minlen) == SSA_NAME)
{
const value_range *vr
= CONST_CAST (class vr_values *, rvals)
pdata->maxlen = build_all_ones_cst (size_type_node);
}
}
- else
+ else if (pdata->minlen && TREE_CODE (pdata->minlen) == INTEGER_CST)
{
pdata->maxlen = pdata->minlen;
pdata->maxbound = pdata->minlen;
}
+ else
+ {
+ /* For PDATA->MINLEN that's a non-constant expression such
+ as PLUS_EXPR whose value range is unknown, set the bounds
+ to zero and SIZE_MAX. */
+ pdata->minlen = build_zero_cst (size_type_node);
+ pdata->maxlen = build_all_ones_cst (size_type_node);
+ }
return true;
}