316 lines · cpp
1// RUN: %clang_cc1 -verify -fopenmp -fsyntax-only %s -Wuninitialized2// RUN: %clang_cc1 -verify -fopenmp -std=c++11 -fsyntax-only %s -Wuninitialized3// RUN: %clang_cc1 -verify=expected,omp52 -fopenmp -fopenmp-version=52 -fsyntax-only %s -Wuninitialized4// RUN: %clang_cc1 -verify=expected,omp52 -fopenmp -fopenmp-version=52 -std=c++11 -fsyntax-only %s -Wuninitialized5// RUN: %clang_cc1 -verify -fopenmp-simd -fsyntax-only %s -Wuninitialized6// RUN: %clang_cc1 -verify -fopenmp-simd -std=c++11 -fsyntax-only %s -Wuninitialized7// RUN: %clang_cc1 -verify=expected,omp52 -fopenmp-simd -fopenmp-version=52 -fsyntax-only %s -Wuninitialized8// RUN: %clang_cc1 -verify=expected,omp52 -fopenmp-simd -fopenmp-version=52 -std=c++11 -fsyntax-only %s -Wuninitialized9 10typedef void **omp_allocator_handle_t;11extern const omp_allocator_handle_t omp_null_allocator;12extern const omp_allocator_handle_t omp_default_mem_alloc;13extern const omp_allocator_handle_t omp_large_cap_mem_alloc;14extern const omp_allocator_handle_t omp_const_mem_alloc;15extern const omp_allocator_handle_t omp_high_bw_mem_alloc;16extern const omp_allocator_handle_t omp_low_lat_mem_alloc;17extern const omp_allocator_handle_t omp_cgroup_mem_alloc;18extern const omp_allocator_handle_t omp_pteam_mem_alloc;19extern const omp_allocator_handle_t omp_thread_mem_alloc;20 21void xxx(int argc) {22 int fp; // expected-note {{initialize the variable 'fp' to silence this warning}}23 [[omp::directive(taskloop reduction(+:fp))]] // expected-warning {{variable 'fp' is uninitialized when used here}}24 for (int i = 0; i < 10; ++i)25 ;26}27 28void foo() {29}30 31bool foobool(int argc) {32 return argc;33}34 35void foobar(int &ref) {36 [[omp::directive(taskloop reduction(+:ref))]]37 for (int i = 0; i < 10; ++i)38 foo();39}40 41struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}42extern S1 a;43class S2 {44 mutable int a;45 S2 &operator+(const S2 &arg) { return (*this); } // expected-note 3 {{implicitly declared private here}}46 47public:48 S2() : a(0) {}49 S2(S2 &s2) : a(s2.a) {}50 static float S2s; // expected-note 2 {{static data member is predetermined as shared}}51 static const float S2sc; // expected-note 2 {{'S2sc' declared here}}52};53const float S2::S2sc = 0;54S2 b; // expected-note 3 {{'b' defined here}}55const S2 ba[5]; // expected-note 2 {{'ba' defined here}}56class S3 {57 int a;58 59public:60 int b;61 S3() : a(0) {}62 S3(const S3 &s3) : a(s3.a) {}63 S3 operator+(const S3 &arg1) { return arg1; }64};65int operator+(const S3 &arg1, const S3 &arg2) { return 5; }66S3 c; // expected-note 3 {{'c' defined here}}67const S3 ca[5]; // expected-note 2 {{'ca' defined here}}68extern const int f; // expected-note 4 {{'f' declared here}}69class S4 {70 int a;71 S4(); // expected-note {{implicitly declared private here}}72 S4(const S4 &s4);73 S4 &operator+(const S4 &arg) { return (*this); }74 75public:76 S4(int v) : a(v) {}77};78S4 &operator&=(S4 &arg1, S4 &arg2) { return arg1; }79class S5 {80 int a:32;81 S5() : a(0) {} // expected-note {{implicitly declared private here}}82 S5(const S5 &s5) : a(s5.a) {}83 S5 &operator+(const S5 &arg);84 85public:86 S5(int v) : a(v) {}87};88class S6 { // expected-note 3 {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const S6' for 1st argument}}89#if __cplusplus >= 201103L // C++11 or later90// expected-note@-2 3 {{candidate function (the implicit move assignment operator) not viable}}91#endif92 int a;93 94public:95 S6() : a(6) {}96 operator int() { return 6; }97} o;98 99struct S7 {100 int a: 32;101 S7() {102 [[omp::directive(taskloop reduction(+:a))]] // expected-error {{expected addressable reduction item for the task-based directives}}103 for (int i = 0; i < 10; ++i)104 ++a;105 }106};107 108S3 h, k;109[[omp::directive(threadprivate(h))]]; // expected-note 2 {{defined as threadprivate or thread local}}110 111template <class T> // expected-note {{declared here}}112T tmain(T argc) {113 const T d = T(); // expected-note 4 {{'d' defined here}}114 const T da[5] = {T()}; // expected-note 2 {{'da' defined here}}115 T qa[5] = {T()};116 T i, z;117 T &j = i; // expected-note 4 {{'j' defined here}}118 S3 &p = k; // expected-note 2 {{'p' defined here}}119 const T &r = da[(int)i]; // expected-note 2 {{'r' defined here}}120 T &q = qa[(int)i]; // expected-note 2 {{'q' defined here}}121 T fl;122 [[omp::directive(taskloop reduction)]] // expected-error {{expected '(' after 'reduction'}}123 for (int i = 0; i < 10; ++i)124 foo();125 [[omp::directive(taskloop reduction +)]] // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp taskloop' are ignored}}126 for (int i = 0; i < 10; ++i)127 foo();128 [[omp::directive(taskloop reduction())]] // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}129 for (int i = 0; i < 10; ++i)130 foo();131 [[omp::directive(taskloop reduction(*))]] // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}132 for (int i = 0; i < 10; ++i)133 foo();134 [[omp::directive(taskloop reduction(\))]] // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}135 for (int i = 0; i < 10; ++i)136 foo();137 [[omp::directive(taskloop reduction(foo : argc))]] //expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'float'}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'int'}}138 for (int i = 0; i < 10; ++i)139 foo();140 [[omp::directive(taskloop reduction(^ : T))]] // expected-error {{'T' does not refer to a value}}141 for (int i = 0; i < 10; ++i)142 foo();143 [[omp::directive(taskloop reduction(+ : z, a, b, c, d, f))]] // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 3 {{const-qualified variable cannot be reduction}} expected-error 2 {{'operator+' is a private member of 'S2'}}144 for (int i = 0; i < 10; ++i)145 foo();146 [[omp::directive(taskloop reduction(min : a, b, c, d, f))]] // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 4 {{arguments of OpenMP clause 'reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 3 {{const-qualified variable cannot be reduction}}147 for (int i = 0; i < 10; ++i)148 foo();149 [[omp::directive(taskloop reduction(max : h.b))]] // expected-error {{expected variable name, array element or array section}}150 for (int i = 0; i < 10; ++i)151 foo();152 [[omp::directive(taskloop reduction(+ : ba))]] // expected-error {{const-qualified variable cannot be reduction}}153 for (int i = 0; i < 10; ++i)154 foo();155 [[omp::directive(taskloop reduction(* : ca))]] // expected-error {{const-qualified variable cannot be reduction}}156 for (int i = 0; i < 10; ++i)157 foo();158 [[omp::directive(taskloop reduction(- : da))]] // expected-error 2 {{const-qualified variable cannot be reduction}} omp52-warning 3 {{minus(-) operator for reductions is deprecated; use + or user defined reduction instead}}159 for (int i = 0; i < 10; ++i)160 foo();161 [[omp::directive(taskloop reduction(^ : fl))]] // expected-error {{invalid operands to binary expression ('float' and 'float')}}162 for (int i = 0; i < 10; ++i)163 foo();164 [[omp::directive(taskloop reduction(&& : S2::S2s))]] // expected-error {{shared variable cannot be reduction}}165 for (int i = 0; i < 10; ++i)166 foo();167 [[omp::directive(taskloop reduction(&& : S2::S2sc))]] // expected-error {{const-qualified variable cannot be reduction}}168 for (int i = 0; i < 10; ++i)169 foo();170 [[omp::directive(taskloop reduction(+ : h, k))]] // expected-error {{threadprivate or thread local variable cannot be reduction}}171 for (int i = 0; i < 10; ++i)172 foo();173 [[omp::directive(taskloop reduction(+ : o))]] // expected-error 2 {{no viable overloaded '='}}174 for (int i = 0; i < 10; ++i)175 foo();176 [[omp::directive(taskloop private(i), reduction(+ : j), reduction(+ : q))]] // expected-error 4 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}177 for (int i = 0; i < 10; ++i)178 foo();179 [[omp::sequence(directive(parallel private(k)), directive(taskloop reduction(+ : p), reduction(+ : p)))]] // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}180 for (int i = 0; i < 10; ++i)181 foo();182 [[omp::directive(taskloop reduction(+ : p), reduction(+ : p))]] // expected-error 2 {{variable can appear only once in OpenMP 'reduction' clause}} expected-note 2 {{previously referenced here}}183 for (int i = 0; i < 10; ++i)184 foo();185 [[omp::directive(taskloop reduction(+ : r))]] // expected-error 2 {{const-qualified variable cannot be reduction}}186 for (int i = 0; i < 10; ++i)187 foo();188 [[omp::sequence(directive(parallel shared(i)), directive(parallel reduction(min : i)), directive(taskloop reduction(max : j)))]] // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}189 for (int i = 0; i < 10; ++i)190 foo();191 [[omp::sequence(directive(parallel private(fl)), directive(taskloop reduction(+ : fl) allocate(omp_thread_mem_alloc: fl)))]] // expected-warning 2 {{allocator with the 'thread' trait access has unspecified behavior on 'taskloop' directive}}192 for (int i = 0; i < 10; ++i)193 foo();194 [[omp::sequence(directive(parallel reduction(* : fl)), directive(taskloop reduction(+ : fl)))]]195 for (int i = 0; i < 10; ++i)196 foo();197 198 return T();199}200 201namespace A {202double x;203[[omp::directive(threadprivate(x))]]; // expected-note {{defined as threadprivate or thread local}}204}205namespace B {206using A::x;207}208 209int main(int argc, char **argv) {210 const int d = 5; // expected-note 2 {{'d' defined here}}211 const int da[5] = {0}; // expected-note {{'da' defined here}}212 int qa[5] = {0};213 S4 e(4);214 S5 g(5);215 int i, z;216 int &j = i; // expected-note 2 {{'j' defined here}}217 S3 &p = k; // expected-note 2 {{'p' defined here}}218 const int &r = da[i]; // expected-note {{'r' defined here}}219 int &q = qa[i]; // expected-note {{'q' defined here}}220 float fl;221 [[omp::directive(taskloop reduction)]] // expected-error {{expected '(' after 'reduction'}}222 for (int i = 0; i < 10; ++i)223 foo();224 [[omp::directive(taskloop reduction +)]] // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp taskloop' are ignored}}225 for (int i = 0; i < 10; ++i)226 foo();227 [[omp::directive(taskloop reduction())]] // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}228 for (int i = 0; i < 10; ++i)229 foo();230 [[omp::directive(taskloop reduction(*))]] // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}231 for (int i = 0; i < 10; ++i)232 foo();233 [[omp::directive(taskloop reduction(\))]] // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}234 for (int i = 0; i < 10; ++i)235 foo();236 [[omp::directive(taskloop reduction(~ : argc))]] // expected-error {{expected unqualified-id}}237 for (int i = 0; i < 10; ++i)238 foo();239 [[omp::directive(taskloop reduction(&& : argc, z))]]240 for (int i = 0; i < 10; ++i)241 foo();242 [[omp::directive(taskloop reduction(^ : S1))]] // expected-error {{'S1' does not refer to a value}}243 for (int i = 0; i < 10; ++i)244 foo();245 [[omp::directive(taskloop reduction(+ : a, b, c, d, f))]] // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 2 {{const-qualified variable cannot be reduction}} expected-error {{'operator+' is a private member of 'S2'}}246 for (int i = 0; i < 10; ++i)247 foo();248 [[omp::directive(taskloop reduction(min : a, b, c, d, f))]] // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 2 {{arguments of OpenMP clause 'reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 2 {{const-qualified variable cannot be reduction}}249 for (int i = 0; i < 10; ++i)250 foo();251 [[omp::directive(taskloop reduction(max : h.b))]] // expected-error {{expected variable name, array element or array section}}252 for (int i = 0; i < 10; ++i)253 foo();254 [[omp::directive(taskloop reduction(+ : ba))]] // expected-error {{const-qualified variable cannot be reduction}}255 for (int i = 0; i < 10; ++i)256 foo();257 [[omp::directive(taskloop reduction(* : ca))]] // expected-error {{const-qualified variable cannot be reduction}}258 for (int i = 0; i < 10; ++i)259 foo();260 [[omp::directive(taskloop reduction(- : da))]] // expected-error {{const-qualified variable cannot be reduction}} omp52-warning {{minus(-) operator for reductions is deprecated; use + or user defined reduction instead}}261 for (int i = 0; i < 10; ++i)262 foo();263 [[omp::directive(taskloop reduction(^ : fl))]] // expected-error {{invalid operands to binary expression ('float' and 'float')}}264 for (int i = 0; i < 10; ++i)265 foo();266 [[omp::directive(taskloop reduction(&& : S2::S2s))]] // expected-error {{shared variable cannot be reduction}}267 for (int i = 0; i < 10; ++i)268 foo();269 [[omp::directive(taskloop reduction(&& : S2::S2sc))]] // expected-error {{const-qualified variable cannot be reduction}}270 for (int i = 0; i < 10; ++i)271 foo();272 [[omp::directive(taskloop reduction(& : e, g))]] // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} expected-error {{invalid operands to binary expression ('S5' and 'S5')}}273 for (int i = 0; i < 10; ++i)274 foo();275 [[omp::directive(taskloop reduction(+ : h, k, B::x))]] // expected-error 2 {{threadprivate or thread local variable cannot be reduction}}276 for (int i = 0; i < 10; ++i)277 foo();278 [[omp::directive(taskloop reduction(+ : o))]] // expected-error {{no viable overloaded '='}}279 for (int i = 0; i < 10; ++i)280 foo();281 [[omp::directive(taskloop private(i), reduction(+ : j), reduction(+ : q))]] // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}282 for (int i = 0; i < 10; ++i)283 foo();284 [[omp::sequence(directive(parallel private(k)), directive(taskloop reduction(+ : p), reduction(+ : p)))]] // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}285 for (int i = 0; i < 10; ++i)286 foo();287 [[omp::directive(taskloop reduction(+ : p), reduction(+ : p))]] // expected-error {{variable can appear only once in OpenMP 'reduction' clause}} expected-note {{previously referenced here}}288 for (int i = 0; i < 10; ++i)289 foo();290 [[omp::directive(taskloop reduction(+ : r))]] // expected-error {{const-qualified variable cannot be reduction}}291 for (int i = 0; i < 10; ++i)292 foo();293 [[omp::sequence(directive(parallel shared(i)), directive(parallel reduction(min : i)), directive(taskloop reduction(max : j)))]] // expected-error {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}294 for (int i = 0; i < 10; ++i)295 foo();296 [[omp::sequence(directive(parallel private(fl)), directive(taskloop reduction(+ : fl)))]]297 for (int i = 0; i < 10; ++i)298 foo();299 [[omp::sequence(directive(parallel reduction(* : fl)), directive(taskloop reduction(+ : fl)))]]300 for (int i = 0; i < 10; ++i)301 foo();302 static int m;303 [[omp::directive(taskloop reduction(+ : m))]] // OK304 for (int i = 0; i < 10; ++i)305 m++;306 [[omp::directive(taskloop reduction(task, + : m))]] // expected-error {{'reduction' clause with 'task' modifier allowed only on non-simd parallel or worksharing constructs}}307 for (int i = 0; i < 10; ++i)308 m++;309 [[omp::directive(taskloop nogroup reduction(+ : m))]] // expected-error {{'reduction' clause cannot be used with 'nogroup' clause}}310 for (int i = 0; i < 10; ++i)311 m++;312 313 return tmain(argc) + tmain(fl); // expected-note {{in instantiation of function template specialization 'tmain<int>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<float>' requested here}}314}315 316