[Bug middle-end/87296] [8/9 Regression] -Wstringop-overflow false positive due to bogus MEM_REF type
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Nov 23 17:56:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87296
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The MEM_REF type is significant only when actually accessing that memory, for
&MEM_REF[...]; it is insignificant and you really shouldn't assume anything
from it except for the address computation (like if it was _7 + 4).
Not really sure why we don't just fold &MEM_REF[x, y] to x p+ y though if x is
SSA_NAME.
Another example:
struct S { char a[4]; char b[6]; char c[2]; };
struct T { char a[10]; char b[4]; char c[2]; };
union U { struct S s; struct T t; };
void bar (union U *);
void baz (char *, char *, char *);
void
foo (union U *u)
{
char (*q)[4] = &u->s.a;
q++;
baz ((char *) q, &u->s.b[2], &u->s.b[6]);
bar (u);
__builtin_strncpy (&u->t.a[4], "abcdef", 6);
}
Because pointer conversions are useless, one pointer can be replaced for
another one which has provenly the same value, but might point to different
fields etc.
More information about the Gcc-bugs
mailing list