diff options
author | Martin Sebor <msebor@redhat.com> | 2018-05-22 19:37:48 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2018-05-22 13:37:48 -0600 |
commit | 36537a1c41adabc6da23ae19e7c3a933582b19dd (patch) | |
tree | a8f5351bc207a35be81c86a6e2470a214629639e /gcc/builtins.c | |
parent | aab778d3825052d262e3fc6d87af67e7cc196273 (diff) | |
download | gcc-36537a1c41adabc6da23ae19e7c3a933582b19dd.zip gcc-36537a1c41adabc6da23ae19e7c3a933582b19dd.tar.gz gcc-36537a1c41adabc6da23ae19e7c3a933582b19dd.tar.bz2 |
PR middle-end/85359 - duplicate -Wstringop-overflow for a strcmp call with a nonstring pointer
gcc/ChangeLog:
PR middle-end/85359
* builtins.c (expand_builtin_strcpy): Call maybe_warn_nonstring_arg
only when expasion succeeds.
(expand_builtin_strcmp): Same.
(expand_builtin_strncmp): Same.
gcc/testsuite/ChangeLog:
PR middle-end/85359
* gcc.dg/attr-nonstring.c: New test.
From-SVN: r260550
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index 9a2bf8c..841c1ef 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -3783,7 +3783,17 @@ expand_builtin_strcpy (tree exp, rtx target) src, destsize); } - return expand_builtin_strcpy_args (dest, src, target); + if (rtx ret = expand_builtin_strcpy_args (dest, src, target)) + { + /* 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. */ + tree fndecl = get_callee_fndecl (exp); + maybe_warn_nonstring_arg (fndecl, exp); + return ret; + } + + return NULL_RTX; } /* Helper function to do the actual work for expand_builtin_strcpy. The @@ -4576,14 +4586,14 @@ expand_builtin_strcmp (tree exp, ATTRIBUTE_UNUSED rtx target) } } - /* 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. */ tree fndecl = get_callee_fndecl (exp); - maybe_warn_nonstring_arg (fndecl, exp); - if (result) { + /* 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 (fndecl, exp); + /* Return the value in the proper mode for this function. */ machine_mode mode = TYPE_MODE (TREE_TYPE (exp)); if (GET_MODE (result) == mode) @@ -4680,14 +4690,14 @@ expand_builtin_strncmp (tree exp, ATTRIBUTE_UNUSED rtx target, arg2_rtx, TREE_TYPE (len), arg3_rtx, MIN (arg1_align, arg2_align)); - /* 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. */ tree fndecl = get_callee_fndecl (exp); - maybe_warn_nonstring_arg (fndecl, exp); - if (result) { + /* 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 (fndecl, exp); + /* Return the value in the proper mode for this function. */ mode = TYPE_MODE (TREE_TYPE (exp)); if (GET_MODE (result) == mode) |