https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82612
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
But we are not even having an ARRAY_REF in the IL ...
So try
int g (int i)
{
int (*p)[2] = (int (*)[2])&i;
return (*p)[2];
}
where we also do not warn. Or the VLA variant:
int g (int i, int n)
{
int (*p)[n] = (int (*)[n])&i;
return (*p)[2];
}
Basically the warning code blindly trusts the ARRAY_TYPE domain even if
there's an underlying decl where that array wouldn't fit. So the warning
you are requesting is more an out-of-bound object access in general.
To warn for this substitute each variable offset with its minimum range
value, call get_ref_base_and_extent and see if offset/size are within
the base object.