diff options
author | Martin Sebor <msebor@redhat.com> | 2017-11-21 20:01:58 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2017-11-21 13:01:58 -0700 |
commit | 6a33d0ff21e941fc3a65f23a753cc318aaae82b5 (patch) | |
tree | b3eedddc82aa715ade9b6b34cd5163e5fd23b551 /gcc/builtins.c | |
parent | ab2c4ec8dcbe5d0b93d0250abd42ff9fb791e0b6 (diff) | |
download | gcc-6a33d0ff21e941fc3a65f23a753cc318aaae82b5.zip gcc-6a33d0ff21e941fc3a65f23a753cc318aaae82b5.tar.gz gcc-6a33d0ff21e941fc3a65f23a753cc318aaae82b5.tar.bz2 |
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.
From-SVN: r255031
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index 650de0d..b974459 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -2885,6 +2885,11 @@ expand_builtin_strlen (tree exp, rtx target, if (!maybe_expand_insn (icode, 4, ops)) return NULL_RTX; + /* Check to see if the argument was declared attribute nonstring + and if so, issue a warning since at this point it's not known + to be nul-terminated. */ + maybe_warn_nonstring_arg (TREE_OPERAND (CALL_EXPR_FN (exp), 0), exp); + /* Now that we are assured of success, expand the source. */ start_sequence (); pat = expand_expr (src, src_reg, Pmode, EXPAND_NORMAL); |