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