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