Message ID | 1dd822ca-f566-2bb7-428b-a7e11b7afac3@gmail.com |
---|---|
State | New |
Headers | show |
Series | issue nonstring warning for strcpy even on s360 (PR 85369) | expand |
Ping: https://gcc.gnu.org/ml/gcc-patches/2018-04/msg00649.html Andreas, I assumed you wanted to include a fix for this in GCC 8. I'm not sure if this is something you can/should approve as one of the s360 maintainers or if it needs to be approved by someone else (e.g., Jeff). As a heads up, I'm travelling the next two weeks and will only have a limited time to commit patches. Martin On 04/12/2018 06:00 PM, Martin Sebor wrote: > PR 85369 notes that the c-c++-common/attr-nonstring-3.c fails > on IBM Z (and other similar targets) whose back-end provides > the movstr expander. The failure is cause by an expected > warning failing to trigger because the strcpy call is expanded > early and the checker never runs. > > The attached patch adjusts the code to make sure the warning > is not bypassed on these targets. > > I've verified the patch with an s390-linux cross-compiler and > with a full x86_64-linux native build and regression run. > > Martin
On 04/12/2018 06:00 PM, Martin Sebor wrote: > PR 85369 notes that the c-c++-common/attr-nonstring-3.c fails > on IBM Z (and other similar targets) whose back-end provides > the movstr expander. The failure is cause by an expected > warning failing to trigger because the strcpy call is expanded > early and the checker never runs. > > The attached patch adjusts the code to make sure the warning > is not bypassed on these targets. > > I've verified the patch with an s390-linux cross-compiler and > with a full x86_64-linux native build and regression run. > > Martin > > gcc-85369.diff > > > PR middle-end/85369 - no -Wstringop-overflow for a strcpy / stpcpy call with a nonstring pointer when providing movstr pattern > > gcc/ChangeLog: > > PR middle-end/85369 > * builtins.c (expand_builtin_strcpy_1): New function. Patch actually introduced expand_builtin_stpcpy_1, not expand_builtin_strcpy_1. > (expand_builtin_stpcpy): Call it, and call maybe_warn_nonstring_arg > only if the former succeeds. OK with ChangeLog nit fixed. jeff
PR middle-end/85369 - no -Wstringop-overflow for a strcpy / stpcpy call with a nonstring pointer when providing movstr pattern gcc/ChangeLog: PR middle-end/85369 * builtins.c (expand_builtin_strcpy_1): New function. (expand_builtin_stpcpy): Call it, and call maybe_warn_nonstring_arg only if the former succeeds. diff --git a/gcc/builtins.c b/gcc/builtins.c index b751a4b..f681488 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -3808,7 +3808,7 @@ expand_builtin_strcpy_args (tree dest, tree src, rtx target) mode MODE if that's convenient). */ static rtx -expand_builtin_stpcpy (tree exp, rtx target, machine_mode mode) +expand_builtin_stpcpy_1 (tree exp, rtx target, machine_mode mode) { tree dst, src; location_t loc = EXPR_LOCATION (exp); @@ -3885,6 +3885,25 @@ expand_builtin_stpcpy (tree exp, rtx target, machine_mode mode) } } +/* Expand a call EXP to the stpcpy builtin and diagnose uses of nonstring + arguments while being careful to avoid duplicate warnings (which could + be issued if the expander were to expand the call, resulting in it + being emitted in expand_call(). */ + +static rtx +expand_builtin_stpcpy (tree exp, rtx target, machine_mode mode) +{ + if (rtx ret = expand_builtin_stpcpy_1 (exp, target, mode)) + { + /* The call has been successfully expanded. Check for nonstring + arguments and issue warnings as appropriate. */ + maybe_warn_nonstring_arg (get_callee_fndecl (exp), exp); + return ret; + } + + return NULL_RTX; +} + /* Check a call EXP to the stpncpy built-in for validity. Return NULL_RTX on both success and failure. */