https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108817

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Here we prove that 'return c' only depends on the last execution of 'c =
b[a+1];' which is going to happen with a == 0 and thus we optimize out that.

$ gcc pr108817.C -fsanitize=address -O3 -fdump-tree-optimized=/dev/stdout

int main ()
{
  signed char _4;
  unsigned long _8;
  int _12;
  unsigned long _15;
  bool _16;
  unsigned long _18;
  int _19;
  char _20;
  bool _21;
  signed char _22;
  signed char _23;
  unsigned long _25;
  signed char * _27;
  bool _38;

  <bb 2> [local count: 26541933]:
  a = 2;
  _15 = (unsigned long) &MEM <int> [(void *)&b + 4B];
(checking if &b + 4 is valid in shadow memory) 
  if (_16 != 0)
    goto <bb 3>; [0.05%]
  else
    goto <bb 4>; [99.95%]

  <bb 3> [local count: 13271]:
  __builtin___asan_report_load4 (_15);

  <bb 4> [local count: 26541933]:
  _19 = b[1]; <- here we use it as the future value
  _20 = (char) _19;
  c = _20;
  a = -1;
  _12 = (int) _20;
  return _12;
}

Final note: note clang does not report the issue even with -O1.

Reply via email to