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 struct S { 12 S(): a(0) {} 13 S(int v) : a(v) {} 14 int a; 15 typedef int type; 16 }; 17 18 template <typename T> 19 class S7 : public T { 20 protected: 21 T a; 22 S7() : a(0) {} 23 24 public: 25 S7(typename T::type v) : a(v) { 26 #pragma omp parallel for private(a) private(this->a) private(T::a) 27 for (int k = 0; k < a.a; ++k) 28 ++this->a.a; 29 } 30 S7 &operator=(S7 &s) { 31 #pragma omp parallel for private(a) private(this->a) 32 for (int k = 0; k < s.a.a; ++k) 33 ++s.a.a; 34 return *this; 35 } 36 }; 37 38 // CHECK: #pragma omp parallel for private(this->a) private(this->a) private(this->S::a) 39 // CHECK: #pragma omp parallel for private(this->a) private(this->a) private(T::a) 40 // CHECK: #pragma omp parallel for private(this->a) private(this->a) 41 42 class S8 : public S7<S> { 43 S8() {} 44 45 public: 46 S8(int v) : S7<S>(v){ 47 #pragma omp parallel for private(a) private(this->a) private(S7<S>::a) 48 for (int k = 0; k < a.a; ++k) 49 ++this->a.a; 50 } 51 S8 &operator=(S8 &s) { 52 #pragma omp parallel for private(a) private(this->a) 53 for (int k = 0; k < s.a.a; ++k) 54 ++s.a.a; 55 return *this; 56 } 57 }; 58 59 // CHECK: #pragma omp parallel for private(this->a) private(this->a) private(this->S7<S>::a) 60 // CHECK: #pragma omp parallel for private(this->a) private(this->a) 61 62 template <class T, int N> 63 T tmain(T argc) { 64 T b = argc, c, d, e, f, h; 65 static T a; 66 // CHECK: static T a; 67 static T g; 68 #pragma omp threadprivate(g) 69 #pragma omp parallel for schedule(dynamic) default(none) copyin(g) linear(a) 70 // CHECK: #pragma omp parallel for schedule(dynamic) default(none) copyin(g) linear(a) 71 for (int i = 0; i < 2; ++i) 72 a = 2; 73 // CHECK-NEXT: for (int i = 0; i < 2; ++i) 74 // CHECK-NEXT: a = 2; 75 #pragma omp parallel for private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) ordered(N) if (parallel :argc) num_threads(N) default(shared) shared(e) reduction(+ : h) 76 for (int i = 0; i < 2; ++i) 77 for (int j = 0; j < 2; ++j) 78 for (int j = 0; j < 2; ++j) 79 for (int j = 0; j < 2; ++j) 80 for (int j = 0; j < 2; ++j) 81 for (int i = 0; i < 2; ++i) 82 for (int j = 0; j < 2; ++j) 83 for (int j = 0; j < 2; ++j) 84 for (int j = 0; j < 2; ++j) 85 for (int j = 0; j < 2; ++j) 86 foo(); 87 // CHECK-NEXT: #pragma omp parallel for private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) ordered(N) if(parallel: argc) num_threads(N) default(shared) shared(e) reduction(+: h) 88 // CHECK-NEXT: for (int i = 0; i < 2; ++i) 89 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 90 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 91 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 92 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 93 // CHECK-NEXT: for (int i = 0; i < 2; ++i) 94 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 95 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 96 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 97 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 98 // CHECK-NEXT: foo(); 99 return T(); 100 } 101 102 int main(int argc, char **argv) { 103 int b = argc, c, d, e, f, h; 104 static int a; 105 // CHECK: static int a; 106 static float g; 107 #pragma omp threadprivate(g) 108 #pragma omp parallel for schedule(guided, argc) default(none) copyin(g) linear(a) 109 // CHECK: #pragma omp parallel for schedule(guided, argc) default(none) copyin(g) linear(a) 110 for (int i = 0; i < 2; ++i) 111 a = 2; 112 // CHECK-NEXT: for (int i = 0; i < 2; ++i) 113 // CHECK-NEXT: a = 2; 114 #pragma omp parallel for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) ordered if (argc) num_threads(a) default(shared) shared(e) reduction(+ : h) linear(a:-5) 115 for (int i = 0; i < 10; ++i) 116 for (int j = 0; j < 10; ++j) 117 foo(); 118 // CHECK-NEXT: #pragma omp parallel for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) ordered if(argc) num_threads(a) default(shared) shared(e) reduction(+: h) linear(a: -5) 119 // CHECK-NEXT: for (int i = 0; i < 10; ++i) 120 // CHECK-NEXT: for (int j = 0; j < 10; ++j) 121 // CHECK-NEXT: foo(); 122 return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0])); 123 } 124 125 #endif 126