1 // RUN: %clang_cc1 -verify -fopenmp %s 2 3 // RUN: %clang_cc1 -verify -fopenmp-simd %s 4 5 extern int omp_default_mem_alloc; 6 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}} 7 extern S1 a; 8 class S2 { 9 mutable int a; 10 11 public: 12 S2() : a(0) {} 13 }; 14 const S2 b; 15 const S2 ba[5]; 16 class S3 { 17 int a; 18 19 public: 20 S3() : a(0) {} 21 }; 22 const S3 ca[5]; 23 class S4 { 24 int a; 25 S4(); 26 27 public: 28 S4(int v) : a(v) { 29 #pragma omp target firstprivate(a) firstprivate(this->a) 30 for (int k = 0; k < v; ++k) 31 ++this->a; 32 } 33 }; 34 class S5 { 35 int a; 36 S5() : a(0) {} 37 38 public: 39 S5(int v) : a(v) {} 40 S5 &operator=(S5 &s) { 41 #pragma omp target firstprivate(a) firstprivate(this->a) firstprivate(s.a) // expected-error {{expected variable name or data member of current class}} 42 for (int k = 0; k < s.a; ++k) // expected-warning {{Non-trivial type 'S5' is mapped, only trivial types are guaranteed to be mapped correctly}} 43 ++s.a; 44 return *this; 45 } 46 }; 47 48 template <typename T> 49 class S6 { 50 public: 51 T a; 52 53 S6() : a(0) {} 54 S6(T v) : a(v) { 55 #pragma omp target firstprivate(a) firstprivate(this->a) 56 for (int k = 0; k < v; ++k) 57 ++this->a; 58 } 59 S6 &operator=(S6 &s) { 60 #pragma omp target firstprivate(a) firstprivate(this->a) firstprivate(s.a) // expected-error {{expected variable name or data member of current class}} 61 for (int k = 0; k < s.a; ++k) 62 ++s.a; 63 return *this; 64 } 65 }; 66 67 template <typename T> 68 class S7 : public T { 69 T a; 70 S7() : a(0) {} 71 72 public: 73 S7(T v) : a(v) { 74 #pragma omp target firstprivate(a) firstprivate(this->a) firstprivate(T::a) 75 for (int k = 0; k < a.a; ++k) 76 ++this->a.a; 77 } 78 S7 &operator=(S7 &s) { 79 #pragma omp target firstprivate(a) firstprivate(this->a) firstprivate(s.a) firstprivate(s.T::a) // expected-error 2 {{expected variable name or data member of current class}} 80 for (int k = 0; k < s.a.a; ++k) 81 ++s.a.a; 82 return *this; 83 } 84 }; 85 86 S3 h; 87 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} 88 89 template <class I, class C> 90 int foomain(I argc, C **argv) { 91 I e(4); 92 I g(5); 93 int i; 94 int &j = i; 95 #pragma omp target firstprivate // expected-error {{expected '(' after 'firstprivate'}} 96 {} 97 #pragma omp target firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 98 {} 99 #pragma omp target firstprivate() // expected-error {{expected expression}} 100 {} 101 #pragma omp target firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 102 {} 103 #pragma omp target firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 104 {} 105 #pragma omp target firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 106 {} 107 #pragma omp target firstprivate(argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}} 108 {} 109 #pragma omp target firstprivate(S1) // expected-error {{'S1' does not refer to a value}} 110 {} 111 #pragma omp target firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}} 112 {} 113 #pragma omp target firstprivate(argv[1]) // expected-error {{expected variable name}} 114 {} 115 #pragma omp target firstprivate(e, g) 116 {} 117 #pragma omp target firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} 118 {} 119 #pragma omp target shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp target'}} 120 #pragma omp parallel 121 { 122 int v = 0; 123 int i; 124 } 125 #pragma omp parallel shared(i) 126 #pragma omp parallel firstprivate(i) 127 #pragma omp target firstprivate(j) 128 {} 129 #pragma omp target firstprivate(i) 130 {} 131 return 0; 132 } 133 134 void bar(S4 a[2]) { 135 #pragma omp parallel 136 #pragma omp target firstprivate(a) 137 {} 138 } 139 140 namespace A { 141 double x; 142 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} 143 } 144 namespace B { 145 using A::x; 146 } 147 148 int main(int argc, char **argv) { 149 S4 e(4); 150 S5 g(5); 151 S6<float> s6(0.0) , s6_0(1.0); 152 S7<S6<float> > s7(0.0) , s7_0(1.0); 153 int i; 154 int &j = i; 155 #pragma omp target firstprivate // expected-error {{expected '(' after 'firstprivate'}} 156 {} 157 #pragma omp target firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 158 {} 159 #pragma omp target firstprivate() // expected-error {{expected expression}} 160 {} 161 #pragma omp target firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 162 {} 163 #pragma omp target firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 164 {} 165 #pragma omp target firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 166 {} 167 #pragma omp target firstprivate(argc) 168 {} 169 #pragma omp target firstprivate(S1) // expected-error {{'S1' does not refer to a value}} 170 {} 171 #pragma omp target firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}} 172 {} 173 #pragma omp target firstprivate(argv[1]) // expected-error {{expected variable name}} 174 {} 175 #pragma omp target firstprivate(e, g) 176 {} 177 #pragma omp target firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} 178 {} 179 #pragma omp target firstprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} 180 {} 181 #pragma omp target shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp target'}} 182 #pragma omp parallel 183 { 184 int i; 185 } 186 #pragma omp parallel shared(i) 187 #pragma omp parallel firstprivate(i) 188 #pragma omp target firstprivate(j) 189 {} 190 #pragma omp target firstprivate(i) 191 {} 192 static int si; 193 #pragma omp target firstprivate(si) // OK 194 {} 195 #pragma omp target map(i) firstprivate(i) // expected-error {{firstprivate variable cannot be in a map clause in '#pragma omp target' directive}} 196 {} 197 s6 = s6_0; // expected-note {{in instantiation of member function 'S6<float>::operator=' requested here}} 198 s7 = s7_0; // expected-note {{in instantiation of member function 'S7<S6<float> >::operator=' requested here}} 199 return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}} 200 } 201 202