C99 testsuite readiness: Compile more tests with -std=gnu89
[official-gcc.git] / gcc / testsuite / g++.dg / gomp / target-this-3.C
blobbc2cc0b297dcb07317a39c09ec7831c717b10cf1
1 // { dg-do compile }
2 // { dg-additional-options "-fdump-tree-gimple" }
3 #include <cstdlib>
4 #include <cstring>
5 extern "C" void abort ();
7 struct S
9   int * ptr;
10   int ptr_len;
12   int *&refptr;
13   int refptr_len;
15   bool set_ptr (int n)
16   {
17     bool mapped;
18     #pragma omp target map(from:mapped)
19     {
20       if (ptr != NULL)
21         for (int i = 0; i < ptr_len; i++)
22           ptr[i] = n;
23       mapped = (ptr != NULL);
24     }
25     return mapped;
26   }
28   bool set_refptr (int n)
29   {
30     bool mapped;
31     #pragma omp target map(from:mapped)
32     {
33       if (refptr != NULL)
34         for (int i = 0; i < refptr_len; i++)
35           refptr[i] = n;
36       mapped = (refptr != NULL);
37     }
38     return mapped;
39   }
42 int main (void)
44   #define N 10
45   int *ptr1 = new int[N];
46   int *ptr2 = new int[N];
48   memset (ptr1, 0, sizeof (int) * N);
49   memset (ptr2, 0, sizeof (int) * N);
51   S s = { ptr1, N, ptr2, N };
53   bool mapped;
54   int val = 123;
56   mapped = s.set_ptr (val);
57   if (mapped)
58     abort ();
59   if (s.ptr != ptr1)
60     abort ();
61   for (int i = 0; i < N; i++)
62     if (ptr1[i] != 0)
63       abort ();
65   mapped = s.set_refptr (val);
66   if (mapped)
67     abort ();
68   if (s.refptr != ptr2)
69     abort ();
70   for (int i = 0; i < N; i++)
71     if (ptr2[i] != 0)
72       abort ();
74   #pragma omp target data map(ptr1[:N])
75   mapped = s.set_ptr (val);
77   if (!mapped)
78     abort ();
79   if (s.set_refptr (0))
80     abort ();
81   if (s.ptr != ptr1 || s.refptr != ptr2)
82     abort ();
83   for (int i = 0; i < N; i++)
84     if (ptr1[i] != val)
85       abort ();
87   #pragma omp target data map(ptr2[:N])
88   mapped = s.set_refptr (val);
90   if (!mapped)
91     abort ();
92   if (s.set_ptr (0))
93     abort ();
94   if (s.ptr != ptr1 || s.refptr != ptr2)
95     abort ();
96   for (int i = 0; i < N; i++)
97     if (ptr2[i] != val)
98       abort ();
100   return 0;
103 /* { 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" } } */
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\(attach_zero_length_array_section:this->ptr \[bias: 0\]\)} "gimple" } } */