https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122073
Bug ID: 122073
Summary: Bogus -Wstringop-overread with [[gnu::nonstring]] and
type punning
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: xry111 at gcc dot gnu.org
Target Milestone: ---
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];
| ^