1 // RUN: %clang_cc1 -verify=expected,omp45 -fopenmp -ferror-limit 100 -std=c++11 -o - %s -fopenmp-version=45 -Wuninitialized
2 // RUN: %clang_cc1 -verify=expected,omp50 -fopenmp -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized
3 
4 // RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-simd -ferror-limit 100 -std=c++11 -o - %s -fopenmp-version=45 -Wuninitialized
5 // RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-simd -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized
6 
foo()7 void foo() {
8 }
9 
xxx(int argc)10 void xxx(int argc) {
11   int x; // expected-note {{initialize the variable 'x' to silence this warning}}
12 #pragma omp distribute parallel for
13   for (int i = 0; i < 10; ++i)
14     argc = x; // expected-warning {{variable 'x' is uninitialized when used here}}
15 }
16 
17 #pragma omp distribute parallel for // expected-error {{unexpected OpenMP directive '#pragma omp distribute parallel for'}}
18 
main(int argc,char ** argv)19 int main(int argc, char **argv) {
20 #pragma omp distribute parallel for order // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp distribute parallel for'}} expected-error {{expected '(' after 'order'}}
21   for (int i = 0; i < argc; ++i)
22     foo();
23 #pragma omp distribute parallel for order( // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp distribute parallel for'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}}
24   for (int i = 0; i < argc; ++i)
25     foo();
26 #pragma omp distribute parallel for order(none // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp distribute parallel for'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}}
27   for (int i = 0; i < argc; ++i)
28     foo();
29 #pragma omp distribute parallel for order(concurrent // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp distribute parallel for'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
30   for (int i = 0; i < argc; ++i)
31     foo();
32 #pragma omp distribute parallel for order(concurrent) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp distribute parallel for'}}
33   for (int i = 0; i < argc; ++i)
34     foo();
35 #pragma omp target
36 #pragma omp teams
37 #pragma omp distribute parallel for { // expected-warning {{extra tokens at the end of '#pragma omp distribute parallel for' are ignored}}
38   for (int i = 0; i < argc; ++i)
39     foo();
40 #pragma omp target
41 #pragma omp teams
42 #pragma omp distribute parallel for ( // expected-warning {{extra tokens at the end of '#pragma omp distribute parallel for' are ignored}}
43   for (int i = 0; i < argc; ++i)
44     foo();
45 #pragma omp target
46 #pragma omp teams
47 #pragma omp distribute parallel for[ // expected-warning {{extra tokens at the end of '#pragma omp distribute parallel for' are ignored}}
48   for (int i = 0; i < argc; ++i)
49     foo();
50 #pragma omp target
51 #pragma omp teams
52 #pragma omp distribute parallel for] // expected-warning {{extra tokens at the end of '#pragma omp distribute parallel for' are ignored}}
53   for (int i = 0; i < argc; ++i)
54     foo();
55 #pragma omp target
56 #pragma omp teams
57 #pragma omp distribute parallel for) // expected-warning {{extra tokens at the end of '#pragma omp distribute parallel for' are ignored}}
58   for (int i = 0; i < argc; ++i)
59     foo();
60 #pragma omp target
61 #pragma omp teams
62 #pragma omp distribute parallel for } // expected-warning {{extra tokens at the end of '#pragma omp distribute parallel for' are ignored}}
63   for (int i = 0; i < argc; ++i)
64     foo();
65 #pragma omp target
66 #pragma omp teams
67 #pragma omp distribute parallel for linear(argc) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp distribute parallel for'}}
68   for (int i = 0; i < argc; ++i)
69     foo();
70 #pragma omp target
71 #pragma omp teams
72 #pragma omp distribute parallel for unknown()   // expected-warning {{extra tokens at the end of '#pragma omp distribute parallel for' are ignored}}
73   for (int i = 0; i < argc; ++i)
74     foo();
75 L1:
76   for (int i = 0; i < argc; ++i)
77     foo();
78 #pragma omp target
79 #pragma omp teams
80 #pragma omp distribute parallel for
81   for (int i = 0; i < argc; ++i)
82     foo();
83 #pragma omp target
84 #pragma omp teams
85 #pragma omp distribute parallel for
86   for (int i = 0; i < argc; ++i) {
87     goto L1; // expected-error {{use of undeclared label 'L1'}}
88     argc++;
89   }
90 
91   for (int i = 0; i < 10; ++i) {
92     switch (argc) {
93     case (0):
94 #pragma omp target
95 #pragma omp teams
96 #pragma omp distribute parallel for
97       for (int i = 0; i < argc; ++i) {
98         foo();
99         break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
100         continue;
101       }
102     default:
103       break;
104     }
105   }
106 #pragma omp target
107 #pragma omp teams
108 #pragma omp distribute parallel for default(none) // expected-note {{explicit data sharing attribute requested here}}
109   for (int i = 0; i < 10; ++i)
110     ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
111 
112   goto L2; // expected-error {{use of undeclared label 'L2'}}
113 #pragma omp target
114 #pragma omp teams
115 #pragma omp distribute parallel for
116   for (int i = 0; i < argc; ++i)
117   L2:
118   foo();
119 #pragma omp target
120 #pragma omp teams
121 #pragma omp distribute parallel for
122   for (int i = 0; i < argc; ++i) {
123     return 1; // expected-error {{cannot return from OpenMP region}}
124   }
125 
126   [[]] // expected-error {{an attribute list cannot appear here}}
127 #pragma omp target
128 #pragma omp teams
129 #pragma omp distribute parallel for
130       for (int n = 0; n < 100; ++n) {
131   }
132 
133   return 0;
134 }
135 
test_ordered()136 void test_ordered() {
137 #pragma omp target
138 #pragma omp teams
139 #pragma omp distribute parallel for collapse(2) collapse(3) // expected-error {{directive '#pragma omp distribute parallel for' cannot contain more than one 'collapse' clause}}
140   for (int i = 0; i < 16; ++i)
141     for (int j = 0; j < 16; ++j)
142     ;
143 }
144 
test_cancel()145 void test_cancel() {
146 #pragma omp target
147 #pragma omp teams
148 #pragma omp distribute parallel for
149   for (int i = 0; i < 16; ++i)
150     for (int j = 0; j < 16; ++j) {
151 #pragma omp cancel for
152     ;
153     }
154 }
155 
156