The new -Wstrop-overflow added in r243419 fails to diagnose buffer overflows caused by calls to the stpcpy function. Looks like I missed that function. $ cat t.c && gcc -O2 -S -Wall -Wextra -Wpedantic -fdump-tree-optimized=/dev/stdout t.c char d[3]; char* f (int i) { const char *s = i < 0 ? "01234567" : "9876543210"; return __builtin_stpcpy (d, s); } ;; Function f (f, funcdef_no=0, decl_uid=1796, cgraph_uid=0, symbol_order=1) Removing basic block 3 f (int i) { const char * iftmp.0_1; char * _5; <bb 2> [100.00%]: if (i_2(D) < 0) goto <bb 4>; [32.39%] else goto <bb 3>; [67.61%] <bb 3> [67.61%]: <bb 4> [100.00%]: # iftmp.0_1 = PHI <"01234567"(2), "9876543210"(3)> _5 = __builtin_stpcpy (&d, iftmp.0_1); [tail call] return _5; }
Let me fix it.
Patch posted for review: https://gcc.gnu.org/ml/gcc-patches/2017-01/msg01994.html
Author: msebor Date: Thu May 4 20:54:43 2017 New Revision: 247618 URL: https://gcc.gnu.org/viewcvs?rev=247618&root=gcc&view=rev Log: PR preprocessor/79214 - -Wno-system-header defeats strncat buffer overflow warnings PR middle-end/79222 - missing -Wstringop-overflow= on a stpcpy overflow PR middle-end/79223 - missing -Wstringop-overflow on a memmove overflow gcc/ChangeLog: PR preprocessor/79214 PR middle-end/79222 PR middle-end/79223 * builtins.c (check_sizes): Add inlinining context and issue warnings even when -Wno-system-headers is set. (check_strncat_sizes): Same. (expand_builtin_strncat): Same. (expand_builtin_memmove): New function. (expand_builtin_stpncpy): Same. (expand_builtin): Handle memmove and stpncpy. gcc/testsuite/ChangeLog: PR preprocessor/79214 PR middle-end/79222 PR middle-end/79223 * gcc.dg/pr79214.c: New test. * gcc.dg/pr79214.h: New test header. * gcc.dg/pr79222.c: New test. * gcc.dg/pr79223.c: New test. * gcc.dg/pr78138.c: Adjust. * gfortran.dg/unconstrained_commons.f: Same. Added: trunk/gcc/testsuite/gcc.dg/pr79214.c trunk/gcc/testsuite/gcc.dg/pr79214.h trunk/gcc/testsuite/gcc.dg/pr79222.c trunk/gcc/testsuite/gcc.dg/pr79223.c Modified: trunk/gcc/ChangeLog trunk/gcc/builtins.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gcc.dg/pr78138.c trunk/gcc/testsuite/gfortran.dg/unconstrained_commons.f
Fix committed in r247618.