| 1 |
extern "C" void abort (); |
| 2 |
|
| 3 |
__attribute__((noinline, noclone)) void |
| 4 |
foo (int *&p, int *&q, int *&r, int n, int m) |
| 5 |
{ |
| 6 |
int i, err, *s = r; |
| 7 |
int sep = 1; |
| 8 |
#pragma omp target map(to:sep) |
| 9 |
sep = 0; |
| 10 |
#pragma omp target data map(to:p[0:8]) |
| 11 |
{ |
| 12 |
/* For zero length array sections, p points to the start of |
| 13 |
already mapped range, q to the end of it (with nothing mapped |
| 14 |
after it), and r does not point to an mapped range. */ |
| 15 |
#pragma omp target map(alloc:p[:0]) map(to:q[:0]) map(from:r[:0]) private(i) map(from:err) firstprivate (s) |
| 16 |
{ |
| 17 |
err = 0; |
| 18 |
for (i = 0; i < 8; i++) |
| 19 |
if (p[i] != i + 1) |
| 20 |
err = 1; |
| 21 |
if (sep) |
| 22 |
{ |
| 23 |
/* Since OpenMP 5.2, 'q'/'r' are no longer set to NULL if pointing to |
| 24 |
unmapped storage. */ |
| 25 |
if (q == (int *) 0 || r == (int *) 0) |
| 26 |
err = 1; |
| 27 |
} |
| 28 |
else if (p + 8 != q || r != s) |
| 29 |
err = 1; |
| 30 |
} |
| 31 |
if (err) |
| 32 |
abort (); |
| 33 |
/* Implicit mapping of pointers behaves the same way. */ |
| 34 |
#pragma omp target private(i) map(from:err) firstprivate (s) |
| 35 |
{ |
| 36 |
err = 0; |
| 37 |
for (i = 0; i < 8; i++) |
| 38 |
if (p[i] != i + 1) |
| 39 |
err = 1; |
| 40 |
if (sep) |
| 41 |
{ |
| 42 |
/* Since OpenMP 5.2, 'q'/'r' are no longer set to NULL if pointing to |
| 43 |
unmapped storage. */ |
| 44 |
if (q == (int *) 0 || r == (int *) 0) |
| 45 |
err = 1; |
| 46 |
} |
| 47 |
else if (p + 8 != q || r != s) |
| 48 |
err = 1; |
| 49 |
} |
| 50 |
if (err) |
| 51 |
abort (); |
| 52 |
/* And zero-length array sections, though not known at compile |
| 53 |
time, behave the same. */ |
| 54 |
#pragma omp target map(p[:n]) map(tofrom:q[:n]) map(alloc:r[:n]) private(i) map(from:err) firstprivate (s) |
| 55 |
{ |
| 56 |
err = 0; |
| 57 |
for (i = 0; i < 8; i++) |
| 58 |
if (p[i] != i + 1) |
| 59 |
err = 1; |
| 60 |
if (sep) |
| 61 |
{ |
| 62 |
/* Since OpenMP 5.2, 'q'/'r' are no longer set to NULL if pointing to |
| 63 |
unmapped storage. */ |
| 64 |
if (q == (int *) 0 || r == (int *) 0) |
| 65 |
err = 1; |
| 66 |
} |
| 67 |
else if (p + 8 != q || r != s) |
| 68 |
err = 1; |
| 69 |
} |
| 70 |
if (err) |
| 71 |
abort (); |
| 72 |
/* Non-zero length array sections, though not known at compile, |
| 73 |
behave differently. */ |
| 74 |
#pragma omp target map(p[:m]) map(tofrom:q[:m]) map(to:r[:m]) private(i) map(from:err) |
| 75 |
{ |
| 76 |
err = 0; |
| 77 |
for (i = 0; i < 8; i++) |
| 78 |
if (p[i] != i + 1) |
| 79 |
err = 1; |
| 80 |
if (q[0] != 9 || r[0] != 10) |
| 81 |
err = 1; |
| 82 |
} |
| 83 |
if (err) |
| 84 |
abort (); |
| 85 |
#pragma omp target data map(to:q[0:1]) |
| 86 |
{ |
| 87 |
/* For zero length array sections, p points to the start of |
| 88 |
already mapped range, q points to the start of another one, |
| 89 |
and r to the end of the second one. */ |
| 90 |
#pragma omp target map(to:p[:0]) map(from:q[:0]) map(tofrom:r[:0]) private(i) map(from:err) |
| 91 |
{ |
| 92 |
err = 0; |
| 93 |
for (i = 0; i < 8; i++) |
| 94 |
if (p[i] != i + 1) |
| 95 |
err = 1; |
| 96 |
if (q[0] != 9) |
| 97 |
err = 1; |
| 98 |
else if (sep) |
| 99 |
{ |
| 100 |
/* Since OpenMP 5.2, 'r' is no longer set to NULL if *r is unmapped.*/ |
| 101 |
if (r == (int *) 0) |
| 102 |
err = 1; |
| 103 |
} |
| 104 |
else if (r != q + 1) |
| 105 |
err = 1; |
| 106 |
} |
| 107 |
if (err) |
| 108 |
abort (); |
| 109 |
/* Implicit mapping of pointers behaves the same way. */ |
| 110 |
#pragma omp target private(i) map(from:err) |
| 111 |
{ |
| 112 |
err = 0; |
| 113 |
for (i = 0; i < 8; i++) |
| 114 |
if (p[i] != i + 1) |
| 115 |
err = 1; |
| 116 |
if (q[0] != 9) |
| 117 |
err = 1; |
| 118 |
else if (sep) |
| 119 |
{ |
| 120 |
/* Since OpenMP 5.2, 'r' is no longer set to NULL if *r is unmapped.*/ |
| 121 |
if (r == (int *) 0) |
| 122 |
err = 1; |
| 123 |
} |
| 124 |
else if (r != q + 1) |
| 125 |
err = 1; |
| 126 |
} |
| 127 |
if (err) |
| 128 |
abort (); |
| 129 |
/* And zero-length array sections, though not known at compile |
| 130 |
time, behave the same. */ |
| 131 |
#pragma omp target map(p[:n]) map(alloc:q[:n]) map(from:r[:n]) private(i) map(from:err) |
| 132 |
{ |
| 133 |
err = 0; |
| 134 |
for (i = 0; i < 8; i++) |
| 135 |
if (p[i] != i + 1) |
| 136 |
err = 1; |
| 137 |
if (q[0] != 9) |
| 138 |
err = 1; |
| 139 |
else if (sep) |
| 140 |
{ |
| 141 |
/* Since OpenMP 5.2, 'r' is no longer set to NULL if *r is unmapped.*/ |
| 142 |
if (r == (int *) 0) |
| 143 |
err = 1; |
| 144 |
} |
| 145 |
else if (r != q + 1) |
| 146 |
err = 1; |
| 147 |
} |
| 148 |
if (err) |
| 149 |
abort (); |
| 150 |
/* Non-zero length array sections, though not known at compile, |
| 151 |
behave differently. */ |
| 152 |
#pragma omp target map(p[:m]) map(alloc:q[:m]) map(tofrom:r[:m]) private(i) map(from:err) |
| 153 |
{ |
| 154 |
err = 0; |
| 155 |
for (i = 0; i < 8; i++) |
| 156 |
if (p[i] != i + 1) |
| 157 |
err = 1; |
| 158 |
if (q[0] != 9 || r[0] != 10) |
| 159 |
err = 1; |
| 160 |
} |
| 161 |
if (err) |
| 162 |
abort (); |
| 163 |
} |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
int |
| 168 |
main () |
| 169 |
{ |
| 170 |
int a[32], i; |
| 171 |
for (i = 0; i < 32; i++) |
| 172 |
a[i] = i; |
| 173 |
int *p = a + 1, *q = a + 9, *r = a + 10; |
| 174 |
foo (p, q, r, 0, 1); |
| 175 |
return 0; |
| 176 |
} |