1 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
4 // expected-no-diagnostics
5 
6 #ifndef HEADER
7 #define HEADER
8 
9 void foo() {}
10 
11 template <typename T, int C>
12 T tmain(T argc, T *argv) {
13   T i, j, b, c, d, e, x[20];
14 
15 #pragma omp target data map(to: c)
16   i = argc;
17 
18 #pragma omp target data map(to: c) if (target data: j > 0)
19   foo();
20 
21 #pragma omp target data map(to: c) if (b)
22   foo();
23 
24 #pragma omp target data map(c)
25   foo();
26 
27 #pragma omp target data map(c) if(b>e)
28   foo();
29 
30 #pragma omp target data map(x[0:10], c)
31   foo();
32 
33 #pragma omp target data map(to: c) map(from: d)
34   foo();
35 
36 #pragma omp target data map(always,alloc: e)
37   foo();
38 
39 // nesting a target region
40 #pragma omp target data map(e)
41 {
42   #pragma omp target map(always, alloc: e)
43     foo();
44 }
45 
46   return 0;
47 }
48 
49 // CHECK: template <typename T = int, int C = 5> int tmain(int argc, int *argv) {
50 // CHECK-NEXT: int i, j, b, c, d, e, x[20];
51 // CHECK-NEXT: #pragma omp target data map(to: c)
52 // CHECK-NEXT: i = argc;
53 // CHECK-NEXT: #pragma omp target data map(to: c) if(target data: j > 0)
54 // CHECK-NEXT: foo();
55 // CHECK-NEXT: #pragma omp target data map(to: c) if(b)
56 // CHECK-NEXT: foo();
57 // CHECK-NEXT: #pragma omp target data map(tofrom: c)
58 // CHECK-NEXT: foo();
59 // CHECK-NEXT: #pragma omp target data map(tofrom: c) if(b > e)
60 // CHECK-NEXT: foo();
61 // CHECK-NEXT: #pragma omp target data map(tofrom: x[0:10],c)
62 // CHECK-NEXT: foo();
63 // CHECK-NEXT: #pragma omp target data map(to: c) map(from: d)
64 // CHECK-NEXT: foo();
65 // CHECK-NEXT: #pragma omp target data map(always,alloc: e)
66 // CHECK-NEXT: foo();
67 // CHECK-NEXT: #pragma omp target data map(tofrom: e)
68 // CHECK-NEXT: {
69 // CHECK-NEXT: #pragma omp target map(always,alloc: e)
70 // CHECK-NEXT: foo();
71 // CHECK: template <typename T = char, int C = 1> char tmain(char argc, char *argv) {
72 // CHECK-NEXT: char i, j, b, c, d, e, x[20];
73 // CHECK-NEXT: #pragma omp target data map(to: c)
74 // CHECK-NEXT: i = argc;
75 // CHECK-NEXT: #pragma omp target data map(to: c) if(target data: j > 0)
76 // CHECK-NEXT: foo();
77 // CHECK-NEXT: #pragma omp target data map(to: c) if(b)
78 // CHECK-NEXT: foo();
79 // CHECK-NEXT: #pragma omp target data map(tofrom: c)
80 // CHECK-NEXT: foo();
81 // CHECK-NEXT: #pragma omp target data map(tofrom: c) if(b > e)
82 // CHECK-NEXT: foo();
83 // CHECK-NEXT: #pragma omp target data map(tofrom: x[0:10],c)
84 // CHECK-NEXT: foo();
85 // CHECK-NEXT: #pragma omp target data map(to: c) map(from: d)
86 // CHECK-NEXT: foo();
87 // CHECK-NEXT: #pragma omp target data map(always,alloc: e)
88 // CHECK-NEXT: foo();
89 // CHECK-NEXT: #pragma omp target data map(tofrom: e)
90 // CHECK-NEXT: {
91 // CHECK-NEXT: #pragma omp target map(always,alloc: e)
92 // CHECK-NEXT: foo();
93 // CHECK: template <typename T, int C> T tmain(T argc, T *argv) {
94 // CHECK-NEXT: T i, j, b, c, d, e, x[20];
95 // CHECK-NEXT: #pragma omp target data map(to: c)
96 // CHECK-NEXT: i = argc;
97 // CHECK-NEXT: #pragma omp target data map(to: c) if(target data: j > 0)
98 // CHECK-NEXT: foo();
99 // CHECK-NEXT: #pragma omp target data map(to: c) if(b)
100 // CHECK-NEXT: foo();
101 // CHECK-NEXT: #pragma omp target data map(tofrom: c)
102 // CHECK-NEXT: foo();
103 // CHECK-NEXT: #pragma omp target data map(tofrom: c) if(b > e)
104 // CHECK-NEXT: foo();
105 // CHECK-NEXT: #pragma omp target data map(tofrom: x[0:10],c)
106 // CHECK-NEXT: foo();
107 // CHECK-NEXT: #pragma omp target data map(to: c) map(from: d)
108 // CHECK-NEXT: foo();
109 // CHECK-NEXT: #pragma omp target data map(always,alloc: e)
110 // CHECK-NEXT: foo();
111 // CHECK-NEXT: #pragma omp target data map(tofrom: e)
112 // CHECK-NEXT: {
113 // CHECK-NEXT: #pragma omp target map(always,alloc: e)
114 // CHECK-NEXT: foo();
115 
116 int main (int argc, char **argv) {
117   int b = argc, c, d, e, f, g, x[20];
118   static int a;
119 // CHECK: static int a;
120 
121 #pragma omp target data map(to: c)
122 // CHECK:      #pragma omp target data map(to: c)
123   a=2;
124 // CHECK-NEXT: a = 2;
125 #pragma omp target data map(to: c) if (target data: b)
126 // CHECK: #pragma omp target data map(to: c) if(target data: b)
127   foo();
128 // CHECK-NEXT: foo();
129 
130 #pragma omp target data map(to: c) if (b > g)
131 // CHECK: #pragma omp target data map(to: c) if(b > g)
132   foo();
133 // CHECK-NEXT: foo();
134 
135 #pragma omp target data map(c)
136 // CHECK-NEXT: #pragma omp target data map(tofrom: c)
137   foo();
138 // CHECK-NEXT: foo();
139 
140 #pragma omp target data map(c) if(b>g)
141 // CHECK-NEXT: #pragma omp target data map(tofrom: c) if(b > g)
142   foo();
143 // CHECK-NEXT: foo();
144 
145 #pragma omp target data map(x[0:10], c)
146 // CHECK-NEXT: #pragma omp target data map(tofrom: x[0:10],c)
147   foo();
148 // CHECK-NEXT: foo();
149 
150 #pragma omp target data map(to: c) map(from: d)
151 // CHECK-NEXT: #pragma omp target data map(to: c) map(from: d)
152   foo();
153 // CHECK-NEXT: foo();
154 
155 #pragma omp target data map(always,alloc: e)
156 // CHECK-NEXT: #pragma omp target data map(always,alloc: e)
157   foo();
158 // CHECK-NEXT: foo();
159 
160 // nesting a target region
161 #pragma omp target data map(e)
162 // CHECK-NEXT: #pragma omp target data map(tofrom: e)
163 {
164 // CHECK-NEXT: {
165   #pragma omp target map(always, alloc: e)
166 // CHECK-NEXT: #pragma omp target map(always,alloc: e)
167     foo();
168 // CHECK-NEXT: foo();
169 }
170   return tmain<int, 5>(argc, &argc) + tmain<char, 1>(argv[0][0], argv[0]);
171 }
172 
173 #endif
174