https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99159
Bug ID: 99159 Summary: Confusing -Warray-bounds warning Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: sirl at gcc dot gnu.org Target Milestone: --- Hi, with this minimized testcase, compiled with -O2 -Warray-bounds: struct s1 { char b[12]; }; struct s2 { int x; struct s1 y; } *pb, c; extern struct s2 *es; void test1 (int f) { struct s2 *p = f ? 0 : es; __builtin_memcpy (&pb->y, p->y.b, sizeof(struct s1)); } void test2 () { struct s2 *p = 0; __builtin_memcpy (&pb->y, p->y.b, sizeof(struct s1)); } trunk@r11-7270 warns like this: testcase.c: In function 'test2': testcase.c:23:3: warning: '__builtin_memcpy' offset [0, 11] is out of the bounds [0, 0] [-Warray-bounds=] 23 | __builtin_memcpy (&pb->y, p->y.b, sizeof(struct s1)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I believe -Warray-bounds shouldn't warn here (or at least not with this message) and gcc-10.2 and also trunk@r11-3693 don't. Note that the real code is more like test1(), where it's not clear that 'p' is always zero.