| 1 |
// We use 'auto' without a function return type, so specify dialect here |
| 2 |
// { dg-additional-options "-std=c++14 -fdump-tree-gimple" } |
| 3 |
// { dg-skip-if "requires hosted libstdc++ for cstring" { ! hostedlib } } |
| 4 |
|
| 5 |
#include <cstdlib> |
| 6 |
#include <cstring> |
| 7 |
|
| 8 |
struct T |
| 9 |
{ |
| 10 |
int *ptr; |
| 11 |
int ptr_len; |
| 12 |
|
| 13 |
int *&refptr; |
| 14 |
int refptr_len; |
| 15 |
|
| 16 |
auto set_ptr_func (int n) |
| 17 |
{ |
| 18 |
auto fn = [=](void) -> bool |
| 19 |
{ |
| 20 |
bool mapped; |
| 21 |
#pragma omp target map(from:mapped) |
| 22 |
{ |
| 23 |
if (ptr) |
| 24 |
for (int i = 0; i < ptr_len; i++) |
| 25 |
ptr[i] = n; |
| 26 |
mapped = (ptr != NULL); |
| 27 |
} |
| 28 |
return mapped; |
| 29 |
}; |
| 30 |
return fn; |
| 31 |
} |
| 32 |
|
| 33 |
auto set_refptr_func (int n) |
| 34 |
{ |
| 35 |
auto fn = [=](void) -> bool |
| 36 |
{ |
| 37 |
bool mapped; |
| 38 |
#pragma omp target map(from:mapped) |
| 39 |
{ |
| 40 |
if (refptr) |
| 41 |
for (int i = 0; i < refptr_len; i++) |
| 42 |
refptr[i] = n; |
| 43 |
mapped = (refptr != NULL); |
| 44 |
} |
| 45 |
return mapped; |
| 46 |
}; |
| 47 |
return fn; |
| 48 |
} |
| 49 |
}; |
| 50 |
|
| 51 |
int main (void) |
| 52 |
{ |
| 53 |
#define N 10 |
| 54 |
int *ptr1 = new int[N]; |
| 55 |
int *ptr2 = new int[N]; |
| 56 |
|
| 57 |
memset (ptr1, 0, sizeof (int) * N); |
| 58 |
memset (ptr2, 0, sizeof (int) * N); |
| 59 |
|
| 60 |
T a = { ptr1, N, ptr2, N }; |
| 61 |
|
| 62 |
auto p1 = a.set_ptr_func (1); |
| 63 |
auto r2 = a.set_refptr_func (2); |
| 64 |
|
| 65 |
if (p1 ()) |
| 66 |
abort (); |
| 67 |
if (r2 ()) |
| 68 |
abort (); |
| 69 |
|
| 70 |
if (a.ptr != ptr1) |
| 71 |
abort (); |
| 72 |
if (a.refptr != ptr2) |
| 73 |
abort (); |
| 74 |
|
| 75 |
for (int i = 0; i < N; i++) |
| 76 |
if (ptr1[i] != 0) |
| 77 |
abort (); |
| 78 |
|
| 79 |
for (int i = 0; i < N; i++) |
| 80 |
if (ptr2[i] != 0) |
| 81 |
abort (); |
| 82 |
|
| 83 |
#pragma omp target data map(ptr1[:N], ptr2[:N]) |
| 84 |
{ |
| 85 |
if (!p1 ()) |
| 86 |
abort (); |
| 87 |
if (!r2 ()) |
| 88 |
abort (); |
| 89 |
} |
| 90 |
|
| 91 |
if (a.ptr != ptr1) |
| 92 |
abort (); |
| 93 |
if (a.refptr != ptr2) |
| 94 |
abort (); |
| 95 |
|
| 96 |
for (int i = 0; i < N; i++) |
| 97 |
if (ptr1[i] != 1) |
| 98 |
abort (); |
| 99 |
|
| 100 |
for (int i = 0; i < N; i++) |
| 101 |
if (ptr2[i] != 2) |
| 102 |
abort (); |
| 103 |
|
| 104 |
return 0; |
| 105 |
} |
| 106 |
|
| 107 |
/* { dg-final { scan-tree-dump {#pragma omp target num_teams.* firstprivate\(n\) map\(alloc:MEM.* \[len: 0\]\) map\(firstprivate:this \[pointer assign, bias: 0\]\) map\(to:\*__closure \[len: [0-9]+\]\) map\(firstprivate:__closure \[pointer assign, bias: 0\]\) map\(tofrom:\*_[0-9]+ \[len: [0-9]+\]\) map\(always_pointer:__closure->__this \[pointer assign, bias: 0\]\) map\(from:mapped \[len: 1\]\) map\(alloc:\*_[0-9]+ \[len: 0\]\) map\(attach_zero_length_array_section:_[0-9]+->ptr \[bias: 0\]\)} "gimple" } } */ |
| 108 |
|
| 109 |
/* { dg-final { scan-tree-dump {#pragma omp target num_teams.* firstprivate\(n\) map\(alloc:MEM.* \[len: 0\]\) map\(firstprivate:this \[pointer assign, bias: 0\]\) map\(to:\*__closure \[len: [0-9]+\]\) map\(firstprivate:__closure \[pointer assign, bias: 0\]\) map\(tofrom:\*_[0-9]+ \[len: [0-9]+\]\) map\(always_pointer:__closure->__this \[pointer assign, bias: 0\]\) map\(from:mapped \[len: [0-9]+\]\) map\(alloc:\*_[0-9]+ \[len: 0\]\) map\(alloc:\*_[0-9]+ \[pointer assign, zero-length array section, bias: 0\]\) map\(attach:_[0-9]+->refptr \[bias: 0\]\)} "gimple" } } */ |