View | Details | Return to bug 21862
Collapse All | Expand All

(-)gcc/testsuite/gcc.c-torture/execute/loop-2h.c.jj (+74 lines)
Line 0 Link Here
1
#include <limits.h>
2
#include <stdlib.h>
3
4
#ifdef __unix__ /* ??? Is that good enough? */
5
#include <sys/types.h>
6
#include <sys/mman.h>
7
#include <sys/stat.h>
8
#include <fcntl.h>
9
#ifndef MAP_ANON
10
#ifdef MAP_ANONYMOUS
11
#define MAP_ANON MAP_ANONYMOUS
12
#else
13
#define MAP_ANON MAP_FILE
14
#endif
15
#endif
16
#ifndef MAP_FILE
17
#define MAP_FILE 0
18
#endif
19
#ifndef MAP_FIXED
20
#define MAP_FIXED 0
21
#endif
22
#endif
23
24
#define MAP_START (void *)0x7fff8000
25
#define MAP_LEN (1 << 16)
26
27
static char *c, *e;
28
29
int __attribute__((noinline))
30
g (int i, char *p, int s)
31
{
32
33
  if ((c && (p != c || p >= e)) || s != 0x100)
34
    abort ();
35
  if (c)
36
    c += 0x100;
37
  else
38
    {
39
      c = p + 0x100;
40
      e = p + MAP_LEN;
41
    }
42
  return i;
43
}
44
45
void
46
f (char *p)
47
{
48
  int i;
49
  for (i = 0; i < MAP_LEN / 0x100; ++i)
50
    if (g (1, p + i * 0x100, 0x100) < 1)
51
      abort ();
52
}
53
54
main ()
55
{
56
#ifdef MAP_ANON
57
  char *p;
58
  int dev_zero;
59
60
  dev_zero = open ("/dev/zero", O_RDONLY);
61
  /* -1 is OK when we have MAP_ANON; else mmap will flag an error.  */
62
  if (INT_MAX != 0x7fffffffL || sizeof (char *) != sizeof (int))
63
    exit (0);
64
  p = mmap (MAP_START, MAP_LEN, PROT_READ|PROT_WRITE,
65
	    MAP_ANON|MAP_FIXED|MAP_PRIVATE, dev_zero, 0);
66
  if (p != (char *)-1)
67
    {
68
      f (p);
69
      if (c != e)
70
        abort ();
71
    }
72
#endif
73
  exit (0);
74
}

Return to bug 21862