https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111049
Bug ID: 111049 Summary: spurious stringop-overflow depending on structure pointer arithmetic with certain sized structures Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: mark at infocomm dot com Target Milestone: --- Created attachment 55746 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55746&action=edit C source that demonstrates the problem These warnings are incorrectly reported and have somewhat meaningless content: In function ‘xxx_set_array’, inlined from ‘xxx_b’ at ptr_diff_err.c:177:5: ptr_diff_err.c:189:23: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] 189 | xxx_array[u][l++] = (code >> i) & 1; | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ ptr_diff_err.c: In function ‘xxx_b’: ptr_diff_err.c:94:16: note: at offset [-10324440, 10324440] to object ‘xxx_array’ with size 3192 declared here 94 | static uint8_t xxx_array[2][1596]; | ^~~~~~~~~ In function ‘xxx_set_array’, inlined from ‘xxx_b’ at ptr_diff_err.c:177:5: ptr_diff_err.c:189:23: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] 189 | xxx_array[u][l++] = (code >> i) & 1; | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ ptr_diff_err.c: In function ‘xxx_b’: ptr_diff_err.c:94:16: note: at offset 0 to object ‘xxx_array’ with size 3192 declared here 94 | static uint8_t xxx_array[2][1596]; | ^~~~~~~~~ In function ‘xxx_set_array’, inlined from ‘xxx_b’ at ptr_diff_err.c:177:5: ptr_diff_err.c:189:23: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] 189 | xxx_array[u][l++] = (code >> i) & 1; | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ ptr_diff_err.c: In function ‘xxx_b’: What does "offset [-10324440, 10324440] to object" mean? What does "a region of size 0" mean? This occurs with: gcc (Raspbian 10.2.1-6+rpi1) 10.2.1 20210110 On: Linux raspberrypi 6.1.21-v7+ #1642 SMP Mon Apr 3 17:20:52 BST 2023 armv7l GNU/Linux These warnings only happen when compiling with -O2 These warnings only happen when the value u mentioned on line 189 is produced by simple pointer arithmetic between elements of the same array of structures. They ONLY happen when the structure has certain sizes and not when that structure has other sizes. The attached source file can be compiled to demonstrate the problem with different sized structures. See comments at the top of the attach example file which describe how to change the compile time structure size with -DSTR_EXTRAS= and which values generate the messages and which values do not.