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 = long> struct S { 23 // CHECK: static long TS; 24 // CHECK-NEXT: #pragma omp threadprivate(S<long>::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 a; 35 S<T> s; 36 T arr[C][10], arr1[C]; 37 #pragma omp parallel 38 a=2; 39 #pragma omp parallel default(none), private(argc,b) firstprivate(argv) shared (d) if (parallel:argc > 0) num_threads(C) copyin(S<T>::TS) proc_bind(master) reduction(+:c, arr1[argc]) reduction(max:e, arr[:C][0:10]) 40 foo(); 41 #pragma omp parallel if (C) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:C][:argc]) reduction(&& : g) 42 foo(); 43 return 0; 44 } 45 46 // CHECK: template <typename T = int, int C = 5> int tmain(int argc, int *argv) { 47 // CHECK-NEXT: int b = argc, c, d, e, f, g; 48 // CHECK-NEXT: static int a; 49 // CHECK-NEXT: S<int> s; 50 // CHECK-NEXT: int arr[5][10], arr1[5]; 51 // CHECK-NEXT: #pragma omp parallel 52 // CHECK-NEXT: a = 2; 53 // CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(5) copyin(S<int>::TS) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:5][0:10]) 54 // CHECK-NEXT: foo() 55 // CHECK-NEXT: #pragma omp parallel if(5) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:5][:argc]) reduction(&&: g) 56 // CHECK-NEXT: foo() 57 // CHECK: template <typename T = long, int C = 1> long tmain(long argc, long *argv) { 58 // CHECK-NEXT: long b = argc, c, d, e, f, g; 59 // CHECK-NEXT: static long a; 60 // CHECK-NEXT: S<long> s; 61 // CHECK-NEXT: long arr[1][10], arr1[1]; 62 // CHECK-NEXT: #pragma omp parallel 63 // CHECK-NEXT: a = 2; 64 // CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(1) copyin(S<long>::TS) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:1][0:10]) 65 // CHECK-NEXT: foo() 66 // CHECK-NEXT: #pragma omp parallel if(1) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:1][:argc]) reduction(&&: g) 67 // CHECK-NEXT: foo() 68 // CHECK: template <typename T, int C> T tmain(T argc, T *argv) { 69 // CHECK-NEXT: T b = argc, c, d, e, f, g; 70 // CHECK-NEXT: static T a; 71 // CHECK-NEXT: S<T> s; 72 // CHECK-NEXT: T arr[C][10], arr1[C]; 73 // CHECK-NEXT: #pragma omp parallel 74 // CHECK-NEXT: a = 2; 75 // CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(C) copyin(S<T>::TS) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:C][0:10]) 76 // CHECK-NEXT: foo() 77 // CHECK-NEXT: #pragma omp parallel if(C) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:C][:argc]) reduction(&&: g) 78 // CHECK-NEXT: foo() 79 80 enum Enum { }; 81 82 int main (int argc, char **argv) { 83 long x; 84 int b = argc, c, d, e, f, g; 85 static int a; 86 #pragma omp threadprivate(a) 87 int arr[10][argc], arr1[2]; 88 Enum ee; 89 // CHECK: Enum ee; 90 #pragma omp parallel 91 // CHECK-NEXT: #pragma omp parallel 92 a=2; 93 // CHECK-NEXT: a = 2; 94 #pragma omp parallel default(none), private(argc,b) firstprivate(argv) if (parallel: argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(| : c, d, arr1[argc]) reduction(* : e, arr[:10][0:argc]) 95 // CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) if(parallel: argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(|: c,d,arr1[argc]) reduction(*: e,arr[:10][0:argc]) 96 foo(); 97 // CHECK-NEXT: foo(); 98 // CHECK-NEXT: #pragma omp parallel if(b) num_threads(c) proc_bind(close) reduction(^: e,f) reduction(&&: g,arr[0:argc][:10]) 99 // CHECK-NEXT: foo() 100 #pragma omp parallel if (b) num_threads(c) proc_bind(close) reduction(^:e, f) reduction(&& : g, arr[0:argc][:10]) 101 foo(); 102 return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x); 103 } 104 105 template <class T> 106 struct Foo { 107 int foo; 108 }; 109 110 void foo(const Foo<int> &arg) { 111 // CHECK: #pragma omp parallel 112 #pragma omp parallel 113 { 114 // CHECK: #pragma omp for schedule(static) 115 #pragma omp for schedule(static) 116 for (int idx = 0; idx < 1234; ++idx) { 117 //arg.foo = idx; 118 idx = arg.foo; 119 } 120 } 121 } 122 123 #endif 124