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

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Example where the new code gets it all wrong
struct S { char a; int b; char c; unsigned d; };
struct T { char t; struct S u; int v; };
typedef short U[2][2];
void baz (U *);

static inline int
bar (char *p)
{
  return *(int *) p;
}

void
foo (int *q)
{
  struct T t;
  t.t = 1;
  t.u.c = 2;
  char *p = (char *) &t;
  q[0] = bar (p + __builtin_offsetof (struct T, u.b));
  q[1] = bar (p + __builtin_offsetof (struct T, u.d));
  q[2] = bar (p + __builtin_offsetof (struct T, v));
  int s[3];
  s[0] = 1;
  char *r = (char *) s;
  q[3] = bar (r + sizeof (int));
  U u[2], v[2];
  u[0][0][0] = 1;
  __builtin_memcpy (&v[1], &u[1], sizeof (U));
  baz (&v[1]);
}

It is true that old MEM_REF printing wasn't correct either:
test.c:19:8: warning: ‘*((void *)&t+8)’ is used uninitialized in this function
[-Wuninitialized]
test.c:20:8: warning: ‘*((void *)&t+16)’ is used uninitialized in this function
[-Wuninitialized]
test.c:21:8: warning: ‘*((void *)&t+20)’ is used uninitialized in this function
[-Wuninitialized]
test.c:25:8: warning: ‘*((void *)&s+4)’ is used uninitialized in this function
[-Wuninitialized]
test.c:28:3: warning: ‘*((void *)&u+8)’ is used uninitialized in this function
[-Wuninitialized]
- it would have been ugly but correct if it used char * instead of void * and
then added another cast to the MEM_REF type.
The new code prints:
test.c:19:8: warning: ‘((int*)t) + 2’ is used uninitialized [-Wuninitialized]
test.c:20:8: warning: ‘((int*)t) + 4’ is used uninitialized [-Wuninitialized]
test.c:21:8: warning: ‘((int*)t) + 5’ is used uninitialized [-Wuninitialized]
test.c:25:8: warning: ‘s + 1’ is used uninitialized [-Wuninitialized]
test.c:28:3: warning: ‘((long unsigned int*)u) + 1’ is used uninitialized
[-Wuninitialized]
Huh!  (int*)t is invalid C (in C++ perhaps there could be an operator for it),
and the result is a pointer anyway.  s + 1 is valid, but again s + 1 is not
uninitialized, it is s[1].  Similarly for u.

Reply via email to