[Bug tree-optimization/89500] [9 Regression] ICE: tree check: expected integer_cst, have ssa_name in get_len, at tree.h:5653

2019-02-26 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89500

Jakub Jelinek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #6 from Jakub Jelinek  ---
Fixed.

[Bug tree-optimization/89500] [9 Regression] ICE: tree check: expected integer_cst, have ssa_name in get_len, at tree.h:5653

2019-02-26 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89500

--- Comment #5 from Jakub Jelinek  ---
Author: jakub
Date: Tue Feb 26 20:36:29 2019
New Revision: 269230

URL: https://gcc.gnu.org/viewcvs?rev=269230=gcc=rev
Log:
PR tree-optimization/89500
* tree-ssa-strlen.c (stridx_strlenloc): Adjust comment.
(handle_builtin_strlen): Remove noncst_bound variable.  Always
optimize strnlen (x, 0) to 0.  Optimize strnlen (x, cst) to
cst if the first cst bytes starting at x are known to be non-zero,
even if the string is not zero terminated.  Don't try to modify
*si for strnlen.  Update strlen_to_stridx only for strlen or if
we can prove strnlen returns the same value as strlen would.

* gcc.dg/pr89500.c: New test.
* gcc.dg/Wstringop-overflow-10.c: New test.
* gcc.dg/strlenopt-60.c: New test.

Added:
trunk/gcc/testsuite/gcc.dg/Wstringop-overflow-10.c
trunk/gcc/testsuite/gcc.dg/pr89500.c
trunk/gcc/testsuite/gcc.dg/strlenopt-60.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-ssa-strlen.c

[Bug tree-optimization/89500] [9 Regression] ICE: tree check: expected integer_cst, have ssa_name in get_len, at tree.h:5653

2019-02-25 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89500

--- Comment #4 from Jakub Jelinek  ---
Created attachment 45819
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45819=edit
gcc9-pr89500.patch

Untested fix.

[Bug tree-optimization/89500] [9 Regression] ICE: tree check: expected integer_cst, have ssa_name in get_len, at tree.h:5653

2019-02-25 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89500

--- Comment #3 from Jakub Jelinek  ---
The simplest fix might be:
--- gcc/tree-ssa-strlen.c.jj2019-01-18 00:33:19.466003372 +0100
+++ gcc/tree-ssa-strlen.c   2019-02-25 21:59:18.743419101 +0100
@@ -1302,6 +1302,7 @@ handle_builtin_strlen (gimple_stmt_itera
= fold_build2_loc (loc, MIN_EXPR, TREE_TYPE (rhs), rhs, bound);

  noncst_bound = (TREE_CODE (new_rhs) != INTEGER_CST
+ || TREE_CODE (rhs) != INTEGER_CST
  || tree_int_cst_lt (new_rhs, rhs));

  rhs = new_rhs;

The problem is that even when rhs is not INTEGER_CST, when bound is
size_zero_node, then new_rhs is size_zero_node too, but we can't really use
tree_int_cst_lt in that case (nor know anything about the string length).

But, I think we don't want to stay at that, noncst_bound seems to be really
misnamed, but furthermore, I fail to see when it is ever useful to record
something (or when it actually would record anything, because it doesn't it
si->nonzero_chars is INTEGER_CST.

[Bug tree-optimization/89500] [9 Regression] ICE: tree check: expected integer_cst, have ssa_name in get_len, at tree.h:5653

2019-02-25 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89500

--- Comment #2 from Jakub Jelinek  ---
Even better testcase without any UB in it:

typedef __SIZE_TYPE__ size_t;
extern size_t strlen (const char *);
extern size_t strnlen (const char *, size_t);
extern void bar (char *);

void
foo (int *a)
{
  char c[64];
  bar (c);
  a[0] = strlen (c);
  a[1] = strnlen (c, 0);
}

[Bug tree-optimization/89500] [9 Regression] ICE: tree check: expected integer_cst, have ssa_name in get_len, at tree.h:5653

2019-02-25 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89500

Jakub Jelinek  changed:

   What|Removed |Added

   Priority|P3  |P1
 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2019-02-25
 CC||jakub at gcc dot gnu.org
   Assignee|unassigned at gcc dot gnu.org  |jakub at gcc dot gnu.org
   Target Milestone|--- |9.0
 Ever confirmed|0   |1

--- Comment #1 from Jakub Jelinek  ---
Started with r262114.  Looking into this.
Slightly adjusted testcase, no need for c[0] nor storing strnlen into the same
element as strlen:
typedef __SIZE_TYPE__ size_t;
extern size_t strlen (const char *);
extern size_t strnlen (const char *, size_t);

void
foo (int *a)
{
  char c[4];
  a[0] = strlen (c);
  a[1] = strnlen (c, 0);
}