https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123275
Bug ID: 123275
Summary: Spurious warning: array subscript 0 is outside array
bounds of ‘void[0]’
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: ubizjak at gmail dot com
Target Milestone: ---
The following testcase, when compiled with -O2 -Wall reports:
--cut here--
typedef unsigned short u16;
#define OLD_CL_ADDRESS 0x020
# define RELOC_HIDE(ptr, off) \
({ unsigned long __ptr; \
__ptr = (unsigned long) (ptr); \
(typeof(ptr)) (__ptr + (off)); })
#define absolute_pointer(val) RELOC_HIDE((void *)(val), 0)
u16 foo (void)
{
struct old_cmdline
{
u16 cl_magic;
u16 cl_offset;
};
const struct old_cmdline * const oldcmd = absolute_pointer (OLD_CL_ADDRESS);
return oldcmd->cl_magic;
}
--cut here--
rr.c: In function ‘foo’:
rr.c:22:16: warning: array subscript 0 is outside array bounds of ‘void[0]’
[-Warray-bounds=]
22 | return oldcmd->cl_magic;
| ^~
cc1: note: source object is likely at address zero
The code is from linux arch/x86/boot/main.c