Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/gcc.dg/pr83047.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* PR tree-optimization/83047 */ | |
2 /* { dg-do run { target mmap } } */ | |
3 /* { dg-options "-O2" } */ | |
4 | |
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 | |
19 __attribute__((noipa)) void | |
20 foo (char *p, char *q, int r) | |
21 { | |
22 char a = q[0]; | |
23 if (r || a == '\0') | |
24 return; | |
25 char b = q[1]; | |
26 p[0] = a; | |
27 p[1] = b; | |
28 } | |
29 | |
30 int | |
31 main () | |
32 { | |
33 char *p = mmap (NULL, 131072, PROT_READ | PROT_WRITE, | |
34 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | |
35 if (p == MAP_FAILED) | |
36 return 0; | |
37 if (munmap (p + 65536, 65536) < 0) | |
38 return 0; | |
39 p[0] = 'c'; | |
40 p[1] = 'd'; | |
41 p[65536 - 2] = 'a'; | |
42 p[65536 - 1] = 'b'; | |
43 volatile int r = 1; | |
44 foo (p, p + 65536 - 2, r); | |
45 if (p[0] != 'c' || p[1] != 'd') | |
46 abort (); | |
47 r = 0; | |
48 foo (p, p + 65536 - 2, r); | |
49 if (p[0] != 'a' || p[1] != 'b') | |
50 abort (); | |
51 p[0] = 'e'; | |
52 p[1] = 'f'; | |
53 r = 1; | |
54 foo (p, p + 65536 - 1, r); | |
55 if (p[0] != 'e' || p[1] != 'f') | |
56 abort (); | |
57 return 0; | |
58 } |