strlen: do not use cond_expr for boundaries
Checks
Commit Message
Hi.
We reach cond_expr and then we get an ICE in tree_int_cst_lt.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
PR tree-optimization/108137
gcc/ChangeLog:
* tree-ssa-strlen.cc (get_range_strlen_phi): Reject anything
different from INTEGER_CST.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/pr108137.c: New test.
---
gcc/testsuite/gcc.dg/tree-ssa/pr108137.c | 8 ++++++++
gcc/tree-ssa-strlen.cc | 13 +++++++------
2 files changed, 15 insertions(+), 6 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr108137.c
Comments
On 12/23/22 08:44, Martin Liška wrote:
> Hi.
>
> We reach cond_expr and then we get an ICE in tree_int_cst_lt.
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
> Thanks,
> Martin
>
> PR tree-optimization/108137
>
> gcc/ChangeLog:
>
> * tree-ssa-strlen.cc (get_range_strlen_phi): Reject anything
> different from INTEGER_CST.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.dg/tree-ssa/pr108137.c: New test.
OK. You could perhaps do better by looking at the arms of the
COND_EXPR, but this seems like the safest thing to do for gcc-13.
jeff
new file mode 100644
@@ -0,0 +1,8 @@
+// PR tree-optimization/108137
+// { dg-do compile }
+// { dg-options "-Wformat-overflow" }
+
+void f(unsigned short x_port, unsigned int x_host)
+{
+ __builtin_printf("missing %s", x_port ? "host" : &"host:port"[x_host ? 5 : 0]);
+}
@@ -1136,14 +1136,15 @@ get_range_strlen_phi (tree src, gphi *phi,
/* Adjust the minimum and maximum length determined so far and
the upper bound on the array size. */
- if (!pdata->minlen
- || tree_int_cst_lt (argdata.minlen, pdata->minlen))
+ if (TREE_CODE (argdata.minlen) == INTEGER_CST
+ && (!pdata->minlen
+ || tree_int_cst_lt (argdata.minlen, pdata->minlen)))
pdata->minlen = argdata.minlen;
- if (!pdata->maxlen
- || (argdata.maxlen
- && TREE_CODE (argdata.maxlen) == INTEGER_CST
- && tree_int_cst_lt (pdata->maxlen, argdata.maxlen)))
+ if (TREE_CODE (argdata.maxlen) == INTEGER_CST
+ && (!pdata->maxlen
+ || (argdata.maxlen
+ && tree_int_cst_lt (pdata->maxlen, argdata.maxlen))))
pdata->maxlen = argdata.maxlen;
if (!pdata->maxbound