PR tree-optimization/82945 - add warning for passing non-strings to functions that...
commit0c45740b611e0930073eeae00422a17c62c2d983
authormsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 21 Nov 2017 20:01:58 +0000 (21 20:01 +0000)
committermsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 21 Nov 2017 20:01:58 +0000 (21 20:01 +0000)
treeb3eedddc82aa715ade9b6b34cd5163e5fd23b551
parent1032f688a0f36843a202a6c7628405801004c9a1
PR tree-optimization/82945 - add warning for passing non-strings to functions that expect string arguments

gcc/ChangeLog:

PR tree-optimization/82945
* builtins.c (expand_builtin_strlen): Call maybe_warn_nonstring_arg.
* calls.h (maybe_warn_nonstring_arg): Declare new function.
* calls.c (get_attr_nonstring_decl, maybe_warn_nonstring_arg): New
functions.
(initialize_argument_information): Call maybe_warn_nonstring_arg.
* calls.h (get_attr_nonstring_decl): Declare new function.
* doc/extend.texi (attribute nonstring): Update.
* gimple-fold.c (gimple_fold_builtin_strncpy): Call
get_attr_nonstring_decl and handle it.
* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Same.  Improve
detection of nul-termination.
(strlen_to_stridx): Change to a pointer.
(handle_builtin_strlen, handle_builtin_stxncpy): Adjust.
(pass_strlen::execute): Same.

gcc/testsuite/ChangeLog:

PR tree-optimization/82945
* c-c++-common/Wstringop-truncation-2.c: New test.
* c-c++-common/Wstringop-truncation.c: Adjust.
* c-c++-common/attr-nonstring-2.c: Adjust.
* c-c++-common/attr-nonstring-3.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@255031 138bc75d-0d04-0410-961f-82ee72b054a4
12 files changed:
gcc/ChangeLog
gcc/builtins.c
gcc/calls.c
gcc/calls.h
gcc/doc/extend.texi
gcc/gimple-fold.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Wstringop-truncation-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wstringop-truncation.c
gcc/testsuite/c-c++-common/attr-nonstring-2.c
gcc/testsuite/c-c++-common/attr-nonstring-3.c [new file with mode: 0644]
gcc/tree-ssa-strlen.c