https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83373
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |diagnostic, | |missed-optimization Status|UNCONFIRMED |NEW Last reconfirmed| |2017-12-11 CC| |msebor at gcc dot gnu.org See Also| |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=78450 Ever confirmed|0 |1 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- Confirmed. The warning is caused by a missed optimization opportunity in the strlen pass. GCC doesn't recognize that the result of a strlen() call with an array argument must be less than the size of the array and, as a result, doesn't eliminate the else block in my_strcpy(). The warning then sees the memcpy(dst, src, 99) call and complains. Here's a small test case for the missing strlen optimization. This is the subject of pr78450. $ cat d.c && gcc -O2 -S -Wall -Wextra -Wpedantic -fdump-tree-optimized=/dev/stdout d.c void init (void*); void f (void) { char a[20]; init (a); if (__builtin_strlen (a) < 20) // must be true return; __builtin_abort (); // can be eliminated } ;; Function f (f, funcdef_no=0, decl_uid=1894, cgraph_uid=0, symbol_order=0) f () { char a[20]; long unsigned int _1; <bb 2> [local count: 1073741825]: init (&a); _1 = __builtin_strlen (&a); if (_1 <= 19) goto <bb 3>; [99.96%] else goto <bb 4>; [0.00%] <bb 3> [local count: 1073312327]: a ={v} {CLOBBER}; return; <bb 4> [count: 0]: __builtin_abort (); // not eliminated but could be }