[Bug tree-optimization/86265] Wrong code on an invalid code starting with r255790
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jun 26 17:53:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86265
--- Comment #8 from Martin Sebor <msebor at gcc dot gnu.org> ---
I would expect the additional detail (about the structure of data) to only help
improve things, not ever make them worse, or introduce bugs into correct code.
But relying on the structure of data is not novel -- the ability is an
important part of the language, and GCC already takes advantage of it in some
cases. For instance, it eliminates the test below:
struct S { char a[4]; int b; char c[1]; };
void f (struct S *s, int i)
{
int c = s->c[0];
s->a[i] = 'a';
if (c != s->c[0])
__builtin_abort ();
}
even though calling f() with i set to offsetof (struct S, c) writes 'a' into
s->c.
GCC doesn't yet eliminate the test when the write is by a built-in like
memcpy() or strcpy() but there is no reason for it not to.
More information about the Gcc-bugs
mailing list