Debian Codegraph @

gcc/testsuite/g++.dg/gomp/target-this-3.C

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