struct [[gnu::may_alias]] A { [[gnu::nonstring]] char x[4]; }; struct B { [[gnu::nonstring]] char x[2]; }; void f (struct B *p) { if (!__builtin_strncmp (p->x, "AA", 2)) ; else if (!__builtin_strncmp (((struct A *)p)->x, "BBCC", 4)) asm (""); } results in a warning which does not make any sense (to me): t1.c: In function 'f': t1.c:16:13: warning: '__builtin_strncmp' argument 1 declared attribute 'nonstring' is smaller than the specified bound 4 [-Wstringop-overread] 16 | else if (!__builtin_strncmp (((struct A *)p)->x, "BBCC", 4)) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ t1.c:8:27: note: argument 'x' declared here 8 | [[gnu::nonstring]] char x[2]; | ^
This is 99% a dup of a different bug dealing with addr_expr being merged to be the same since they point to the same location but this warning requires the non merging of the addr_expr.
Yes https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118232#c4