[Bug tree-optimization/86914] [8/9 Regression] -O2 generates wrong code with strlen() of pointers within one-element arrays of structures

2018-08-27 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86914

--- Comment #5 from Martin Sebor  ---
Author: msebor
Date: Tue Aug 28 00:25:50 2018
New Revision: 263905

URL: https://gcc.gnu.org/viewcvs?rev=263905=gcc=rev
Log:
PR tree-optimization/86914 - wrong code with strlen() of poor-man's flexible
array member plus offset

gcc/ChangeLog:

PR tree-optimization/86914
* tree-ssa-strlen.c (maybe_set_strlen_range): Avoid MEM_REF.

gcc/testsuite/ChangeLog:

PR tree-optimization/86914
* gcc.dg/strlenopt-57.c: New test.


Added:
trunk/gcc/testsuite/gcc.dg/strlenopt-57.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-ssa-strlen.c

[Bug tree-optimization/86914] [8/9 Regression] -O2 generates wrong code with strlen() of pointers within one-element arrays of structures

2018-08-21 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86914

Richard Biener  changed:

   What|Removed |Added

   Priority|P3  |P2
   Target Milestone|--- |8.3

[Bug tree-optimization/86914] [8/9 Regression] -O2 generates wrong code with strlen() of pointers within one-element arrays of structures

2018-08-14 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86914

Martin Sebor  changed:

   What|Removed |Added

   Keywords||patch

--- Comment #4 from Martin Sebor  ---
Patch: https://gcc.gnu.org/ml/gcc-patches/2018-08/msg00823.html

[Bug tree-optimization/86914] [8/9 Regression] -O2 generates wrong code with strlen() of pointers within one-element arrays of structures

2018-08-11 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86914

Martin Sebor  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED

--- Comment #3 from Martin Sebor  ---
Let me handle this.

[Bug tree-optimization/86914] [8/9 Regression] -O2 generates wrong code with strlen() of pointers within one-element arrays of structures

2018-08-11 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86914

Martin Sebor  changed:

   What|Removed |Added

   Keywords||wrong-code
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2018-08-11
 CC||law at redhat dot com,
   ||msebor at gcc dot gnu.org
Summary|gcc 8.1 -O2 generates wrong |[8/9 Regression] -O2
   |code with strlen() of   |generates wrong code with
   |pointers within one-element |strlen() of pointers within
   |arrays of structures|one-element arrays of
   ||structures
 Ever confirmed|0   |1
  Known to fail||8.2.0, 9.0

--- Comment #2 from Martin Sebor  ---
Confirmed.  Most likely caused by r255790.

The strlen pass sees:

  _1 = [(void *)p_3(D) + 5B];
  _2 = __builtin_strlen (_1);

The code in maybe_set_strlen_range() tries to avoid using the size of the last
member array (GCC treats all such arrays as flexible array members) by checking
the result of array_at_struct_end_p() but the function doesn't handle MEM_REF
and returns false.  The optimization is disabled if the array is a bona fide
C11 flexible array member because the size of such an array is unknown.

Enhancing array_at_struct_end_p() to deal with MEM_REF or adding an
array_not_at_struct_end_p() that returns a conservative result would fix this
but the strlen range optimization will likely be disabled regardless.