1 /* Test whether strncmp has not been "optimized" into memcmp
2    nor any code with memcmp semantics.  */
3 /* { dg-do run { target mmap } } */
4 /* { dg-options "-O2" } */
5 #include <stddef.h>
6 #include <stdio.h>
7 #include <sys/mman.h>
8 #ifndef MAP_ANONYMOUS
9 #define MAP_ANONYMOUS MAP_ANON
10 #endif
11 #ifndef MAP_ANON
12 #define MAP_ANON 0
13 #endif
14 #ifndef MAP_FAILED
15 #define MAP_FAILED ((void *)-1)
16 #endif
17 #include <stdlib.h>
18 
test(const char * p)19 void __attribute__((noinline)) test (const char *p)
20 {
21   if (__builtin_strncmp (p, "abcdefghijklmnopq", 17) == 0)
22     abort ();
23 }
24 
main(void)25 int main (void)
26 {
27   char *p = mmap (NULL, 131072, PROT_READ | PROT_WRITE,
28                   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
29   if (p == MAP_FAILED)
30     return 0;
31   if (munmap (p + 65536, 65536) < 0)
32     return 0;
33   __builtin_memcpy (p + 65536 - 5, "abcd", 5);
34   test (p + 65536 - 5);
35   return 0;
36 }
37