[Bug middle-end/104965] [11/12 Regression] Yet another -Warray-bounds false positive

2022-04-21 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104965

Richard Biener  changed:

   What|Removed |Added

   Target Milestone|11.3|11.4

--- Comment #5 from Richard Biener  ---
GCC 11.3 is being released, retargeting bugs to GCC 11.4.

[Bug middle-end/104965] [11/12 Regression] Yet another -Warray-bounds false positive

2022-03-17 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104965

--- Comment #4 from Andrew Pinski  ---
I think the missed optimization is recorded as either PR 79349 or PR 103827.

[Bug middle-end/104965] [11/12 Regression] Yet another -Warray-bounds false positive

2022-03-17 Thread msebor at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104965

Martin Sebor  changed:

   What|Removed |Added

 CC||msebor at gcc dot gnu.org

--- Comment #3 from Martin Sebor  ---
It looks like an escape analysis limitation.  With this simpler test case using
different types to rule out aliasing assumptions:

#include 

int main()
{
  std::basic_string s;
  auto p = new int[s.size ()]{ };
  char c = 0;
  if (s.size())
c = *p;
  delete[] p;
  return c;
}

pr104965.C:9:9: warning: array subscript 0 is outside array bounds of ‘void
[0]’ [-Warray-bounds]
9 | c = *p;
  | ^~
pr104965.C:6:34: note: object of size 0 allocated by ‘operator new []’
6 |   auto p = new short[s.size ()]{ };
  |  ^

One of the stores to the local s escapes its address which is then assumed to
have been clobbered by operator new:

   [local count: 1073741824]:
  s ={v} {CLOBBER};
  MEM[(struct _Alloc_hider *)] ={v} {CLOBBER};
  MEM[(struct _Alloc_hider *)]._M_p = _M_local_buf;
  s._M_string_length = 0;
  MEM[(char_type &) + 16] = 0;
  _5 = operator new [] (0);

   [local count: 1073741824]:
  _10 = s._M_string_length;
  if (_10 != 0)
goto ; [50.00%]
  else
goto ; [50.00%]

   [local count: 536870913]:
  _1 = MEM[(int *)_5];
  c_6 = (char) _1;

[Bug middle-end/104965] [11/12 Regression] Yet another -Warray-bounds false positive

2022-03-17 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104965

--- Comment #2 from Jonathan Wakely  ---
In this case s.size() reads a local variable that can't be altered by new.

[Bug middle-end/104965] [11/12 Regression] Yet another -Warray-bounds false positive

2022-03-17 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104965

Richard Biener  changed:

   What|Removed |Added

   Target Milestone|--- |11.3

--- Comment #1 from Richard Biener  ---
Likely a similar issue as PR104966, avoid relying on memory CSE across a call
to 'new'.