https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117482
Bug ID: 117482 Summary: Bogus -Wstringop-overflow warning in intrusive list implementation Product: gcc Version: 14.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: adam at adamrosenfield dot com Target Milestone: --- Created attachment 59555 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59555&action=edit Test file exhibiting the bogus -Wstringop-overflow warning In the attached code, we have an intrusive linked list implementation that generates bogus -Wstringop-overflow warning. Compile as: ``` $ gcc -c bug.c -Wall -O3 bug.c: In function ‘foo’: bug.c:55:10: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] 55 | x->a = 0; | ~~~~~^~~ ``` This occurs in every GCC version since 12.1. This occurs at -O2 and -O3, but not at -O1 or -Os. It's fairly sensitive to local code changes. If the `x->a` member is read from instead of written into, it doesn't trigger. If there's another access of `x->a` prior to the write, it doesn't trigger. If the type of `a` is changed to a type with any other size (short/int/long long/etc.), it doesn't trigger. If other fields are added or removed, or if the type of the `head` field as changed, it doesn't trigger. I've found a number of other -Wstringop-overflow bugs related to from the metabug at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=Wstringop-overflow, and I looked through some of them, but I haven't exhaustively checked them all since there are so many. If this is a duplicate of an existing issue, please feel free to link this & resolve as a duplicate if needed.