1 // Ensure that a non-scalar dummy arguments which are implicitly used inside
2 // offloaded regions are properly mapped using present_or_copy semantics.
3 
4 // { dg-do run }
5 
6 #include <cassert>
7 
8 const int n = 100;
9 
10 struct data {
11   int v;
12 };
13 
14 void
kernels_present(data & d,int & x)15 kernels_present (data &d, int &x)
16 {
17 #pragma acc kernels present (d, x) default (none)
18   {
19     d.v = x;
20   }
21 }
22 
23 void
parallel_present(data & d,int & x)24 parallel_present (data &d, int &x)
25 {
26 #pragma acc parallel present (d, x) default (none)
27   {
28     d.v = x;
29   }
30 }
31 
32 void
kernels_implicit(data & d,int & x)33 kernels_implicit (data &d, int &x)
34 {
35 #pragma acc kernels
36   {
37     d.v = x;
38   }
39 }
40 
41 void
parallel_implicit(data & d,int & x)42 parallel_implicit (data &d, int &x)
43 {
44 #pragma acc parallel
45   {
46     d.v = x;
47   }
48 }
49 
50 void
reference_data(data & d,int & x)51 reference_data (data &d, int &x)
52 {
53 #pragma acc data copy(d, x)
54   {
55     kernels_present (d, x);
56 
57 #pragma acc update host(d)
58     assert (d.v == x);
59 
60     x = 200;
61 #pragma acc update device(x)
62 
63     parallel_present (d, x);
64   }
65 
66   assert (d.v == x);
67 
68   x = 300;
69   kernels_implicit (d, x);
70   assert (d.v == x);
71 
72   x = 400;
73   parallel_implicit (d, x);
74   assert (d.v == x);
75 }
76 
77 int
main()78 main ()
79 {
80   data d;
81   int x = 100;
82 
83 #pragma acc data copy(d, x)
84   {
85     kernels_present (d, x);
86 
87 #pragma acc update host(d)
88     assert (d.v == x);
89 
90     x = 200;
91 #pragma acc update device(x)
92 
93     parallel_present (d, x);
94   }
95 
96   assert (d.v == x);
97 
98   x = 300;
99   kernels_implicit (d, x);
100   assert (d.v == x);
101 
102   x = 400;
103   parallel_implicit (d, x);
104   assert (d.v == x);
105 
106   reference_data (d, x);
107 
108   return 0;
109 }
110