https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92765
--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Testcase showing wrong-code with the __builtin_strcmp_eq stuff (assuming the
testcase is considered valid):
/* { dg-do run { target mmap } } */
/* { dg-options "-O2" } */
#include <stdlib.h>
#include <sys/mman.h>
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif
#ifndef MAP_ANON
#define MAP_ANON 0
#endif
#ifndef MAP_FAILED
#define MAP_FAILED ((void *)-1)
#endif
union U { struct T { char a[2]; char b[4094]; } c; struct S { char d[4]; int e;
} f; };
__attribute__((noipa)) void
bar (char *p)
{
asm volatile ("" : : "g" (p) : "memory");
}
__attribute__((noipa)) int
foo (union U *p)
{
bar ((char *) &p->c.b);
return __builtin_strcmp (&p->f.d[2], "abcdefghijk") == 0;
}
int
main ()
{
char *p = mmap (NULL, 131072, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED)
return 0;
if (munmap (p + 65536, 65536) < 0)
return 0;
union U *u;
u = (union U *) (p + 65536 - sizeof (u->f));
__builtin_memcpy (u->f.d, "abc", 4);
u->f.e = 1;
if (foo (u) != 0)
__builtin_abort ();
return 0;
}