1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -verify %s 2 3 void foo(); 4 5 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp sections'}} 6 #pragma omp sections 7 8 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp sections'}} 9 #pragma omp sections foo 10 11 void test_no_clause() { 12 int i; 13 #pragma omp sections 14 { 15 foo(); 16 } 17 18 // expected-error@+2 {{the statement for '#pragma omp sections' must be a compound statement}} 19 #pragma omp sections 20 ++i; 21 22 #pragma omp sections 23 { 24 foo(); 25 foo(); // expected-error {{statement in 'omp sections' directive must be enclosed into a section region}} 26 } 27 } 28 29 void test_branch_protected_scope() { 30 int i = 0; 31 L1: 32 ++i; 33 34 int x[24]; 35 36 #pragma omp parallel 37 #pragma omp sections 38 { 39 if (i == 5) 40 goto L1; // expected-error {{use of undeclared label 'L1'}} 41 else if (i == 6) 42 return; // expected-error {{cannot return from OpenMP region}} 43 else if (i == 7) 44 goto L2; 45 else if (i == 8) { 46 L2: 47 x[i]++; 48 } 49 #pragma omp section 50 if (i == 5) 51 goto L1; // expected-error {{use of undeclared label 'L1'}} 52 else if (i == 6) 53 return; // expected-error {{cannot return from OpenMP region}} 54 else if (i == 7) 55 goto L3; 56 else if (i == 8) { 57 L3: 58 x[i]++; 59 } 60 } 61 62 if (x[0] == 0) 63 goto L2; // expected-error {{use of undeclared label 'L2'}} 64 else if (x[1] == 1) 65 goto L1; 66 goto L3; // expected-error {{use of undeclared label 'L3'}} 67 } 68 69 void test_invalid_clause() { 70 int i; 71 #pragma omp parallel 72 // expected-warning@+1 {{extra tokens at the end of '#pragma omp sections' are ignored}} 73 #pragma omp sections foo bar 74 { 75 foo(); 76 // expected-error@+1 {{unexpected OpenMP clause 'nowait' in directive '#pragma omp section'}} 77 #pragma omp section nowait 78 ; 79 } 80 } 81 82 void test_non_identifiers() { 83 int i, x; 84 85 #pragma omp parallel 86 // expected-warning@+1 {{extra tokens at the end of '#pragma omp sections' are ignored}} 87 #pragma omp sections; 88 { 89 foo(); 90 } 91 #pragma omp parallel 92 // expected-error@+2 {{unexpected OpenMP clause 'linear' in directive '#pragma omp sections'}} 93 // expected-warning@+1 {{extra tokens at the end of '#pragma omp sections' are ignored}} 94 #pragma omp sections linear(x); 95 { 96 foo(); 97 } 98 99 #pragma omp parallel 100 // expected-warning@+1 {{extra tokens at the end of '#pragma omp sections' are ignored}} 101 #pragma omp sections private(x); 102 { 103 foo(); 104 } 105 106 #pragma omp parallel 107 // expected-warning@+1 {{extra tokens at the end of '#pragma omp sections' are ignored}} 108 #pragma omp sections, private(x); 109 { 110 foo(); 111 } 112 } 113 114 void test_private() { 115 int i; 116 #pragma omp parallel 117 // expected-error@+2 {{expected expression}} 118 // expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}} 119 #pragma omp sections private( 120 { 121 foo(); 122 } 123 #pragma omp parallel 124 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}} 125 // expected-error@+1 2 {{expected expression}} 126 #pragma omp sections private(, 127 { 128 foo(); 129 } 130 #pragma omp parallel 131 // expected-error@+1 2 {{expected expression}} 132 #pragma omp sections private(, ) 133 { 134 foo(); 135 } 136 #pragma omp parallel 137 // expected-error@+1 {{expected expression}} 138 #pragma omp sections private() 139 { 140 foo(); 141 } 142 #pragma omp parallel 143 // expected-error@+1 {{expected expression}} 144 #pragma omp sections private(int) 145 { 146 foo(); 147 } 148 #pragma omp parallel 149 // expected-error@+1 {{expected variable name}} 150 #pragma omp sections private(0) 151 { 152 foo(); 153 } 154 155 int x, y, z; 156 #pragma omp parallel 157 #pragma omp sections private(x) 158 { 159 foo(); 160 } 161 #pragma omp parallel 162 #pragma omp sections private(x, y) 163 { 164 foo(); 165 } 166 #pragma omp parallel 167 #pragma omp sections private(x, y, z) 168 { 169 foo(); 170 } 171 } 172 173 void test_lastprivate() { 174 int i; 175 #pragma omp parallel 176 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}} 177 // expected-error@+1 {{expected expression}} 178 #pragma omp sections lastprivate( 179 { 180 foo(); 181 } 182 183 #pragma omp parallel 184 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}} 185 // expected-error@+1 2 {{expected expression}} 186 #pragma omp sections lastprivate(, 187 { 188 foo(); 189 } 190 #pragma omp parallel 191 // expected-error@+1 2 {{expected expression}} 192 #pragma omp sections lastprivate(, ) 193 { 194 foo(); 195 } 196 #pragma omp parallel 197 // expected-error@+1 {{expected expression}} 198 #pragma omp sections lastprivate() 199 { 200 foo(); 201 } 202 #pragma omp parallel 203 // expected-error@+1 {{expected expression}} 204 #pragma omp sections lastprivate(int) 205 { 206 foo(); 207 } 208 #pragma omp parallel 209 // expected-error@+1 {{expected variable name}} 210 #pragma omp sections lastprivate(0) 211 { 212 foo(); 213 } 214 215 int x, y, z; 216 #pragma omp parallel 217 #pragma omp sections lastprivate(x) 218 { 219 foo(); 220 } 221 #pragma omp parallel 222 #pragma omp sections lastprivate(x, y) 223 { 224 foo(); 225 } 226 #pragma omp parallel 227 #pragma omp sections lastprivate(x, y, z) 228 { 229 foo(); 230 } 231 } 232 233 void test_firstprivate() { 234 int i; 235 #pragma omp parallel 236 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}} 237 // expected-error@+1 {{expected expression}} 238 #pragma omp sections firstprivate( 239 { 240 foo(); 241 } 242 243 #pragma omp parallel 244 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}} 245 // expected-error@+1 2 {{expected expression}} 246 #pragma omp sections firstprivate(, 247 { 248 foo(); 249 } 250 #pragma omp parallel 251 // expected-error@+1 2 {{expected expression}} 252 #pragma omp sections firstprivate(, ) 253 { 254 foo(); 255 } 256 #pragma omp parallel 257 // expected-error@+1 {{expected expression}} 258 #pragma omp sections firstprivate() 259 { 260 foo(); 261 } 262 #pragma omp parallel 263 // expected-error@+1 {{expected expression}} 264 #pragma omp sections firstprivate(int) 265 { 266 foo(); 267 } 268 #pragma omp parallel 269 // expected-error@+1 {{expected variable name}} 270 #pragma omp sections firstprivate(0) 271 { 272 foo(); 273 } 274 275 int x, y, z; 276 #pragma omp parallel 277 #pragma omp sections lastprivate(x) firstprivate(x) 278 { 279 foo(); 280 } 281 #pragma omp parallel 282 #pragma omp sections lastprivate(x, y) firstprivate(x, y) 283 { 284 foo(); 285 } 286 #pragma omp parallel 287 #pragma omp sections lastprivate(x, y, z) firstprivate(x, y, z) 288 { 289 foo(); 290 } 291 } 292 293 void test_nowait() { 294 #pragma omp parallel 295 #pragma omp sections nowait nowait // expected-error {{directive '#pragma omp sections' cannot contain more than one 'nowait' clause}} 296 { 297 ; 298 } 299 } 300