PR tree-optimization/90879 - fold zero-equality of strcmp between a longer string...
authorMartin Sebor <msebor@redhat.com>
Wed, 9 Oct 2019 21:35:11 +0000 (21:35 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Wed, 9 Oct 2019 21:35:11 +0000 (15:35 -0600)
commita7160771da8b77a03317aab2c27706ba70fe3e9c
treed959d13c4cf04cf2f20c0cc56cd382c62d3b3b45
parent89e0a492af5bec8ffa2ec5d99c4858df50d22c16
PR tree-optimization/90879 - fold zero-equality of strcmp between a longer string and a smaller array

gcc/c-family/ChangeLog:

PR tree-optimization/90879
* c.opt (-Wstring-compare): New option.

gcc/testsuite/ChangeLog:

PR tree-optimization/90879
* gcc.dg/Wstring-compare-2.c: New test.
* gcc.dg/Wstring-compare.c: New test.
* gcc.dg/strcmpopt_3.c: Scan the optmized dump instead of strlen.
* gcc.dg/strcmpopt_6.c: New test.
* gcc.dg/strlenopt-65.c: Remove uinnecessary declarations, add
test cases.
* gcc.dg/strlenopt-66.c: Run it.
* gcc.dg/strlenopt-68.c: New test.

gcc/ChangeLog:

PR tree-optimization/90879
* builtins.c (check_access): Avoid using maxbound when null.
* calls.c (maybe_warn_nonstring_arg): Adjust to get_range_strlen change.
* doc/invoke.texi (-Wstring-compare): Document new warning option.
* gimple-fold.c (get_range_strlen_tree): Make setting maxbound
conditional.
(get_range_strlen): Overwrite initial maxbound when non-null.
* gimple-ssa-sprintf.c (get_string_length): Adjust to get_range_strlen
changes.
* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Same.
(used_only_for_zero_equality): New function.
(handle_builtin_memcmp): Call it.
(determine_min_objsize): Return an integer instead of tree.
(get_len_or_size, strxcmp_eqz_result): New functions.
(maybe_warn_pointless_strcmp): New function.
(handle_builtin_string_cmp): Call it.  Fold zero-equality of strcmp
between a longer string and a smaller array.
(get_range_strlen_dynamic): Overwrite initial maxbound when non-null.

From-SVN: r276773
17 files changed:
gcc/ChangeLog
gcc/builtins.c
gcc/c-family/ChangeLog
gcc/c-family/c.opt
gcc/calls.c
gcc/doc/invoke.texi
gcc/gimple-fold.c
gcc/gimple-ssa-sprintf.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wstring-compare-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wstring-compare.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/strcmpopt_3.c
gcc/testsuite/gcc.dg/strcmpopt_6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/strlenopt-65.c
gcc/testsuite/gcc.dg/strlenopt-66.c
gcc/testsuite/gcc.dg/strlenopt-69.c [new file with mode: 0644]
gcc/tree-ssa-strlen.c