summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c++/target-18.C
blob: f1085b14022933eca162f0268dd9e9a5b7007f62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
extern "C" void abort ();

__attribute__((noinline, noclone)) void
foo (int *&p, int *&q, int *&r, int n, int m)
{
  int i, err, *s = r;
  int sep = 1;
  #pragma omp target map(to:sep)
  sep = 0;
  #pragma omp target data map(to:p[0:8])
  {
    /* For zero length array sections, p points to the start of
       already mapped range, q to the end of it (with nothing mapped
       after it), and r does not point to an mapped range.  */
    #pragma omp target map(alloc:p[:0]) map(to:q[:0]) map(from:r[:0]) private(i) map(from:err) firstprivate (s)
    {
      err = 0;
      for (i = 0; i < 8; i++)
	if (p[i] != i + 1)
	  err = 1;
      if (sep)
	{
	  if (q != (int *) 0 || r != (int *) 0)
	    err = 1;
	}
      else if (p + 8 != q || r != s)
	err = 1;
    }
    if (err)
      abort ();
    /* Implicit mapping of pointers behaves the same way.  */
    #pragma omp target private(i) map(from:err) firstprivate (s)
    {
      err = 0;
      for (i = 0; i < 8; i++)
	if (p[i] != i + 1)
	  err = 1;
      if (sep)
	{
	  if (q != (int *) 0 || r != (int *) 0)
	    err = 1;
	}
      else if (p + 8 != q || r != s)
	err = 1;
    }
    if (err)
      abort ();
    /* And zero-length array sections, though not known at compile
       time, behave the same.  */
    #pragma omp target map(p[:n]) map(tofrom:q[:n]) map(alloc:r[:n]) private(i) map(from:err) firstprivate (s)
    {
      err = 0;
      for (i = 0; i < 8; i++)
	if (p[i] != i + 1)
	  err = 1;
      if (sep)
	{
	  if (q != (int *) 0 || r != (int *) 0)
	    err = 1;
	}
      else if (p + 8 != q || r != s)
	err = 1;
    }
    if (err)
      abort ();
    /* Non-zero length array sections, though not known at compile,
       behave differently.  */
    #pragma omp target map(p[:m]) map(tofrom:q[:m]) map(to:r[:m]) private(i) map(from:err)
    {
      err = 0;
      for (i = 0; i < 8; i++)
	if (p[i] != i + 1)
	  err = 1;
      if (q[0] != 9 || r[0] != 10)
	err = 1;
    }
    if (err)
      abort ();
    #pragma omp target data map(to:q[0:1])
    {
      /* For zero length array sections, p points to the start of
	 already mapped range, q points to the start of another one,
	 and r to the end of the second one.  */
      #pragma omp target map(to:p[:0]) map(from:q[:0]) map(tofrom:r[:0]) private(i) map(from:err)
      {
	err = 0;
	for (i = 0; i < 8; i++)
	  if (p[i] != i + 1)
	    err = 1;
	if (q[0] != 9)
	  err = 1;
	else if (sep)
	  {
	    if (r != (int *) 0)
	      err = 1;
	  }
	else if (r != q + 1)
	  err = 1;
      }
      if (err)
	abort ();
      /* Implicit mapping of pointers behaves the same way.  */
      #pragma omp target private(i) map(from:err)
      {
	err = 0;
	for (i = 0; i < 8; i++)
	  if (p[i] != i + 1)
	    err = 1;
	if (q[0] != 9)
	  err = 1;
	else if (sep)
	  {
	    if (r != (int *) 0)
	      err = 1;
	  }
	else if (r != q + 1)
	  err = 1;
      }
      if (err)
	abort ();
      /* And zero-length array sections, though not known at compile
	 time, behave the same.  */
      #pragma omp target map(p[:n]) map(alloc:q[:n]) map(from:r[:n]) private(i) map(from:err)
      {
	err = 0;
	for (i = 0; i < 8; i++)
	  if (p[i] != i + 1)
	    err = 1;
	if (q[0] != 9)
	  err = 1;
	else if (sep)
	  {
	    if (r != (int *) 0)
	      err = 1;
	  }
	else if (r != q + 1)
	  err = 1;
      }
      if (err)
	abort ();
      /* Non-zero length array sections, though not known at compile,
	 behave differently.  */
      #pragma omp target map(p[:m]) map(alloc:q[:m]) map(tofrom:r[:m]) private(i) map(from:err)
      {
	err = 0;
	for (i = 0; i < 8; i++)
	  if (p[i] != i + 1)
	    err = 1;
	if (q[0] != 9 || r[0] != 10)
	  err = 1;
      }
      if (err)
	abort ();
    }
  }
}

int
main ()
{
  int a[32], i;
  for (i = 0; i < 32; i++)
    a[i] = i;
  int *p = a + 1, *q = a + 9, *r = a + 10;
  foo (p, q, r, 0, 1);
  return 0;
}