https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85623
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2018-05-08 Ever confirmed|0 |1 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- Confirmed with the simpler test case below. GCC transforms the strncmp() call to strcmp() because it can see that the bound is larger than the length of one of the arguments but the warning doesn't consider this case (i.e., it triggers even when the strcmp call cannot read past the end of the non-string array. $ cat b.c && gcc -O2 -S -Wall b.c extern __attribute__((nonstring)) char a[4]; int f (const char *s) { return __builtin_strcmp (a, "12"); } b.c: In function ‘f’: b.c:5:10: warning: ‘__builtin_strcmp’ argument 1 declared attribute ‘nonstring’ [-Wstringop-overflow=] return __builtin_strcmp (a, "12"); ^~~~~~~~~~~~~~~~~~~~~~~~~~ b.c:1:40: note: argument ‘a’ declared here extern __attribute__((nonstring)) char a[4]; ^