https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578
--- Comment #16 from Martin Sebor <msebor at gcc dot gnu.org> ---
It's the pointer itself that needs to be volatile to keep GCC from determining
its value. This shows the difference:
$ cat pr99578-15.c && gcc -O2 -S -Wall pr99578-15.c
void f (void)
{
void* ptr = (void *)0x00007ffffffffff8ul;
__builtin_memcpy (ptr, "\x90\x90\xf\xbxen\x90", 8); // warning
}
void g (void)
{
void* volatile ptr = (void *)0x00007ffffffffff8ul;
__builtin_memcpy (ptr, "\x90\x90\xf\xbxen\x90", 8); // okay
}
pr99578-15.c: In function ‘f’:
pr99578-15.c:4:3: warning: ‘__builtin_memcpy’ offset [0, 7] is out of the
bounds [0, 0] [-Warray-bounds]
4 | __builtin_memcpy (ptr, "\x90\x90\xf\xbxen\x90", 8); // warning
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Alternatively, store the address a global (modifiable) variable.