2018-05-15 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / pr55430.c
blobac56cacea5a861c05a136f23683a9c21961020cc
1 /* PR middle-end/55430 */
2 /* { dg-do run { target mmap } } */
3 /* { 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>
19 struct S
21 unsigned int s1 : 8;
22 unsigned int s2 : 2;
25 __attribute__((noinline, noclone)) int
26 foo (int x, int y, struct S *z, unsigned int w)
28 if (z[y].s2 == x && z[y].s1 == w)
29 return 1;
30 return 0;
33 int
34 main ()
36 char *p = mmap (NULL, 131072, PROT_READ | PROT_WRITE,
37 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
38 if (p == MAP_FAILED)
39 return 0;
40 if (munmap (p + 65536, 65536) < 0)
41 return 0;
42 if ((65536 / sizeof (struct S)) * sizeof (struct S) != 65536)
43 return 0;
44 struct S *s = (struct S *) (p + 65536);
45 return foo (0, 0, s - 1, 0) != 1;