[Bug tree-optimization/97474] [8/9/10/11 Regression] produces wrong code with references to another field

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Oct 19 07:49:25 GMT 2020


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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
OK, so the issue is that the C++ frontend marks 'this' as restrict which in
turn means that no other pointer can alias it.  For foo() GCC computes

  <bb 2> :
  _1 = MEM[(struct A &)a_7(D) clique 1 base 1].a;
  # PT = nonlocal escaped null 
  _2 = MEM[(struct A &)a_7(D) clique 1 base 1].b;
  _3 = MEM[(int &)_2 clique 1 base 0]; 
  _4 = _1 * _3; 
  MEM[(struct A &)a_7(D) clique 1 base 1].a = _4;
  # PT = nonlocal escaped null  
  _5 = MEM[(struct A &)a_7(D) clique 1 base 1].b;
  _9 = MEM[(int &)_5 clique 1 base 0]; 
  return _9;

in particular

a_7(D), points-to NULL, points-to vars: { D.2410 } (nonlocal, restrict)
_5, points-to non-local, points-to escaped, points-to NULL, points-to vars: { }

and thus the load of _9 via _5 does not alias the store via a_7.  Basically,
GCC does not consider storage pointed to by a restrict pointer to point to
itself (what the CTOR does - make b refer to its own a).

It's not difficult to fix this - simply amend the constraints:

a = &PARM_NOALIAS(9)
PARM_NOALIAS(9) = &NONLOCAL

also have

PARM_NOALIAS(9) = &PARM_NOALIAS(9)

the question is whether this generally applies to restrict qualified pointers.
In some sense for

 A * restrict p;
 int *q = p->b;

q is derived from p.


More information about the Gcc-bugs mailing list