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 <class T> 12 struct S { 13 operator T() {return T();} 14 static T TS; 15 #pragma omp threadprivate(TS) 16 }; 17 18 // CHECK: template <class T = int> struct S { 19 // CHECK: static int TS; 20 // CHECK-NEXT: #pragma omp threadprivate(S<int>::TS) 21 // CHECK-NEXT: } 22 // CHECK: template <class T = char> struct S { 23 // CHECK: static char TS; 24 // CHECK-NEXT: #pragma omp threadprivate(S<char>::TS) 25 // CHECK-NEXT: } 26 // CHECK: template <class T> struct S { 27 // CHECK: static T TS; 28 // CHECK-NEXT: #pragma omp threadprivate(S::TS) 29 // CHECK: }; 30 31 template <typename T, int C> 32 T tmain(T argc, T *argv) { 33 T b = argc, c, d, e, f, g; 34 static T h; 35 S<T> s; 36 T arr[C][10], arr1[C]; 37 T i, j, a[20]; 38 #pragma omp target parallel 39 h=2; 40 #pragma omp target parallel default(none), private(argc,b) firstprivate(argv) shared (d) if (parallel:argc > 0) num_threads(C) proc_bind(master) reduction(+:c, arr1[argc]) reduction(max:e, arr[:C][0:10]) 41 foo(); 42 #pragma omp target parallel if (C) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:C][:argc]) reduction(&& : g) 43 foo(); 44 #pragma omp target parallel if (target:argc > 0) 45 foo(); 46 #pragma omp target parallel if (parallel:argc > 0) 47 foo(); 48 #pragma omp target parallel if (C) 49 foo(); 50 #pragma omp target parallel map(i) 51 foo(); 52 #pragma omp target parallel map(a[0:10], i) 53 foo(); 54 #pragma omp target parallel map(to: i) map(from: j) 55 foo(); 56 #pragma omp target parallel map(always,alloc: i) 57 foo(); 58 #pragma omp target parallel nowait 59 foo(); 60 #pragma omp target parallel depend(in : argc, argv[i:argc], a[:]) 61 foo(); 62 #pragma omp target parallel defaultmap(tofrom: scalar) 63 foo(); 64 return 0; 65 } 66 67 // CHECK: template <typename T = int, int C = 5> int tmain(int argc, int *argv) { 68 // CHECK-NEXT: int b = argc, c, d, e, f, g; 69 // CHECK-NEXT: static int h; 70 // CHECK-NEXT: S<int> s; 71 // CHECK-NEXT: int arr[5][10], arr1[5]; 72 // CHECK-NEXT: int i, j, a[20] 73 // CHECK-NEXT: #pragma omp target parallel 74 // CHECK-NEXT: h = 2; 75 // CHECK-NEXT: #pragma omp target parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(5) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:5][0:10]) 76 // CHECK-NEXT: foo() 77 // CHECK-NEXT: #pragma omp target parallel if(5) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:5][:argc]) reduction(&&: g) 78 // CHECK-NEXT: foo() 79 // CHECK-NEXT: #pragma omp target parallel if(target: argc > 0) 80 // CHECK-NEXT: foo() 81 // CHECK-NEXT: #pragma omp target parallel if(parallel: argc > 0) 82 // CHECK-NEXT: foo() 83 // CHECK-NEXT: #pragma omp target parallel if(5) 84 // CHECK-NEXT: foo() 85 // CHECK-NEXT: #pragma omp target parallel map(tofrom: i) 86 // CHECK-NEXT: foo() 87 // CHECK-NEXT: #pragma omp target parallel map(tofrom: a[0:10],i) 88 // CHECK-NEXT: foo() 89 // CHECK-NEXT: #pragma omp target parallel map(to: i) map(from: j) 90 // CHECK-NEXT: foo() 91 // CHECK-NEXT: #pragma omp target parallel map(always,alloc: i) 92 // CHECK-NEXT: foo() 93 // CHECK-NEXT: #pragma omp target parallel nowait 94 // CHECK-NEXT: foo() 95 // CHECK-NEXT: #pragma omp target parallel depend(in : argc,argv[i:argc],a[:]) 96 // CHECK-NEXT: foo() 97 // CHECK-NEXT: #pragma omp target parallel defaultmap(tofrom: scalar) 98 // CHECK-NEXT: foo() 99 // CHECK: template <typename T = char, int C = 1> char tmain(char argc, char *argv) { 100 // CHECK-NEXT: char b = argc, c, d, e, f, g; 101 // CHECK-NEXT: static char h; 102 // CHECK-NEXT: S<char> s; 103 // CHECK-NEXT: char arr[1][10], arr1[1]; 104 // CHECK-NEXT: char i, j, a[20] 105 // CHECK-NEXT: #pragma omp target parallel 106 // CHECK-NEXT: h = 2; 107 // CHECK-NEXT: #pragma omp target parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(1) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:1][0:10]) 108 // CHECK-NEXT: foo() 109 // CHECK-NEXT: #pragma omp target parallel if(1) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:1][:argc]) reduction(&&: g) 110 // CHECK-NEXT: foo() 111 // CHECK-NEXT: #pragma omp target parallel if(target: argc > 0) 112 // CHECK-NEXT: foo() 113 // CHECK-NEXT: #pragma omp target parallel if(parallel: argc > 0) 114 // CHECK-NEXT: foo() 115 // CHECK-NEXT: #pragma omp target parallel if(1) 116 // CHECK-NEXT: foo() 117 // CHECK-NEXT: #pragma omp target parallel map(tofrom: i) 118 // CHECK-NEXT: foo() 119 // CHECK-NEXT: #pragma omp target parallel map(tofrom: a[0:10],i) 120 // CHECK-NEXT: foo() 121 // CHECK-NEXT: #pragma omp target parallel map(to: i) map(from: j) 122 // CHECK-NEXT: foo() 123 // CHECK-NEXT: #pragma omp target parallel map(always,alloc: i) 124 // CHECK-NEXT: foo() 125 // CHECK-NEXT: #pragma omp target parallel nowait 126 // CHECK-NEXT: foo() 127 // CHECK-NEXT: #pragma omp target parallel depend(in : argc,argv[i:argc],a[:]) 128 // CHECK-NEXT: foo() 129 // CHECK-NEXT: #pragma omp target parallel defaultmap(tofrom: scalar) 130 // CHECK-NEXT: foo() 131 // CHECK: template <typename T, int C> T tmain(T argc, T *argv) { 132 // CHECK-NEXT: T b = argc, c, d, e, f, g; 133 // CHECK-NEXT: static T h; 134 // CHECK-NEXT: S<T> s; 135 // CHECK-NEXT: T arr[C][10], arr1[C]; 136 // CHECK-NEXT: T i, j, a[20] 137 // CHECK-NEXT: #pragma omp target parallel 138 // CHECK-NEXT: h = 2; 139 // CHECK-NEXT: #pragma omp target parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(C) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:C][0:10]) 140 // CHECK-NEXT: foo() 141 // CHECK-NEXT: #pragma omp target parallel if(C) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:C][:argc]) reduction(&&: g) 142 // CHECK-NEXT: foo() 143 // CHECK-NEXT: #pragma omp target parallel if(target: argc > 0) 144 // CHECK-NEXT: foo() 145 // CHECK-NEXT: #pragma omp target parallel if(parallel: argc > 0) 146 // CHECK-NEXT: foo() 147 // CHECK-NEXT: #pragma omp target parallel if(C) 148 // CHECK-NEXT: foo() 149 // CHECK-NEXT: #pragma omp target parallel map(tofrom: i) 150 // CHECK-NEXT: foo() 151 // CHECK-NEXT: #pragma omp target parallel map(tofrom: a[0:10],i) 152 // CHECK-NEXT: foo() 153 // CHECK-NEXT: #pragma omp target parallel map(to: i) map(from: j) 154 // CHECK-NEXT: foo() 155 // CHECK-NEXT: #pragma omp target parallel map(always,alloc: i) 156 // CHECK-NEXT: foo() 157 // CHECK-NEXT: #pragma omp target parallel nowait 158 // CHECK-NEXT: foo() 159 // CHECK-NEXT: #pragma omp target parallel depend(in : argc,argv[i:argc],a[:]) 160 // CHECK-NEXT: foo() 161 // CHECK-NEXT: #pragma omp target parallel defaultmap(tofrom: scalar) 162 // CHECK-NEXT: foo() 163 164 // CHECK-LABEL: int main(int argc, char **argv) { 165 int main (int argc, char **argv) { 166 int i, j, a[20]; 167 // CHECK-NEXT: int i, j, a[20] 168 #pragma omp target parallel 169 // CHECK-NEXT: #pragma omp target parallel 170 foo(); 171 // CHECK-NEXT: foo(); 172 #pragma omp target parallel if (argc > 0) 173 // CHECK-NEXT: #pragma omp target parallel if(argc > 0) 174 foo(); 175 // CHECK-NEXT: foo(); 176 177 #pragma omp target parallel if (target: argc > 0) 178 // CHECK-NEXT: #pragma omp target parallel if(target: argc > 0) 179 foo(); 180 // CHECK-NEXT: foo(); 181 182 #pragma omp target parallel if (parallel: argc > 0) 183 // CHECK-NEXT: #pragma omp target parallel if(parallel: argc > 0) 184 foo(); 185 // CHECK-NEXT: foo(); 186 187 #pragma omp target parallel map(i) if(argc>0) 188 // CHECK-NEXT: #pragma omp target parallel map(tofrom: i) if(argc > 0) 189 foo(); 190 // CHECK-NEXT: foo(); 191 192 #pragma omp target parallel map(i) 193 // CHECK-NEXT: #pragma omp target parallel map(tofrom: i) 194 foo(); 195 // CHECK-NEXT: foo(); 196 197 #pragma omp target parallel map(a[0:10], i) 198 // CHECK-NEXT: #pragma omp target parallel map(tofrom: a[0:10],i) 199 foo(); 200 // CHECK-NEXT: foo(); 201 202 #pragma omp target parallel map(to: i) map(from: j) 203 // CHECK-NEXT: #pragma omp target parallel map(to: i) map(from: j) 204 foo(); 205 // CHECK-NEXT: foo(); 206 207 #pragma omp target parallel map(always,alloc: i) 208 // CHECK-NEXT: #pragma omp target parallel map(always,alloc: i) 209 foo(); 210 // CHECK-NEXT: foo(); 211 212 #pragma omp target parallel nowait 213 // CHECK-NEXT: #pragma omp target parallel nowait 214 foo(); 215 // CHECK-NEXT: foo(); 216 217 #pragma omp target parallel depend(in : argc, argv[i:argc], a[:]) 218 // CHECK-NEXT: #pragma omp target parallel depend(in : argc,argv[i:argc],a[:]) 219 foo(); 220 // CHECK-NEXT: foo(); 221 222 #pragma omp target parallel defaultmap(tofrom: scalar) 223 // CHECK-NEXT: #pragma omp target parallel defaultmap(tofrom: scalar) 224 foo(); 225 // CHECK-NEXT: foo(); 226 227 return tmain<int, 5>(argc, &argc) + tmain<char, 1>(argv[0][0], argv[0]); 228 } 229 230 extern template int S<int>::TS; 231 extern template char S<char>::TS; 232 233 #endif 234