[Bug tree-optimization/87901] partial DSE of memset doesn't work for other kind of stores

2018-11-07 Thread rguenth at gcc dot gnu.org
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...

[Bug tree-optimization/87901] partial DSE of memset doesn't work for other kind of stores

2018-11-06 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87901

Martin Sebor  changed:

   What|Removed |Added

 CC||msebor at gcc dot gnu.org

--- Comment #1 from Martin Sebor  ---
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?