PR middle-end/77357 - strlen of constant strings not folded
authorMartin Sebor <msebor@redhat.com>
Mon, 9 Jul 2018 20:33:48 +0000 (20:33 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Mon, 9 Jul 2018 20:33:48 +0000 (14:33 -0600)
commit35b4d3a644222b7bd69b3a1e9c00e78f3dbf3eba
treea540d226c0eeee38bd5ea06483ae688c1e0c070e
parentaad2444d346d4ae504a938de8708341dd1889aed
PR middle-end/77357 - strlen of constant strings not folded

gcc/ChangeLog:

PR middle-end/77357
PR middle-end/86428
* builtins.c (c_strlen): Avoid out-of-bounds warnings when
accessing implicitly initialized array elements.
* expr.c (string_constant): Handle string initializers of
character arrays within aggregates.
* gimple-fold.c (fold_array_ctor_reference): Add argument.
Store element offset.  As a special case, handle zero size.
(fold_nonarray_ctor_reference): Same.
(fold_ctor_reference): Add argument.  Store subobject offset.
* gimple-fold.h (fold_ctor_reference): Add argument.

gcc/testsuite/ChangeLog:

PR middle-end/77357
* gcc.dg/strlenopt-49.c: New test.
* gcc.dg/strlenopt-50.c: New test.
* gcc.dg/strlenopt-51.c: New test.
* gcc.dg/strlenopt-52.c: New test.

From-SVN: r262522
13 files changed:
gcc/ChangeLog
gcc/builtins.c
gcc/expr.c
gcc/fold-const.c
gcc/fold-const.h
gcc/gimple-fold.c
gcc/gimple-fold.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/builtins/strlen-3.c
gcc/testsuite/gcc.dg/strlenopt-49.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/strlenopt-50.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/strlenopt-51.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/strlenopt-52.c [new file with mode: 0644]