https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87901
--- Comment #2 from Richard Biener ---
(In reply to Martin Sebor from comment #1)
> The example is undefined -- it forms a past the-end pointer -- and
> -Warray-bounds detects it:
>
> warning: array subscript 2 is outside array bounds of ‘int[1]’
> [-Warray-bounds]
> 6 | *((short *) + sizeof (int) - sizeof (short)) = 1;
>
> I don't suppose you meant to do that, but presumably meant to access a part
> of the object. But even then the code is undefined.
>
> Can you explain/clarify what you have in mind and why it's important?
Whoops - should be + 2 - 1 (was char * before I made it to shorts).
int i;
void foo ()
{
i = 0;
*((short *) + 1) = 1;
}
the original motivation is from 36602 patch regressions. When transforming
char z[32];
int
foo(void)
{
memset (z, 0, 16);
memset (z+8, 0, 24);
}
to
int
foo(void)
{
MEM[] = 0;
MEM[+8] = {};
}
DSE doesn't know to adjust the = 0 store (and likely not a = {} store if it
were first).
I first wanted to construct an example with unions...