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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Hmm, so the issue is we're associating the memory state with a VDEF and assign
the value of a load expression based on that.  And the load expressions with
"different" TBAA are the same so we get a expression hashtable hit for the
value that was determined from a walk with different effective alias.

The not executed load invokes UB but that now leaks to the load not invoking
UB.

For this particular case it seems we can simply combine the store since
there's a must-alias.  But the testcase could be adjusted to make
*(long long *)b = 1; via a pointer that's not visibly equal and from
a non-constant and we'd get the same effect.  Likewise the read now
done via memcpy could be done via a *(long long *) access, so it does not
need to involve a ref-all:

void abort (void);
void *malloc(unsigned long);
void *memset(void *, int, unsigned long);
void *memcpy(void *, const void *, unsigned long);
int x;
long r;
long long __attribute__((noipa))
foo (unsigned char *b, unsigned char *w, long long z)
{
  memset (b, 0, 8);
  *(long long *)w = z;
  b[4] = 1;
  if (x)
    r = *(long *)b;
  return *(long long *)b;
}
int main(void) {
  unsigned char *b = malloc(8);
  long long t = foo (b, b, 1);
  if (t != 0x100000001)
    abort ();
  return 0;
}

Reply via email to