https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103768
Bug ID: 103768 Summary: array-bounds warning for `memcpy((void*)0x1234, p, n)`, where n is greater than 8 Product: gcc Version: 11.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: pmenzel+gcc at molgen dot mpg.de Target Milestone: --- In the SeaBIOS list thread *[PATCH] memmap: Fix gcc out-of-bounds warning* [1], the array out of bounds warning below from at least GCC 11.2.0 is discussed: ``` In file included from src/fw/smm.c:18: src/fw/smm.c: In function 'smm_save_and_copy': src/string.h:23:16: warning: '__builtin_memcpy' offset [0, 511] is out of the bounds [0, 0] [-Warray-bounds] 23 | #define memcpy __builtin_memcpy src/fw/smm.c:148:5: note: in expansion of macro 'memcpy' 148 | memcpy(&smm->cpu, &initsmm->cpu, sizeof(smm->cpu)); | ^~~~~~ src/fw/smm.c: In function 'smm_relocate_and_restore': src/string.h:23:16: warning: '__builtin_memcpy' offset [0, 511] is out of the bounds [0, 0] [-Warray-bounds] 23 | #define memcpy __builtin_memcpy src/fw/smm.c:171:5: note: in expansion of macro 'memcpy' 171 | memcpy(&initsmm->cpu, &smm->cpu, sizeof(initsmm->cpu)); | ^~~~~~ src/fw/smm.c: In function 'handle_smi': src/string.h:23:16: warning: '__builtin_memcpy' offset [0, 511] is out of the bounds [0, 0] [-Warray-bounds] 23 | #define memcpy __builtin_memcpy src/fw/smm.c:88:13: note: in expansion of macro 'memcpy' 88 | memcpy(&newsmm->backup1, &smm->cpu, sizeof(newsmm->backup1)); | ^~~~~~ src/string.h:23:16: warning: '__builtin_memcpy' offset [0, 511] is out of the bounds [0, 0] [-Warray-bounds] 23 | #define memcpy __builtin_memcpy src/fw/smm.c:89:13: note: in expansion of macro 'memcpy' 89 | memcpy(&newsmm->backup2, &smm->cpu, sizeof(newsmm->backup2)); | ^~~~~~ ``` Kevin writes: > Yes - I see that as well in smm.c. Alas, I don't have a fix for it. > It seems to me that gcc is producing bogus warnings here. It looks > like anything of the form "memcpy((void*)0x1234, p, n)" where n is > greater than 8 produces this warning. It's a requirement to memcpy to > a physical memory address. Disabling the warning would require adding > both "-Wno-array-bounds -Wno-stringop-overflow" to the build. > > Maybe someone else has an idea on how to suppress this warning. The SeaBIOS source code is available in a git repository [2]. `make olddefconfig && make -j$(nproc)` reproduces the warning. [1]: https://mail.coreboot.org/hyperkitty/list/seab...@seabios.org/thread/KCV5A4GZQDFNANU7QZYR4Y6ZNFGMEJQN/ [2]: https://review.coreboot.org/plugins/gitiles/seabios/+/refs/tags/rel-1.15.0/src/fw/smm.c#148