blob: 2e5e36242ed5464bc566f7b80bb4a217a6dcf9aa [file] [log] [blame]
Alexey Bataeva769e072013-03-22 06:34:35 +00001//===--- ParseOpenMP.cpp - OpenMP directives parsing ----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9/// \file
10/// \brief This file implements parsing of all OpenMP directives and clauses.
11///
12//===----------------------------------------------------------------------===//
13
Alexey Bataev9959db52014-05-06 10:08:46 +000014#include "clang/AST/ASTContext.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000015#include "clang/AST/StmtOpenMP.h"
Alexey Bataeva769e072013-03-22 06:34:35 +000016#include "clang/Parse/ParseDiagnostic.h"
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000017#include "clang/Parse/Parser.h"
Vassil Vassilev11ad3392017-03-23 15:11:07 +000018#include "clang/Parse/RAIIObjectsForParser.h"
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000019#include "clang/Sema/Scope.h"
20#include "llvm/ADT/PointerIntPair.h"
Michael Wong65f367f2015-07-21 13:44:28 +000021
Alexey Bataeva769e072013-03-22 06:34:35 +000022using namespace clang;
23
24//===----------------------------------------------------------------------===//
25// OpenMP declarative directives.
26//===----------------------------------------------------------------------===//
27
Dmitry Polukhin82478332016-02-13 06:53:38 +000028namespace {
29enum OpenMPDirectiveKindEx {
30 OMPD_cancellation = OMPD_unknown + 1,
31 OMPD_data,
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000032 OMPD_declare,
Dmitry Polukhin0b0da292016-04-06 11:38:59 +000033 OMPD_end,
34 OMPD_end_declare,
Dmitry Polukhin82478332016-02-13 06:53:38 +000035 OMPD_enter,
36 OMPD_exit,
37 OMPD_point,
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000038 OMPD_reduction,
Dmitry Polukhin82478332016-02-13 06:53:38 +000039 OMPD_target_enter,
Samuel Antao686c70c2016-05-26 17:30:50 +000040 OMPD_target_exit,
41 OMPD_update,
Kelvin Li579e41c2016-11-30 23:51:03 +000042 OMPD_distribute_parallel,
Kelvin Li80e8f562016-12-29 22:16:30 +000043 OMPD_teams_distribute_parallel,
44 OMPD_target_teams_distribute_parallel
Dmitry Polukhin82478332016-02-13 06:53:38 +000045};
Dmitry Polukhind69b5052016-05-09 14:59:13 +000046
47class ThreadprivateListParserHelper final {
48 SmallVector<Expr *, 4> Identifiers;
49 Parser *P;
50
51public:
52 ThreadprivateListParserHelper(Parser *P) : P(P) {}
53 void operator()(CXXScopeSpec &SS, DeclarationNameInfo NameInfo) {
54 ExprResult Res =
55 P->getActions().ActOnOpenMPIdExpression(P->getCurScope(), SS, NameInfo);
56 if (Res.isUsable())
57 Identifiers.push_back(Res.get());
58 }
59 llvm::ArrayRef<Expr *> getIdentifiers() const { return Identifiers; }
60};
Dmitry Polukhin82478332016-02-13 06:53:38 +000061} // namespace
62
63// Map token string to extended OMP token kind that are
64// OpenMPDirectiveKind + OpenMPDirectiveKindEx.
65static unsigned getOpenMPDirectiveKindEx(StringRef S) {
66 auto DKind = getOpenMPDirectiveKind(S);
67 if (DKind != OMPD_unknown)
68 return DKind;
69
70 return llvm::StringSwitch<unsigned>(S)
71 .Case("cancellation", OMPD_cancellation)
72 .Case("data", OMPD_data)
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000073 .Case("declare", OMPD_declare)
Dmitry Polukhin0b0da292016-04-06 11:38:59 +000074 .Case("end", OMPD_end)
Dmitry Polukhin82478332016-02-13 06:53:38 +000075 .Case("enter", OMPD_enter)
76 .Case("exit", OMPD_exit)
77 .Case("point", OMPD_point)
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000078 .Case("reduction", OMPD_reduction)
Samuel Antao686c70c2016-05-26 17:30:50 +000079 .Case("update", OMPD_update)
Dmitry Polukhin82478332016-02-13 06:53:38 +000080 .Default(OMPD_unknown);
81}
82
Alexey Bataev4acb8592014-07-07 13:01:15 +000083static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) {
Alexander Musmanf82886e2014-09-18 05:12:34 +000084 // Array of foldings: F[i][0] F[i][1] ===> F[i][2].
85 // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd
86 // TODO: add other combined directives in topological order.
Dmitry Polukhin82478332016-02-13 06:53:38 +000087 static const unsigned F[][3] = {
88 { OMPD_cancellation, OMPD_point, OMPD_cancellation_point },
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000089 { OMPD_declare, OMPD_reduction, OMPD_declare_reduction },
Alexey Bataev587e1de2016-03-30 10:43:55 +000090 { OMPD_declare, OMPD_simd, OMPD_declare_simd },
Dmitry Polukhin0b0da292016-04-06 11:38:59 +000091 { OMPD_declare, OMPD_target, OMPD_declare_target },
Carlo Bertolli9925f152016-06-27 14:55:37 +000092 { OMPD_distribute, OMPD_parallel, OMPD_distribute_parallel },
93 { OMPD_distribute_parallel, OMPD_for, OMPD_distribute_parallel_for },
Kelvin Li4a39add2016-07-05 05:00:15 +000094 { OMPD_distribute_parallel_for, OMPD_simd,
95 OMPD_distribute_parallel_for_simd },
Kelvin Li787f3fc2016-07-06 04:45:38 +000096 { OMPD_distribute, OMPD_simd, OMPD_distribute_simd },
Dmitry Polukhin0b0da292016-04-06 11:38:59 +000097 { OMPD_end, OMPD_declare, OMPD_end_declare },
98 { OMPD_end_declare, OMPD_target, OMPD_end_declare_target },
Dmitry Polukhin82478332016-02-13 06:53:38 +000099 { OMPD_target, OMPD_data, OMPD_target_data },
100 { OMPD_target, OMPD_enter, OMPD_target_enter },
101 { OMPD_target, OMPD_exit, OMPD_target_exit },
Samuel Antao686c70c2016-05-26 17:30:50 +0000102 { OMPD_target, OMPD_update, OMPD_target_update },
Dmitry Polukhin82478332016-02-13 06:53:38 +0000103 { OMPD_target_enter, OMPD_data, OMPD_target_enter_data },
104 { OMPD_target_exit, OMPD_data, OMPD_target_exit_data },
105 { OMPD_for, OMPD_simd, OMPD_for_simd },
106 { OMPD_parallel, OMPD_for, OMPD_parallel_for },
107 { OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd },
108 { OMPD_parallel, OMPD_sections, OMPD_parallel_sections },
109 { OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd },
110 { OMPD_target, OMPD_parallel, OMPD_target_parallel },
Kelvin Li986330c2016-07-20 22:57:10 +0000111 { OMPD_target, OMPD_simd, OMPD_target_simd },
Kelvin Lia579b912016-07-14 02:54:56 +0000112 { OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for },
Kelvin Li02532872016-08-05 14:37:37 +0000113 { OMPD_target_parallel_for, OMPD_simd, OMPD_target_parallel_for_simd },
Kelvin Li4e325f72016-10-25 12:50:55 +0000114 { OMPD_teams, OMPD_distribute, OMPD_teams_distribute },
Kelvin Li579e41c2016-11-30 23:51:03 +0000115 { OMPD_teams_distribute, OMPD_simd, OMPD_teams_distribute_simd },
116 { OMPD_teams_distribute, OMPD_parallel, OMPD_teams_distribute_parallel },
117 { OMPD_teams_distribute_parallel, OMPD_for, OMPD_teams_distribute_parallel_for },
Kelvin Libf594a52016-12-17 05:48:59 +0000118 { OMPD_teams_distribute_parallel_for, OMPD_simd, OMPD_teams_distribute_parallel_for_simd },
Kelvin Li83c451e2016-12-25 04:52:54 +0000119 { OMPD_target, OMPD_teams, OMPD_target_teams },
Kelvin Li80e8f562016-12-29 22:16:30 +0000120 { OMPD_target_teams, OMPD_distribute, OMPD_target_teams_distribute },
121 { OMPD_target_teams_distribute, OMPD_parallel, OMPD_target_teams_distribute_parallel },
Kelvin Lida681182017-01-10 18:08:18 +0000122 { OMPD_target_teams_distribute, OMPD_simd, OMPD_target_teams_distribute_simd },
Kelvin Li1851df52017-01-03 05:23:48 +0000123 { OMPD_target_teams_distribute_parallel, OMPD_for, OMPD_target_teams_distribute_parallel_for },
124 { OMPD_target_teams_distribute_parallel_for, OMPD_simd, OMPD_target_teams_distribute_parallel_for_simd }
Dmitry Polukhin82478332016-02-13 06:53:38 +0000125 };
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000126 enum { CancellationPoint = 0, DeclareReduction = 1, TargetData = 2 };
Alexey Bataev4acb8592014-07-07 13:01:15 +0000127 auto Tok = P.getCurToken();
Dmitry Polukhin82478332016-02-13 06:53:38 +0000128 unsigned DKind =
Alexey Bataev4acb8592014-07-07 13:01:15 +0000129 Tok.isAnnotation()
Dmitry Polukhin82478332016-02-13 06:53:38 +0000130 ? static_cast<unsigned>(OMPD_unknown)
131 : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok));
132 if (DKind == OMPD_unknown)
133 return OMPD_unknown;
Michael Wong65f367f2015-07-21 13:44:28 +0000134
Alexander Musmanf82886e2014-09-18 05:12:34 +0000135 for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) {
Dmitry Polukhin82478332016-02-13 06:53:38 +0000136 if (DKind != F[i][0])
137 continue;
Michael Wong65f367f2015-07-21 13:44:28 +0000138
Dmitry Polukhin82478332016-02-13 06:53:38 +0000139 Tok = P.getPreprocessor().LookAhead(0);
140 unsigned SDKind =
141 Tok.isAnnotation()
142 ? static_cast<unsigned>(OMPD_unknown)
143 : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok));
144 if (SDKind == OMPD_unknown)
145 continue;
Michael Wong65f367f2015-07-21 13:44:28 +0000146
Dmitry Polukhin82478332016-02-13 06:53:38 +0000147 if (SDKind == F[i][1]) {
148 P.ConsumeToken();
149 DKind = F[i][2];
Alexey Bataev4acb8592014-07-07 13:01:15 +0000150 }
151 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000152 return DKind < OMPD_unknown ? static_cast<OpenMPDirectiveKind>(DKind)
153 : OMPD_unknown;
154}
155
156static DeclarationName parseOpenMPReductionId(Parser &P) {
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000157 Token Tok = P.getCurToken();
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000158 Sema &Actions = P.getActions();
159 OverloadedOperatorKind OOK = OO_None;
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000160 // Allow to use 'operator' keyword for C++ operators
161 bool WithOperator = false;
162 if (Tok.is(tok::kw_operator)) {
163 P.ConsumeToken();
164 Tok = P.getCurToken();
165 WithOperator = true;
166 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000167 switch (Tok.getKind()) {
168 case tok::plus: // '+'
169 OOK = OO_Plus;
170 break;
171 case tok::minus: // '-'
172 OOK = OO_Minus;
173 break;
174 case tok::star: // '*'
175 OOK = OO_Star;
176 break;
177 case tok::amp: // '&'
178 OOK = OO_Amp;
179 break;
180 case tok::pipe: // '|'
181 OOK = OO_Pipe;
182 break;
183 case tok::caret: // '^'
184 OOK = OO_Caret;
185 break;
186 case tok::ampamp: // '&&'
187 OOK = OO_AmpAmp;
188 break;
189 case tok::pipepipe: // '||'
190 OOK = OO_PipePipe;
191 break;
192 case tok::identifier: // identifier
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000193 if (!WithOperator)
194 break;
Galina Kistanova474f2ce2017-06-01 21:26:38 +0000195 LLVM_FALLTHROUGH;
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000196 default:
197 P.Diag(Tok.getLocation(), diag::err_omp_expected_reduction_identifier);
198 P.SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
199 Parser::StopBeforeMatch);
200 return DeclarationName();
201 }
202 P.ConsumeToken();
203 auto &DeclNames = Actions.getASTContext().DeclarationNames;
204 return OOK == OO_None ? DeclNames.getIdentifier(Tok.getIdentifierInfo())
205 : DeclNames.getCXXOperatorName(OOK);
206}
207
208/// \brief Parse 'omp declare reduction' construct.
209///
210/// declare-reduction-directive:
211/// annot_pragma_openmp 'declare' 'reduction'
212/// '(' <reduction_id> ':' <type> {',' <type>} ':' <expression> ')'
213/// ['initializer' '(' ('omp_priv' '=' <expression>)|<function_call> ')']
214/// annot_pragma_openmp_end
215/// <reduction_id> is either a base language identifier or one of the following
216/// operators: '+', '-', '*', '&', '|', '^', '&&' and '||'.
217///
218Parser::DeclGroupPtrTy
219Parser::ParseOpenMPDeclareReductionDirective(AccessSpecifier AS) {
220 // Parse '('.
221 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
222 if (T.expectAndConsume(diag::err_expected_lparen_after,
223 getOpenMPDirectiveName(OMPD_declare_reduction))) {
224 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
225 return DeclGroupPtrTy();
226 }
227
228 DeclarationName Name = parseOpenMPReductionId(*this);
229 if (Name.isEmpty() && Tok.is(tok::annot_pragma_openmp_end))
230 return DeclGroupPtrTy();
231
232 // Consume ':'.
233 bool IsCorrect = !ExpectAndConsume(tok::colon);
234
235 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
236 return DeclGroupPtrTy();
237
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000238 IsCorrect = IsCorrect && !Name.isEmpty();
239
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000240 if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end)) {
241 Diag(Tok.getLocation(), diag::err_expected_type);
242 IsCorrect = false;
243 }
244
245 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
246 return DeclGroupPtrTy();
247
248 SmallVector<std::pair<QualType, SourceLocation>, 8> ReductionTypes;
249 // Parse list of types until ':' token.
250 do {
251 ColonProtectionRAIIObject ColonRAII(*this);
252 SourceRange Range;
253 TypeResult TR = ParseTypeName(&Range, Declarator::PrototypeContext, AS);
254 if (TR.isUsable()) {
255 auto ReductionType =
256 Actions.ActOnOpenMPDeclareReductionType(Range.getBegin(), TR);
257 if (!ReductionType.isNull()) {
258 ReductionTypes.push_back(
259 std::make_pair(ReductionType, Range.getBegin()));
260 }
261 } else {
262 SkipUntil(tok::comma, tok::colon, tok::annot_pragma_openmp_end,
263 StopBeforeMatch);
264 }
265
266 if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end))
267 break;
268
269 // Consume ','.
270 if (ExpectAndConsume(tok::comma)) {
271 IsCorrect = false;
272 if (Tok.is(tok::annot_pragma_openmp_end)) {
273 Diag(Tok.getLocation(), diag::err_expected_type);
274 return DeclGroupPtrTy();
275 }
276 }
277 } while (Tok.isNot(tok::annot_pragma_openmp_end));
278
279 if (ReductionTypes.empty()) {
280 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
281 return DeclGroupPtrTy();
282 }
283
284 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
285 return DeclGroupPtrTy();
286
287 // Consume ':'.
288 if (ExpectAndConsume(tok::colon))
289 IsCorrect = false;
290
291 if (Tok.is(tok::annot_pragma_openmp_end)) {
292 Diag(Tok.getLocation(), diag::err_expected_expression);
293 return DeclGroupPtrTy();
294 }
295
296 DeclGroupPtrTy DRD = Actions.ActOnOpenMPDeclareReductionDirectiveStart(
297 getCurScope(), Actions.getCurLexicalContext(), Name, ReductionTypes, AS);
298
299 // Parse <combiner> expression and then parse initializer if any for each
300 // correct type.
301 unsigned I = 0, E = ReductionTypes.size();
302 for (auto *D : DRD.get()) {
303 TentativeParsingAction TPA(*this);
304 ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope |
305 Scope::OpenMPDirectiveScope);
306 // Parse <combiner> expression.
307 Actions.ActOnOpenMPDeclareReductionCombinerStart(getCurScope(), D);
308 ExprResult CombinerResult =
309 Actions.ActOnFinishFullExpr(ParseAssignmentExpression().get(),
310 D->getLocation(), /*DiscardedValue=*/true);
311 Actions.ActOnOpenMPDeclareReductionCombinerEnd(D, CombinerResult.get());
312
313 if (CombinerResult.isInvalid() && Tok.isNot(tok::r_paren) &&
314 Tok.isNot(tok::annot_pragma_openmp_end)) {
315 TPA.Commit();
316 IsCorrect = false;
317 break;
318 }
319 IsCorrect = !T.consumeClose() && IsCorrect && CombinerResult.isUsable();
320 ExprResult InitializerResult;
321 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
322 // Parse <initializer> expression.
323 if (Tok.is(tok::identifier) &&
324 Tok.getIdentifierInfo()->isStr("initializer"))
325 ConsumeToken();
326 else {
327 Diag(Tok.getLocation(), diag::err_expected) << "'initializer'";
328 TPA.Commit();
329 IsCorrect = false;
330 break;
331 }
332 // Parse '('.
333 BalancedDelimiterTracker T(*this, tok::l_paren,
334 tok::annot_pragma_openmp_end);
335 IsCorrect =
336 !T.expectAndConsume(diag::err_expected_lparen_after, "initializer") &&
337 IsCorrect;
338 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
339 ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope |
340 Scope::OpenMPDirectiveScope);
341 // Parse expression.
342 Actions.ActOnOpenMPDeclareReductionInitializerStart(getCurScope(), D);
343 InitializerResult = Actions.ActOnFinishFullExpr(
344 ParseAssignmentExpression().get(), D->getLocation(),
345 /*DiscardedValue=*/true);
346 Actions.ActOnOpenMPDeclareReductionInitializerEnd(
347 D, InitializerResult.get());
348 if (InitializerResult.isInvalid() && Tok.isNot(tok::r_paren) &&
349 Tok.isNot(tok::annot_pragma_openmp_end)) {
350 TPA.Commit();
351 IsCorrect = false;
352 break;
353 }
354 IsCorrect =
355 !T.consumeClose() && IsCorrect && !InitializerResult.isInvalid();
356 }
357 }
358
359 ++I;
360 // Revert parsing if not the last type, otherwise accept it, we're done with
361 // parsing.
362 if (I != E)
363 TPA.Revert();
364 else
365 TPA.Commit();
366 }
367 return Actions.ActOnOpenMPDeclareReductionDirectiveEnd(getCurScope(), DRD,
368 IsCorrect);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000369}
370
Alexey Bataev2af33e32016-04-07 12:45:37 +0000371namespace {
372/// RAII that recreates function context for correct parsing of clauses of
373/// 'declare simd' construct.
374/// OpenMP, 2.8.2 declare simd Construct
375/// The expressions appearing in the clauses of this directive are evaluated in
376/// the scope of the arguments of the function declaration or definition.
377class FNContextRAII final {
378 Parser &P;
379 Sema::CXXThisScopeRAII *ThisScope;
380 Parser::ParseScope *TempScope;
381 Parser::ParseScope *FnScope;
382 bool HasTemplateScope = false;
383 bool HasFunScope = false;
384 FNContextRAII() = delete;
385 FNContextRAII(const FNContextRAII &) = delete;
386 FNContextRAII &operator=(const FNContextRAII &) = delete;
387
388public:
389 FNContextRAII(Parser &P, Parser::DeclGroupPtrTy Ptr) : P(P) {
390 Decl *D = *Ptr.get().begin();
391 NamedDecl *ND = dyn_cast<NamedDecl>(D);
392 RecordDecl *RD = dyn_cast_or_null<RecordDecl>(D->getDeclContext());
393 Sema &Actions = P.getActions();
394
395 // Allow 'this' within late-parsed attributes.
396 ThisScope = new Sema::CXXThisScopeRAII(Actions, RD, /*TypeQuals=*/0,
397 ND && ND->isCXXInstanceMember());
398
399 // If the Decl is templatized, add template parameters to scope.
400 HasTemplateScope = D->isTemplateDecl();
401 TempScope =
402 new Parser::ParseScope(&P, Scope::TemplateParamScope, HasTemplateScope);
403 if (HasTemplateScope)
404 Actions.ActOnReenterTemplateScope(Actions.getCurScope(), D);
405
406 // If the Decl is on a function, add function parameters to the scope.
407 HasFunScope = D->isFunctionOrFunctionTemplate();
408 FnScope = new Parser::ParseScope(&P, Scope::FnScope | Scope::DeclScope,
409 HasFunScope);
410 if (HasFunScope)
411 Actions.ActOnReenterFunctionContext(Actions.getCurScope(), D);
412 }
413 ~FNContextRAII() {
414 if (HasFunScope) {
415 P.getActions().ActOnExitFunctionContext();
416 FnScope->Exit(); // Pop scope, and remove Decls from IdResolver
417 }
418 if (HasTemplateScope)
419 TempScope->Exit();
420 delete FnScope;
421 delete TempScope;
422 delete ThisScope;
423 }
424};
425} // namespace
426
Alexey Bataevd93d3762016-04-12 09:35:56 +0000427/// Parses clauses for 'declare simd' directive.
428/// clause:
429/// 'inbranch' | 'notinbranch'
430/// 'simdlen' '(' <expr> ')'
431/// { 'uniform' '(' <argument_list> ')' }
432/// { 'aligned '(' <argument_list> [ ':' <alignment> ] ')' }
Alexey Bataevecba70f2016-04-12 11:02:11 +0000433/// { 'linear '(' <argument_list> [ ':' <step> ] ')' }
434static bool parseDeclareSimdClauses(
435 Parser &P, OMPDeclareSimdDeclAttr::BranchStateTy &BS, ExprResult &SimdLen,
436 SmallVectorImpl<Expr *> &Uniforms, SmallVectorImpl<Expr *> &Aligneds,
437 SmallVectorImpl<Expr *> &Alignments, SmallVectorImpl<Expr *> &Linears,
438 SmallVectorImpl<unsigned> &LinModifiers, SmallVectorImpl<Expr *> &Steps) {
Alexey Bataevd93d3762016-04-12 09:35:56 +0000439 SourceRange BSRange;
440 const Token &Tok = P.getCurToken();
441 bool IsError = false;
442 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
443 if (Tok.isNot(tok::identifier))
444 break;
445 OMPDeclareSimdDeclAttr::BranchStateTy Out;
446 IdentifierInfo *II = Tok.getIdentifierInfo();
447 StringRef ClauseName = II->getName();
448 // Parse 'inranch|notinbranch' clauses.
449 if (OMPDeclareSimdDeclAttr::ConvertStrToBranchStateTy(ClauseName, Out)) {
450 if (BS != OMPDeclareSimdDeclAttr::BS_Undefined && BS != Out) {
451 P.Diag(Tok, diag::err_omp_declare_simd_inbranch_notinbranch)
452 << ClauseName
453 << OMPDeclareSimdDeclAttr::ConvertBranchStateTyToStr(BS) << BSRange;
454 IsError = true;
455 }
456 BS = Out;
457 BSRange = SourceRange(Tok.getLocation(), Tok.getEndLoc());
458 P.ConsumeToken();
459 } else if (ClauseName.equals("simdlen")) {
460 if (SimdLen.isUsable()) {
461 P.Diag(Tok, diag::err_omp_more_one_clause)
462 << getOpenMPDirectiveName(OMPD_declare_simd) << ClauseName << 0;
463 IsError = true;
464 }
465 P.ConsumeToken();
466 SourceLocation RLoc;
467 SimdLen = P.ParseOpenMPParensExpr(ClauseName, RLoc);
468 if (SimdLen.isInvalid())
469 IsError = true;
470 } else {
471 OpenMPClauseKind CKind = getOpenMPClauseKind(ClauseName);
Alexey Bataevecba70f2016-04-12 11:02:11 +0000472 if (CKind == OMPC_uniform || CKind == OMPC_aligned ||
473 CKind == OMPC_linear) {
Alexey Bataevd93d3762016-04-12 09:35:56 +0000474 Parser::OpenMPVarListDataTy Data;
475 auto *Vars = &Uniforms;
Alexey Bataevecba70f2016-04-12 11:02:11 +0000476 if (CKind == OMPC_aligned)
Alexey Bataevd93d3762016-04-12 09:35:56 +0000477 Vars = &Aligneds;
Alexey Bataevecba70f2016-04-12 11:02:11 +0000478 else if (CKind == OMPC_linear)
479 Vars = &Linears;
Alexey Bataevd93d3762016-04-12 09:35:56 +0000480
481 P.ConsumeToken();
482 if (P.ParseOpenMPVarList(OMPD_declare_simd,
483 getOpenMPClauseKind(ClauseName), *Vars, Data))
484 IsError = true;
485 if (CKind == OMPC_aligned)
486 Alignments.append(Aligneds.size() - Alignments.size(), Data.TailExpr);
Alexey Bataevecba70f2016-04-12 11:02:11 +0000487 else if (CKind == OMPC_linear) {
488 if (P.getActions().CheckOpenMPLinearModifier(Data.LinKind,
489 Data.DepLinMapLoc))
490 Data.LinKind = OMPC_LINEAR_val;
491 LinModifiers.append(Linears.size() - LinModifiers.size(),
492 Data.LinKind);
493 Steps.append(Linears.size() - Steps.size(), Data.TailExpr);
494 }
Alexey Bataevd93d3762016-04-12 09:35:56 +0000495 } else
496 // TODO: add parsing of other clauses.
497 break;
498 }
499 // Skip ',' if any.
500 if (Tok.is(tok::comma))
501 P.ConsumeToken();
502 }
503 return IsError;
504}
505
Alexey Bataev2af33e32016-04-07 12:45:37 +0000506/// Parse clauses for '#pragma omp declare simd'.
507Parser::DeclGroupPtrTy
508Parser::ParseOMPDeclareSimdClauses(Parser::DeclGroupPtrTy Ptr,
509 CachedTokens &Toks, SourceLocation Loc) {
510 PP.EnterToken(Tok);
511 PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true);
512 // Consume the previously pushed token.
513 ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
514
515 FNContextRAII FnContext(*this, Ptr);
516 OMPDeclareSimdDeclAttr::BranchStateTy BS =
517 OMPDeclareSimdDeclAttr::BS_Undefined;
518 ExprResult Simdlen;
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000519 SmallVector<Expr *, 4> Uniforms;
Alexey Bataevd93d3762016-04-12 09:35:56 +0000520 SmallVector<Expr *, 4> Aligneds;
521 SmallVector<Expr *, 4> Alignments;
Alexey Bataevecba70f2016-04-12 11:02:11 +0000522 SmallVector<Expr *, 4> Linears;
523 SmallVector<unsigned, 4> LinModifiers;
524 SmallVector<Expr *, 4> Steps;
525 bool IsError =
526 parseDeclareSimdClauses(*this, BS, Simdlen, Uniforms, Aligneds,
527 Alignments, Linears, LinModifiers, Steps);
Alexey Bataev2af33e32016-04-07 12:45:37 +0000528 // Need to check for extra tokens.
529 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
530 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
531 << getOpenMPDirectiveName(OMPD_declare_simd);
532 while (Tok.isNot(tok::annot_pragma_openmp_end))
533 ConsumeAnyToken();
534 }
535 // Skip the last annot_pragma_openmp_end.
Richard Smithaf3b3252017-05-18 19:21:48 +0000536 SourceLocation EndLoc = ConsumeAnnotationToken();
Alexey Bataevd93d3762016-04-12 09:35:56 +0000537 if (!IsError) {
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000538 return Actions.ActOnOpenMPDeclareSimdDirective(
Alexey Bataevecba70f2016-04-12 11:02:11 +0000539 Ptr, BS, Simdlen.get(), Uniforms, Aligneds, Alignments, Linears,
540 LinModifiers, Steps, SourceRange(Loc, EndLoc));
Alexey Bataevd93d3762016-04-12 09:35:56 +0000541 }
Alexey Bataev2af33e32016-04-07 12:45:37 +0000542 return Ptr;
Alexey Bataev20dfd772016-04-04 10:12:15 +0000543}
544
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000545/// \brief Parsing of declarative OpenMP directives.
546///
547/// threadprivate-directive:
548/// annot_pragma_openmp 'threadprivate' simple-variable-list
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000549/// annot_pragma_openmp_end
Alexey Bataeva769e072013-03-22 06:34:35 +0000550///
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000551/// declare-reduction-directive:
552/// annot_pragma_openmp 'declare' 'reduction' [...]
553/// annot_pragma_openmp_end
554///
Alexey Bataev587e1de2016-03-30 10:43:55 +0000555/// declare-simd-directive:
556/// annot_pragma_openmp 'declare simd' {<clause> [,]}
557/// annot_pragma_openmp_end
558/// <function declaration/definition>
559///
560Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
561 AccessSpecifier &AS, ParsedAttributesWithRange &Attrs,
562 DeclSpec::TST TagType, Decl *Tag) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000563 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
Alexey Bataevee6507d2013-11-18 08:17:37 +0000564 ParenBraceBracketBalancer BalancerRAIIObj(*this);
Alexey Bataeva769e072013-03-22 06:34:35 +0000565
Richard Smithaf3b3252017-05-18 19:21:48 +0000566 SourceLocation Loc = ConsumeAnnotationToken();
Alexey Bataev4acb8592014-07-07 13:01:15 +0000567 auto DKind = ParseOpenMPDirectiveKind(*this);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000568
569 switch (DKind) {
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000570 case OMPD_threadprivate: {
Alexey Bataeva769e072013-03-22 06:34:35 +0000571 ConsumeToken();
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000572 ThreadprivateListParserHelper Helper(this);
573 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Helper, true)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000574 // The last seen token is annot_pragma_openmp_end - need to check for
575 // extra tokens.
576 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
577 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000578 << getOpenMPDirectiveName(OMPD_threadprivate);
Alp Tokerd751fa72013-12-18 19:10:49 +0000579 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataeva769e072013-03-22 06:34:35 +0000580 }
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000581 // Skip the last annot_pragma_openmp_end.
Richard Smithaf3b3252017-05-18 19:21:48 +0000582 ConsumeAnnotationToken();
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000583 return Actions.ActOnOpenMPThreadprivateDirective(Loc,
584 Helper.getIdentifiers());
Alexey Bataeva769e072013-03-22 06:34:35 +0000585 }
586 break;
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000587 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000588 case OMPD_declare_reduction:
589 ConsumeToken();
590 if (auto Res = ParseOpenMPDeclareReductionDirective(AS)) {
591 // The last seen token is annot_pragma_openmp_end - need to check for
592 // extra tokens.
593 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
594 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
595 << getOpenMPDirectiveName(OMPD_declare_reduction);
596 while (Tok.isNot(tok::annot_pragma_openmp_end))
597 ConsumeAnyToken();
598 }
599 // Skip the last annot_pragma_openmp_end.
Richard Smithaf3b3252017-05-18 19:21:48 +0000600 ConsumeAnnotationToken();
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000601 return Res;
602 }
603 break;
Alexey Bataev587e1de2016-03-30 10:43:55 +0000604 case OMPD_declare_simd: {
605 // The syntax is:
606 // { #pragma omp declare simd }
607 // <function-declaration-or-definition>
608 //
Alexey Bataev587e1de2016-03-30 10:43:55 +0000609 ConsumeToken();
Alexey Bataev2af33e32016-04-07 12:45:37 +0000610 CachedTokens Toks;
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000611 while(Tok.isNot(tok::annot_pragma_openmp_end)) {
612 Toks.push_back(Tok);
613 ConsumeAnyToken();
614 }
615 Toks.push_back(Tok);
616 ConsumeAnyToken();
Alexey Bataev587e1de2016-03-30 10:43:55 +0000617
618 DeclGroupPtrTy Ptr;
Alexey Bataev20dfd772016-04-04 10:12:15 +0000619 if (Tok.is(tok::annot_pragma_openmp))
Alexey Bataev587e1de2016-03-30 10:43:55 +0000620 Ptr = ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs, TagType, Tag);
Alexey Bataev20dfd772016-04-04 10:12:15 +0000621 else if (Tok.isNot(tok::r_brace) && !isEofOrEom()) {
Alexey Bataev587e1de2016-03-30 10:43:55 +0000622 // Here we expect to see some function declaration.
623 if (AS == AS_none) {
624 assert(TagType == DeclSpec::TST_unspecified);
625 MaybeParseCXX11Attributes(Attrs);
Alexey Bataev587e1de2016-03-30 10:43:55 +0000626 ParsingDeclSpec PDS(*this);
627 Ptr = ParseExternalDeclaration(Attrs, &PDS);
628 } else {
629 Ptr =
630 ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag);
631 }
632 }
633 if (!Ptr) {
634 Diag(Loc, diag::err_omp_decl_in_declare_simd);
635 return DeclGroupPtrTy();
636 }
Alexey Bataev2af33e32016-04-07 12:45:37 +0000637 return ParseOMPDeclareSimdClauses(Ptr, Toks, Loc);
Alexey Bataev587e1de2016-03-30 10:43:55 +0000638 }
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000639 case OMPD_declare_target: {
640 SourceLocation DTLoc = ConsumeAnyToken();
641 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000642 // OpenMP 4.5 syntax with list of entities.
643 llvm::SmallSetVector<const NamedDecl*, 16> SameDirectiveDecls;
644 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
645 OMPDeclareTargetDeclAttr::MapTypeTy MT =
646 OMPDeclareTargetDeclAttr::MT_To;
647 if (Tok.is(tok::identifier)) {
648 IdentifierInfo *II = Tok.getIdentifierInfo();
649 StringRef ClauseName = II->getName();
650 // Parse 'to|link' clauses.
651 if (!OMPDeclareTargetDeclAttr::ConvertStrToMapTypeTy(ClauseName,
652 MT)) {
653 Diag(Tok, diag::err_omp_declare_target_unexpected_clause)
654 << ClauseName;
655 break;
656 }
657 ConsumeToken();
658 }
659 auto Callback = [this, MT, &SameDirectiveDecls](
660 CXXScopeSpec &SS, DeclarationNameInfo NameInfo) {
661 Actions.ActOnOpenMPDeclareTargetName(getCurScope(), SS, NameInfo, MT,
662 SameDirectiveDecls);
663 };
664 if (ParseOpenMPSimpleVarList(OMPD_declare_target, Callback, true))
665 break;
666
667 // Consume optional ','.
668 if (Tok.is(tok::comma))
669 ConsumeToken();
670 }
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000671 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000672 ConsumeAnyToken();
673 return DeclGroupPtrTy();
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000674 }
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000675
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000676 // Skip the last annot_pragma_openmp_end.
677 ConsumeAnyToken();
678
679 if (!Actions.ActOnStartOpenMPDeclareTargetDirective(DTLoc))
680 return DeclGroupPtrTy();
681
682 DKind = ParseOpenMPDirectiveKind(*this);
683 while (DKind != OMPD_end_declare_target && DKind != OMPD_declare_target &&
684 Tok.isNot(tok::eof) && Tok.isNot(tok::r_brace)) {
685 ParsedAttributesWithRange attrs(AttrFactory);
686 MaybeParseCXX11Attributes(attrs);
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000687 ParseExternalDeclaration(attrs);
688 if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
689 TentativeParsingAction TPA(*this);
Richard Smithaf3b3252017-05-18 19:21:48 +0000690 ConsumeAnnotationToken();
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000691 DKind = ParseOpenMPDirectiveKind(*this);
692 if (DKind != OMPD_end_declare_target)
693 TPA.Revert();
694 else
695 TPA.Commit();
696 }
697 }
698
699 if (DKind == OMPD_end_declare_target) {
700 ConsumeAnyToken();
701 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
702 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
703 << getOpenMPDirectiveName(OMPD_end_declare_target);
704 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
705 }
706 // Skip the last annot_pragma_openmp_end.
707 ConsumeAnyToken();
708 } else {
709 Diag(Tok, diag::err_expected_end_declare_target);
710 Diag(DTLoc, diag::note_matching) << "'#pragma omp declare target'";
711 }
712 Actions.ActOnFinishOpenMPDeclareTargetDirective();
713 return DeclGroupPtrTy();
714 }
Alexey Bataeva769e072013-03-22 06:34:35 +0000715 case OMPD_unknown:
716 Diag(Tok, diag::err_omp_unknown_directive);
717 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000718 case OMPD_parallel:
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000719 case OMPD_simd:
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000720 case OMPD_task:
Alexey Bataev68446b72014-07-18 07:47:19 +0000721 case OMPD_taskyield:
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000722 case OMPD_barrier:
Alexey Bataev2df347a2014-07-18 10:17:07 +0000723 case OMPD_taskwait:
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000724 case OMPD_taskgroup:
Alexey Bataev6125da92014-07-21 11:26:11 +0000725 case OMPD_flush:
Alexey Bataevf29276e2014-06-18 04:14:57 +0000726 case OMPD_for:
Alexander Musmanf82886e2014-09-18 05:12:34 +0000727 case OMPD_for_simd:
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000728 case OMPD_sections:
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000729 case OMPD_section:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000730 case OMPD_single:
Alexander Musman80c22892014-07-17 08:54:58 +0000731 case OMPD_master:
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000732 case OMPD_ordered:
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000733 case OMPD_critical:
Alexey Bataev4acb8592014-07-07 13:01:15 +0000734 case OMPD_parallel_for:
Alexander Musmane4e893b2014-09-23 09:33:00 +0000735 case OMPD_parallel_for_simd:
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000736 case OMPD_parallel_sections:
Alexey Bataev0162e452014-07-22 10:10:35 +0000737 case OMPD_atomic:
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000738 case OMPD_target:
Alexey Bataev13314bf2014-10-09 04:18:56 +0000739 case OMPD_teams:
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000740 case OMPD_cancellation_point:
Alexey Bataev80909872015-07-02 11:25:17 +0000741 case OMPD_cancel:
Samuel Antao5b0688e2015-07-22 16:02:46 +0000742 case OMPD_target_data:
Samuel Antaodf67fc42016-01-19 19:15:56 +0000743 case OMPD_target_enter_data:
Samuel Antao72590762016-01-19 20:04:50 +0000744 case OMPD_target_exit_data:
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000745 case OMPD_target_parallel:
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000746 case OMPD_target_parallel_for:
Alexey Bataev49f6e782015-12-01 04:18:41 +0000747 case OMPD_taskloop:
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000748 case OMPD_taskloop_simd:
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000749 case OMPD_distribute:
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000750 case OMPD_end_declare_target:
Samuel Antao686c70c2016-05-26 17:30:50 +0000751 case OMPD_target_update:
Carlo Bertolli9925f152016-06-27 14:55:37 +0000752 case OMPD_distribute_parallel_for:
Kelvin Li4a39add2016-07-05 05:00:15 +0000753 case OMPD_distribute_parallel_for_simd:
Kelvin Li787f3fc2016-07-06 04:45:38 +0000754 case OMPD_distribute_simd:
Kelvin Lia579b912016-07-14 02:54:56 +0000755 case OMPD_target_parallel_for_simd:
Kelvin Li986330c2016-07-20 22:57:10 +0000756 case OMPD_target_simd:
Kelvin Li02532872016-08-05 14:37:37 +0000757 case OMPD_teams_distribute:
Kelvin Li4e325f72016-10-25 12:50:55 +0000758 case OMPD_teams_distribute_simd:
Kelvin Li579e41c2016-11-30 23:51:03 +0000759 case OMPD_teams_distribute_parallel_for_simd:
Kelvin Li7ade93f2016-12-09 03:24:30 +0000760 case OMPD_teams_distribute_parallel_for:
Kelvin Libf594a52016-12-17 05:48:59 +0000761 case OMPD_target_teams:
Kelvin Li83c451e2016-12-25 04:52:54 +0000762 case OMPD_target_teams_distribute:
Kelvin Li80e8f562016-12-29 22:16:30 +0000763 case OMPD_target_teams_distribute_parallel_for:
Kelvin Li1851df52017-01-03 05:23:48 +0000764 case OMPD_target_teams_distribute_parallel_for_simd:
Kelvin Lida681182017-01-10 18:08:18 +0000765 case OMPD_target_teams_distribute_simd:
Alexey Bataeva769e072013-03-22 06:34:35 +0000766 Diag(Tok, diag::err_omp_unexpected_directive)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000767 << getOpenMPDirectiveName(DKind);
Alexey Bataeva769e072013-03-22 06:34:35 +0000768 break;
769 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000770 while (Tok.isNot(tok::annot_pragma_openmp_end))
771 ConsumeAnyToken();
772 ConsumeAnyToken();
David Blaikie0403cb12016-01-15 23:43:25 +0000773 return nullptr;
Alexey Bataeva769e072013-03-22 06:34:35 +0000774}
775
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000776/// \brief Parsing of declarative or executable OpenMP directives.
777///
778/// threadprivate-directive:
779/// annot_pragma_openmp 'threadprivate' simple-variable-list
780/// annot_pragma_openmp_end
781///
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000782/// declare-reduction-directive:
783/// annot_pragma_openmp 'declare' 'reduction' '(' <reduction_id> ':'
784/// <type> {',' <type>} ':' <expression> ')' ['initializer' '('
785/// ('omp_priv' '=' <expression>|<function_call>) ')']
786/// annot_pragma_openmp_end
787///
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000788/// executable-directive:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000789/// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' |
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000790/// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] |
791/// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' |
Alexander Musmanf82886e2014-09-18 05:12:34 +0000792/// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' |
Michael Wong65f367f2015-07-21 13:44:28 +0000793/// 'for simd' | 'parallel for simd' | 'target' | 'target data' |
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000794/// 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' |
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000795/// 'distribute' | 'target enter data' | 'target exit data' |
Samuel Antao686c70c2016-05-26 17:30:50 +0000796/// 'target parallel' | 'target parallel for' |
Kelvin Li4a39add2016-07-05 05:00:15 +0000797/// 'target update' | 'distribute parallel for' |
Kelvin Lia579b912016-07-14 02:54:56 +0000798/// 'distribute paralle for simd' | 'distribute simd' |
Kelvin Li02532872016-08-05 14:37:37 +0000799/// 'target parallel for simd' | 'target simd' |
Kelvin Li579e41c2016-11-30 23:51:03 +0000800/// 'teams distribute' | 'teams distribute simd' |
Kelvin Li7ade93f2016-12-09 03:24:30 +0000801/// 'teams distribute parallel for simd' |
Kelvin Li80e8f562016-12-29 22:16:30 +0000802/// 'teams distribute parallel for' | 'target teams' |
803/// 'target teams distribute' |
Kelvin Li1851df52017-01-03 05:23:48 +0000804/// 'target teams distribute parallel for' |
Kelvin Lida681182017-01-10 18:08:18 +0000805/// 'target teams distribute parallel for simd' |
806/// 'target teams distribute simd' {clause}
Samuel Antao72590762016-01-19 20:04:50 +0000807/// annot_pragma_openmp_end
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000808///
Alexey Bataevc4fad652016-01-13 11:18:54 +0000809StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
Jonathan Roelofsce1db6d2017-03-14 17:29:33 +0000810 AllowedConstructsKind Allowed) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000811 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
Alexey Bataevee6507d2013-11-18 08:17:37 +0000812 ParenBraceBracketBalancer BalancerRAIIObj(*this);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000813 SmallVector<OMPClause *, 5> Clauses;
Alexey Bataev4ca40ed2014-05-12 04:23:46 +0000814 SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1>
Alexey Bataeva55ed262014-05-28 06:15:33 +0000815 FirstClauses(OMPC_unknown + 1);
Alexander Musmana8e9d2e2014-06-03 10:16:47 +0000816 unsigned ScopeFlags =
Alexey Bataeva55ed262014-05-28 06:15:33 +0000817 Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope;
Richard Smithaf3b3252017-05-18 19:21:48 +0000818 SourceLocation Loc = ConsumeAnnotationToken(), EndLoc;
Alexey Bataev4acb8592014-07-07 13:01:15 +0000819 auto DKind = ParseOpenMPDirectiveKind(*this);
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000820 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
Alexey Bataev758e55e2013-09-06 18:03:48 +0000821 // Name of critical directive.
822 DeclarationNameInfo DirName;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000823 StmtResult Directive = StmtError();
Alexey Bataev68446b72014-07-18 07:47:19 +0000824 bool HasAssociatedStatement = true;
Alexey Bataev6125da92014-07-21 11:26:11 +0000825 bool FlushHasClause = false;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000826
827 switch (DKind) {
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000828 case OMPD_threadprivate: {
Alexey Bataevc4fad652016-01-13 11:18:54 +0000829 if (Allowed != ACK_Any) {
830 Diag(Tok, diag::err_omp_immediate_directive)
831 << getOpenMPDirectiveName(DKind) << 0;
832 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000833 ConsumeToken();
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000834 ThreadprivateListParserHelper Helper(this);
835 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Helper, false)) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000836 // The last seen token is annot_pragma_openmp_end - need to check for
837 // extra tokens.
838 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
839 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000840 << getOpenMPDirectiveName(OMPD_threadprivate);
Alp Tokerd751fa72013-12-18 19:10:49 +0000841 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000842 }
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000843 DeclGroupPtrTy Res = Actions.ActOnOpenMPThreadprivateDirective(
844 Loc, Helper.getIdentifiers());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000845 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
846 }
Alp Tokerd751fa72013-12-18 19:10:49 +0000847 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000848 break;
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000849 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000850 case OMPD_declare_reduction:
851 ConsumeToken();
852 if (auto Res = ParseOpenMPDeclareReductionDirective(/*AS=*/AS_none)) {
853 // The last seen token is annot_pragma_openmp_end - need to check for
854 // extra tokens.
855 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
856 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
857 << getOpenMPDirectiveName(OMPD_declare_reduction);
858 while (Tok.isNot(tok::annot_pragma_openmp_end))
859 ConsumeAnyToken();
860 }
861 ConsumeAnyToken();
862 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
863 } else
864 SkipUntil(tok::annot_pragma_openmp_end);
865 break;
Alexey Bataev6125da92014-07-21 11:26:11 +0000866 case OMPD_flush:
867 if (PP.LookAhead(0).is(tok::l_paren)) {
868 FlushHasClause = true;
869 // Push copy of the current token back to stream to properly parse
870 // pseudo-clause OMPFlushClause.
871 PP.EnterToken(Tok);
872 }
Galina Kistanova474f2ce2017-06-01 21:26:38 +0000873 LLVM_FALLTHROUGH;
Alexey Bataev68446b72014-07-18 07:47:19 +0000874 case OMPD_taskyield:
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000875 case OMPD_barrier:
Alexey Bataev2df347a2014-07-18 10:17:07 +0000876 case OMPD_taskwait:
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000877 case OMPD_cancellation_point:
Alexey Bataev80909872015-07-02 11:25:17 +0000878 case OMPD_cancel:
Samuel Antaodf67fc42016-01-19 19:15:56 +0000879 case OMPD_target_enter_data:
Samuel Antao72590762016-01-19 20:04:50 +0000880 case OMPD_target_exit_data:
Samuel Antao686c70c2016-05-26 17:30:50 +0000881 case OMPD_target_update:
Alexey Bataevc4fad652016-01-13 11:18:54 +0000882 if (Allowed == ACK_StatementsOpenMPNonStandalone) {
Alexey Bataev68446b72014-07-18 07:47:19 +0000883 Diag(Tok, diag::err_omp_immediate_directive)
Alexey Bataeveb482352015-12-18 05:05:56 +0000884 << getOpenMPDirectiveName(DKind) << 0;
Alexey Bataev68446b72014-07-18 07:47:19 +0000885 }
886 HasAssociatedStatement = false;
Alexey Bataev6125da92014-07-21 11:26:11 +0000887 // Fall through for further analysis.
Galina Kistanova474f2ce2017-06-01 21:26:38 +0000888 LLVM_FALLTHROUGH;
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000889 case OMPD_parallel:
Alexey Bataevf29276e2014-06-18 04:14:57 +0000890 case OMPD_simd:
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000891 case OMPD_for:
Alexander Musmanf82886e2014-09-18 05:12:34 +0000892 case OMPD_for_simd:
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000893 case OMPD_sections:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000894 case OMPD_single:
Alexey Bataev4acb8592014-07-07 13:01:15 +0000895 case OMPD_section:
Alexander Musman80c22892014-07-17 08:54:58 +0000896 case OMPD_master:
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000897 case OMPD_critical:
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000898 case OMPD_parallel_for:
Alexander Musmane4e893b2014-09-23 09:33:00 +0000899 case OMPD_parallel_for_simd:
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000900 case OMPD_parallel_sections:
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000901 case OMPD_task:
Alexey Bataev0162e452014-07-22 10:10:35 +0000902 case OMPD_ordered:
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000903 case OMPD_atomic:
Alexey Bataev13314bf2014-10-09 04:18:56 +0000904 case OMPD_target:
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000905 case OMPD_teams:
Michael Wong65f367f2015-07-21 13:44:28 +0000906 case OMPD_taskgroup:
Alexey Bataev49f6e782015-12-01 04:18:41 +0000907 case OMPD_target_data:
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000908 case OMPD_target_parallel:
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000909 case OMPD_target_parallel_for:
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000910 case OMPD_taskloop:
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000911 case OMPD_taskloop_simd:
Carlo Bertolli9925f152016-06-27 14:55:37 +0000912 case OMPD_distribute:
Kelvin Li4a39add2016-07-05 05:00:15 +0000913 case OMPD_distribute_parallel_for:
Kelvin Li787f3fc2016-07-06 04:45:38 +0000914 case OMPD_distribute_parallel_for_simd:
Kelvin Lia579b912016-07-14 02:54:56 +0000915 case OMPD_distribute_simd:
Kelvin Li986330c2016-07-20 22:57:10 +0000916 case OMPD_target_parallel_for_simd:
Kelvin Li02532872016-08-05 14:37:37 +0000917 case OMPD_target_simd:
Kelvin Li4e325f72016-10-25 12:50:55 +0000918 case OMPD_teams_distribute:
Kelvin Li579e41c2016-11-30 23:51:03 +0000919 case OMPD_teams_distribute_simd:
Kelvin Li7ade93f2016-12-09 03:24:30 +0000920 case OMPD_teams_distribute_parallel_for_simd:
Kelvin Libf594a52016-12-17 05:48:59 +0000921 case OMPD_teams_distribute_parallel_for:
Kelvin Li83c451e2016-12-25 04:52:54 +0000922 case OMPD_target_teams:
Kelvin Li80e8f562016-12-29 22:16:30 +0000923 case OMPD_target_teams_distribute:
Kelvin Li1851df52017-01-03 05:23:48 +0000924 case OMPD_target_teams_distribute_parallel_for:
Kelvin Lida681182017-01-10 18:08:18 +0000925 case OMPD_target_teams_distribute_parallel_for_simd:
926 case OMPD_target_teams_distribute_simd: {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000927 ConsumeToken();
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000928 // Parse directive name of the 'critical' directive if any.
929 if (DKind == OMPD_critical) {
930 BalancedDelimiterTracker T(*this, tok::l_paren,
931 tok::annot_pragma_openmp_end);
932 if (!T.consumeOpen()) {
933 if (Tok.isAnyIdentifier()) {
934 DirName =
935 DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation());
936 ConsumeAnyToken();
937 } else {
938 Diag(Tok, diag::err_omp_expected_identifier_for_critical);
939 }
940 T.consumeClose();
941 }
Alexey Bataev80909872015-07-02 11:25:17 +0000942 } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000943 CancelRegion = ParseOpenMPDirectiveKind(*this);
944 if (Tok.isNot(tok::annot_pragma_openmp_end))
945 ConsumeToken();
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000946 }
Alexey Bataev758e55e2013-09-06 18:03:48 +0000947
Alexey Bataevf29276e2014-06-18 04:14:57 +0000948 if (isOpenMPLoopDirective(DKind))
949 ScopeFlags |= Scope::OpenMPLoopDirectiveScope;
950 if (isOpenMPSimdDirective(DKind))
951 ScopeFlags |= Scope::OpenMPSimdDirectiveScope;
952 ParseScope OMPDirectiveScope(this, ScopeFlags);
Alexey Bataevbae9a792014-06-27 10:37:06 +0000953 Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000954
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000955 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
Alexey Bataev6125da92014-07-21 11:26:11 +0000956 OpenMPClauseKind CKind =
957 Tok.isAnnotation()
958 ? OMPC_unknown
959 : FlushHasClause ? OMPC_flush
960 : getOpenMPClauseKind(PP.getSpelling(Tok));
Alexey Bataevaac108a2015-06-23 04:51:00 +0000961 Actions.StartOpenMPClause(CKind);
Alexey Bataev6125da92014-07-21 11:26:11 +0000962 FlushHasClause = false;
Alexey Bataeva55ed262014-05-28 06:15:33 +0000963 OMPClause *Clause =
964 ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000965 FirstClauses[CKind].setInt(true);
966 if (Clause) {
967 FirstClauses[CKind].setPointer(Clause);
968 Clauses.push_back(Clause);
969 }
970
971 // Skip ',' if any.
972 if (Tok.is(tok::comma))
973 ConsumeToken();
Alexey Bataevaac108a2015-06-23 04:51:00 +0000974 Actions.EndOpenMPClause();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000975 }
976 // End location of the directive.
977 EndLoc = Tok.getLocation();
978 // Consume final annot_pragma_openmp_end.
Richard Smithaf3b3252017-05-18 19:21:48 +0000979 ConsumeAnnotationToken();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000980
Alexey Bataeveb482352015-12-18 05:05:56 +0000981 // OpenMP [2.13.8, ordered Construct, Syntax]
982 // If the depend clause is specified, the ordered construct is a stand-alone
983 // directive.
984 if (DKind == OMPD_ordered && FirstClauses[OMPC_depend].getInt()) {
Alexey Bataevc4fad652016-01-13 11:18:54 +0000985 if (Allowed == ACK_StatementsOpenMPNonStandalone) {
Alexey Bataeveb482352015-12-18 05:05:56 +0000986 Diag(Loc, diag::err_omp_immediate_directive)
987 << getOpenMPDirectiveName(DKind) << 1
988 << getOpenMPClauseName(OMPC_depend);
989 }
990 HasAssociatedStatement = false;
991 }
992
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000993 StmtResult AssociatedStmt;
Alexey Bataev68446b72014-07-18 07:47:19 +0000994 if (HasAssociatedStatement) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000995 // The body is a block scope like in Lambdas and Blocks.
996 Sema::CompoundScopeRAII CompoundScope(Actions);
Alexey Bataevbae9a792014-06-27 10:37:06 +0000997 Actions.ActOnOpenMPRegionStart(DKind, getCurScope());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000998 Actions.ActOnStartOfCompoundStmt();
999 // Parse statement
1000 AssociatedStmt = ParseStatement();
1001 Actions.ActOnFinishOfCompoundStmt();
Alexey Bataeva8d4a5432015-04-02 07:48:16 +00001002 AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001003 }
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001004 Directive = Actions.ActOnOpenMPExecutableDirective(
1005 DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc,
1006 EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001007
1008 // Exit scope.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001009 Actions.EndOpenMPDSABlock(Directive.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001010 OMPDirectiveScope.Exit();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001011 break;
Alexey Bataeva55ed262014-05-28 06:15:33 +00001012 }
Alexey Bataev587e1de2016-03-30 10:43:55 +00001013 case OMPD_declare_simd:
Dmitry Polukhin0b0da292016-04-06 11:38:59 +00001014 case OMPD_declare_target:
1015 case OMPD_end_declare_target:
Alexey Bataev587e1de2016-03-30 10:43:55 +00001016 Diag(Tok, diag::err_omp_unexpected_directive)
1017 << getOpenMPDirectiveName(DKind);
1018 SkipUntil(tok::annot_pragma_openmp_end);
1019 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001020 case OMPD_unknown:
1021 Diag(Tok, diag::err_omp_unknown_directive);
Alp Tokerd751fa72013-12-18 19:10:49 +00001022 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001023 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001024 }
1025 return Directive;
1026}
1027
Dmitry Polukhind69b5052016-05-09 14:59:13 +00001028// Parses simple list:
1029// simple-variable-list:
1030// '(' id-expression {, id-expression} ')'
1031//
1032bool Parser::ParseOpenMPSimpleVarList(
1033 OpenMPDirectiveKind Kind,
1034 const llvm::function_ref<void(CXXScopeSpec &, DeclarationNameInfo)> &
1035 Callback,
1036 bool AllowScopeSpecifier) {
Alexey Bataeva769e072013-03-22 06:34:35 +00001037 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +00001038 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001039 if (T.expectAndConsume(diag::err_expected_lparen_after,
1040 getOpenMPDirectiveName(Kind)))
1041 return true;
1042 bool IsCorrect = true;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001043 bool NoIdentIsFound = true;
Alexey Bataeva769e072013-03-22 06:34:35 +00001044
1045 // Read tokens while ')' or annot_pragma_openmp_end is not found.
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001046 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
Alexey Bataeva769e072013-03-22 06:34:35 +00001047 CXXScopeSpec SS;
1048 SourceLocation TemplateKWLoc;
1049 UnqualifiedId Name;
1050 // Read var name.
1051 Token PrevTok = Tok;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001052 NoIdentIsFound = false;
Alexey Bataeva769e072013-03-22 06:34:35 +00001053
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001054 if (AllowScopeSpecifier && getLangOpts().CPlusPlus &&
David Blaikieefdccaa2016-01-15 23:43:34 +00001055 ParseOptionalCXXScopeSpecifier(SS, nullptr, false)) {
Alexey Bataeva769e072013-03-22 06:34:35 +00001056 IsCorrect = false;
1057 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +00001058 StopBeforeMatch);
Richard Smith35845152017-02-07 01:37:30 +00001059 } else if (ParseUnqualifiedId(SS, false, false, false, false, nullptr,
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001060 TemplateKWLoc, Name)) {
Alexey Bataeva769e072013-03-22 06:34:35 +00001061 IsCorrect = false;
1062 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +00001063 StopBeforeMatch);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001064 } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) &&
1065 Tok.isNot(tok::annot_pragma_openmp_end)) {
1066 IsCorrect = false;
1067 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +00001068 StopBeforeMatch);
Alp Tokerec543272013-12-24 09:48:30 +00001069 Diag(PrevTok.getLocation(), diag::err_expected)
1070 << tok::identifier
1071 << SourceRange(PrevTok.getLocation(), PrevTokLocation);
Alexey Bataeva769e072013-03-22 06:34:35 +00001072 } else {
Dmitry Polukhind69b5052016-05-09 14:59:13 +00001073 Callback(SS, Actions.GetNameFromUnqualifiedId(Name));
Alexey Bataeva769e072013-03-22 06:34:35 +00001074 }
1075 // Consume ','.
1076 if (Tok.is(tok::comma)) {
1077 ConsumeToken();
1078 }
Alexey Bataeva769e072013-03-22 06:34:35 +00001079 }
1080
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001081 if (NoIdentIsFound) {
Alp Tokerec543272013-12-24 09:48:30 +00001082 Diag(Tok, diag::err_expected) << tok::identifier;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001083 IsCorrect = false;
1084 }
1085
1086 // Parse ')'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001087 IsCorrect = !T.consumeClose() && IsCorrect;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001088
Dmitry Polukhind69b5052016-05-09 14:59:13 +00001089 return !IsCorrect;
Alexey Bataeva769e072013-03-22 06:34:35 +00001090}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001091
1092/// \brief Parsing of OpenMP clauses.
1093///
1094/// clause:
Alexey Bataev3778b602014-07-17 07:32:53 +00001095/// if-clause | final-clause | num_threads-clause | safelen-clause |
1096/// default-clause | private-clause | firstprivate-clause | shared-clause
1097/// | linear-clause | aligned-clause | collapse-clause |
1098/// lastprivate-clause | reduction-clause | proc_bind-clause |
Alexey Bataev74ba3a52014-07-17 12:47:03 +00001099/// schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
Alexey Bataev67a4f222014-07-23 10:25:33 +00001100/// mergeable-clause | flush-clause | read-clause | write-clause |
Alexey Bataev66b15b52015-08-21 11:14:16 +00001101/// update-clause | capture-clause | seq_cst-clause | device-clause |
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001102/// simdlen-clause | threads-clause | simd-clause | num_teams-clause |
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001103/// thread_limit-clause | priority-clause | grainsize-clause |
Samuel Antaoec172c62016-05-26 17:49:04 +00001104/// nogroup-clause | num_tasks-clause | hint-clause | to-clause |
Carlo Bertolli70594e92016-07-13 17:16:49 +00001105/// from-clause | is_device_ptr-clause
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001106///
1107OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
1108 OpenMPClauseKind CKind, bool FirstClause) {
Craig Topper161e4db2014-05-21 06:02:52 +00001109 OMPClause *Clause = nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001110 bool ErrorFound = false;
1111 // Check if clause is allowed for the given directive.
1112 if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) {
Alexey Bataeva55ed262014-05-28 06:15:33 +00001113 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
1114 << getOpenMPDirectiveName(DKind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001115 ErrorFound = true;
1116 }
1117
1118 switch (CKind) {
Alexey Bataev3778b602014-07-17 07:32:53 +00001119 case OMPC_final:
Alexey Bataev568a8332014-03-06 06:15:19 +00001120 case OMPC_num_threads:
Alexey Bataev62c87d22014-03-21 04:51:18 +00001121 case OMPC_safelen:
Alexey Bataev66b15b52015-08-21 11:14:16 +00001122 case OMPC_simdlen:
Alexander Musman8bd31e62014-05-27 15:12:19 +00001123 case OMPC_collapse:
Alexey Bataev10e775f2015-07-30 11:36:16 +00001124 case OMPC_ordered:
Michael Wonge710d542015-08-07 16:16:36 +00001125 case OMPC_device:
Kelvin Li099bb8c2015-11-24 20:50:12 +00001126 case OMPC_num_teams:
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001127 case OMPC_thread_limit:
Alexey Bataeva0569352015-12-01 10:17:31 +00001128 case OMPC_priority:
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001129 case OMPC_grainsize:
Alexey Bataev382967a2015-12-08 12:06:20 +00001130 case OMPC_num_tasks:
Alexey Bataev28c75412015-12-15 08:19:24 +00001131 case OMPC_hint:
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001132 // OpenMP [2.5, Restrictions]
Alexey Bataev568a8332014-03-06 06:15:19 +00001133 // At most one num_threads clause can appear on the directive.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001134 // OpenMP [2.8.1, simd construct, Restrictions]
Alexander Musman8bd31e62014-05-27 15:12:19 +00001135 // Only one safelen clause can appear on a simd directive.
Alexey Bataev66b15b52015-08-21 11:14:16 +00001136 // Only one simdlen clause can appear on a simd directive.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001137 // Only one collapse clause can appear on a simd directive.
Michael Wonge710d542015-08-07 16:16:36 +00001138 // OpenMP [2.9.1, target data construct, Restrictions]
1139 // At most one device clause can appear on the directive.
Alexey Bataev3778b602014-07-17 07:32:53 +00001140 // OpenMP [2.11.1, task Construct, Restrictions]
1141 // At most one if clause can appear on the directive.
1142 // At most one final clause can appear on the directive.
Kelvin Li099bb8c2015-11-24 20:50:12 +00001143 // OpenMP [teams Construct, Restrictions]
1144 // At most one num_teams clause can appear on the directive.
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001145 // At most one thread_limit clause can appear on the directive.
Alexey Bataeva0569352015-12-01 10:17:31 +00001146 // OpenMP [2.9.1, task Construct, Restrictions]
1147 // At most one priority clause can appear on the directive.
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001148 // OpenMP [2.9.2, taskloop Construct, Restrictions]
1149 // At most one grainsize clause can appear on the directive.
Alexey Bataev382967a2015-12-08 12:06:20 +00001150 // OpenMP [2.9.2, taskloop Construct, Restrictions]
1151 // At most one num_tasks clause can appear on the directive.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001152 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001153 Diag(Tok, diag::err_omp_more_one_clause)
1154 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +00001155 ErrorFound = true;
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001156 }
1157
Alexey Bataev10e775f2015-07-30 11:36:16 +00001158 if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren))
1159 Clause = ParseOpenMPClause(CKind);
1160 else
1161 Clause = ParseOpenMPSingleExprClause(CKind);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001162 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001163 case OMPC_default:
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001164 case OMPC_proc_bind:
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001165 // OpenMP [2.14.3.1, Restrictions]
1166 // Only a single default clause may be specified on a parallel, task or
1167 // teams directive.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001168 // OpenMP [2.5, parallel Construct, Restrictions]
1169 // At most one proc_bind clause can appear on the directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001170 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001171 Diag(Tok, diag::err_omp_more_one_clause)
1172 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +00001173 ErrorFound = true;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001174 }
1175
1176 Clause = ParseOpenMPSimpleClause(CKind);
1177 break;
Alexey Bataev56dafe82014-06-20 07:16:17 +00001178 case OMPC_schedule:
Carlo Bertollib4adf552016-01-15 18:50:31 +00001179 case OMPC_dist_schedule:
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00001180 case OMPC_defaultmap:
Alexey Bataev56dafe82014-06-20 07:16:17 +00001181 // OpenMP [2.7.1, Restrictions, p. 3]
1182 // Only one schedule clause can appear on a loop directive.
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00001183 // OpenMP [2.10.4, Restrictions, p. 106]
1184 // At most one defaultmap clause can appear on the directive.
Alexey Bataev56dafe82014-06-20 07:16:17 +00001185 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001186 Diag(Tok, diag::err_omp_more_one_clause)
1187 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +00001188 ErrorFound = true;
Alexey Bataev56dafe82014-06-20 07:16:17 +00001189 }
Galina Kistanova474f2ce2017-06-01 21:26:38 +00001190 LLVM_FALLTHROUGH;
Alexey Bataev56dafe82014-06-20 07:16:17 +00001191
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001192 case OMPC_if:
Alexey Bataev56dafe82014-06-20 07:16:17 +00001193 Clause = ParseOpenMPSingleExprWithArgClause(CKind);
1194 break;
Alexey Bataev236070f2014-06-20 11:19:47 +00001195 case OMPC_nowait:
Alexey Bataev7aea99a2014-07-17 12:19:31 +00001196 case OMPC_untied:
Alexey Bataev74ba3a52014-07-17 12:47:03 +00001197 case OMPC_mergeable:
Alexey Bataevf98b00c2014-07-23 02:27:21 +00001198 case OMPC_read:
Alexey Bataevdea47612014-07-23 07:46:59 +00001199 case OMPC_write:
Alexey Bataev67a4f222014-07-23 10:25:33 +00001200 case OMPC_update:
Alexey Bataev459dec02014-07-24 06:46:57 +00001201 case OMPC_capture:
Alexey Bataev82bad8b2014-07-24 08:55:34 +00001202 case OMPC_seq_cst:
Alexey Bataev346265e2015-09-25 10:37:12 +00001203 case OMPC_threads:
Alexey Bataevd14d1e62015-09-28 06:39:35 +00001204 case OMPC_simd:
Alexey Bataevb825de12015-12-07 10:51:44 +00001205 case OMPC_nogroup:
Alexey Bataev142e1fc2014-06-20 09:44:06 +00001206 // OpenMP [2.7.1, Restrictions, p. 9]
1207 // Only one ordered clause can appear on a loop directive.
Alexey Bataev236070f2014-06-20 11:19:47 +00001208 // OpenMP [2.7.1, Restrictions, C/C++, p. 4]
1209 // Only one nowait clause can appear on a for directive.
Alexey Bataev142e1fc2014-06-20 09:44:06 +00001210 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001211 Diag(Tok, diag::err_omp_more_one_clause)
1212 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +00001213 ErrorFound = true;
Alexey Bataev142e1fc2014-06-20 09:44:06 +00001214 }
1215
1216 Clause = ParseOpenMPClause(CKind);
1217 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001218 case OMPC_private:
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001219 case OMPC_firstprivate:
Alexander Musman1bb328c2014-06-04 13:06:39 +00001220 case OMPC_lastprivate:
Alexey Bataev758e55e2013-09-06 18:03:48 +00001221 case OMPC_shared:
Alexey Bataevc5e02582014-06-16 07:08:35 +00001222 case OMPC_reduction:
Alexander Musman8dba6642014-04-22 13:09:42 +00001223 case OMPC_linear:
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001224 case OMPC_aligned:
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001225 case OMPC_copyin:
Alexey Bataevbae9a792014-06-27 10:37:06 +00001226 case OMPC_copyprivate:
Alexey Bataev6125da92014-07-21 11:26:11 +00001227 case OMPC_flush:
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001228 case OMPC_depend:
Kelvin Li0bff7af2015-11-23 05:32:03 +00001229 case OMPC_map:
Samuel Antao661c0902016-05-26 17:39:58 +00001230 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +00001231 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +00001232 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +00001233 case OMPC_is_device_ptr:
Alexey Bataeveb482352015-12-18 05:05:56 +00001234 Clause = ParseOpenMPVarListClause(DKind, CKind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001235 break;
1236 case OMPC_unknown:
1237 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +00001238 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +00001239 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001240 break;
1241 case OMPC_threadprivate:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001242 case OMPC_uniform:
Alexey Bataeva55ed262014-05-28 06:15:33 +00001243 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
1244 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +00001245 SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001246 break;
1247 }
Craig Topper161e4db2014-05-21 06:02:52 +00001248 return ErrorFound ? nullptr : Clause;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001249}
1250
Alexey Bataev2af33e32016-04-07 12:45:37 +00001251/// Parses simple expression in parens for single-expression clauses of OpenMP
1252/// constructs.
1253/// \param RLoc Returned location of right paren.
1254ExprResult Parser::ParseOpenMPParensExpr(StringRef ClauseName,
1255 SourceLocation &RLoc) {
1256 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
1257 if (T.expectAndConsume(diag::err_expected_lparen_after, ClauseName.data()))
1258 return ExprError();
1259
1260 SourceLocation ELoc = Tok.getLocation();
1261 ExprResult LHS(ParseCastExpression(
1262 /*isUnaryExpression=*/false, /*isAddressOfOperand=*/false, NotTypeCast));
1263 ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
1264 Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc);
1265
1266 // Parse ')'.
1267 T.consumeClose();
1268
1269 RLoc = T.getCloseLocation();
1270 return Val;
1271}
1272
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001273/// \brief Parsing of OpenMP clauses with single expressions like 'final',
Alexey Bataeva0569352015-12-01 10:17:31 +00001274/// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams',
Alexey Bataev28c75412015-12-15 08:19:24 +00001275/// 'thread_limit', 'simdlen', 'priority', 'grainsize', 'num_tasks' or 'hint'.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001276///
Alexey Bataev3778b602014-07-17 07:32:53 +00001277/// final-clause:
1278/// 'final' '(' expression ')'
1279///
Alexey Bataev62c87d22014-03-21 04:51:18 +00001280/// num_threads-clause:
1281/// 'num_threads' '(' expression ')'
1282///
1283/// safelen-clause:
1284/// 'safelen' '(' expression ')'
1285///
Alexey Bataev66b15b52015-08-21 11:14:16 +00001286/// simdlen-clause:
1287/// 'simdlen' '(' expression ')'
1288///
Alexander Musman8bd31e62014-05-27 15:12:19 +00001289/// collapse-clause:
1290/// 'collapse' '(' expression ')'
1291///
Alexey Bataeva0569352015-12-01 10:17:31 +00001292/// priority-clause:
1293/// 'priority' '(' expression ')'
1294///
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001295/// grainsize-clause:
1296/// 'grainsize' '(' expression ')'
1297///
Alexey Bataev382967a2015-12-08 12:06:20 +00001298/// num_tasks-clause:
1299/// 'num_tasks' '(' expression ')'
1300///
Alexey Bataev28c75412015-12-15 08:19:24 +00001301/// hint-clause:
1302/// 'hint' '(' expression ')'
1303///
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001304OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
1305 SourceLocation Loc = ConsumeToken();
Alexey Bataev2af33e32016-04-07 12:45:37 +00001306 SourceLocation LLoc = Tok.getLocation();
1307 SourceLocation RLoc;
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001308
Alexey Bataev2af33e32016-04-07 12:45:37 +00001309 ExprResult Val = ParseOpenMPParensExpr(getOpenMPClauseName(Kind), RLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001310
1311 if (Val.isInvalid())
Craig Topper161e4db2014-05-21 06:02:52 +00001312 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001313
Alexey Bataev2af33e32016-04-07 12:45:37 +00001314 return Actions.ActOnOpenMPSingleExprClause(Kind, Val.get(), Loc, LLoc, RLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001315}
1316
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001317/// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001318///
1319/// default-clause:
1320/// 'default' '(' 'none' | 'shared' ')
1321///
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001322/// proc_bind-clause:
1323/// 'proc_bind' '(' 'master' | 'close' | 'spread' ')
1324///
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001325OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
1326 SourceLocation Loc = Tok.getLocation();
1327 SourceLocation LOpen = ConsumeToken();
1328 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +00001329 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001330 if (T.expectAndConsume(diag::err_expected_lparen_after,
1331 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +00001332 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001333
Alexey Bataeva55ed262014-05-28 06:15:33 +00001334 unsigned Type = getOpenMPSimpleClauseType(
1335 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001336 SourceLocation TypeLoc = Tok.getLocation();
1337 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1338 Tok.isNot(tok::annot_pragma_openmp_end))
1339 ConsumeAnyToken();
1340
1341 // Parse ')'.
1342 T.consumeClose();
1343
1344 return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc,
1345 Tok.getLocation());
1346}
1347
Alexey Bataev142e1fc2014-06-20 09:44:06 +00001348/// \brief Parsing of OpenMP clauses like 'ordered'.
1349///
1350/// ordered-clause:
1351/// 'ordered'
1352///
Alexey Bataev236070f2014-06-20 11:19:47 +00001353/// nowait-clause:
1354/// 'nowait'
1355///
Alexey Bataev7aea99a2014-07-17 12:19:31 +00001356/// untied-clause:
1357/// 'untied'
1358///
Alexey Bataev74ba3a52014-07-17 12:47:03 +00001359/// mergeable-clause:
1360/// 'mergeable'
1361///
Alexey Bataevf98b00c2014-07-23 02:27:21 +00001362/// read-clause:
1363/// 'read'
1364///
Alexey Bataev346265e2015-09-25 10:37:12 +00001365/// threads-clause:
1366/// 'threads'
1367///
Alexey Bataevd14d1e62015-09-28 06:39:35 +00001368/// simd-clause:
1369/// 'simd'
1370///
Alexey Bataevb825de12015-12-07 10:51:44 +00001371/// nogroup-clause:
1372/// 'nogroup'
1373///
Alexey Bataev142e1fc2014-06-20 09:44:06 +00001374OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
1375 SourceLocation Loc = Tok.getLocation();
1376 ConsumeAnyToken();
1377
1378 return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
1379}
1380
1381
Alexey Bataev56dafe82014-06-20 07:16:17 +00001382/// \brief Parsing of OpenMP clauses with single expressions and some additional
1383/// argument like 'schedule' or 'dist_schedule'.
1384///
1385/// schedule-clause:
Alexey Bataev6402bca2015-12-28 07:25:51 +00001386/// 'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression ]
1387/// ')'
Alexey Bataev56dafe82014-06-20 07:16:17 +00001388///
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001389/// if-clause:
1390/// 'if' '(' [ directive-name-modifier ':' ] expression ')'
1391///
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00001392/// defaultmap:
1393/// 'defaultmap' '(' modifier ':' kind ')'
1394///
Alexey Bataev56dafe82014-06-20 07:16:17 +00001395OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) {
1396 SourceLocation Loc = ConsumeToken();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001397 SourceLocation DelimLoc;
Alexey Bataev56dafe82014-06-20 07:16:17 +00001398 // Parse '('.
1399 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
1400 if (T.expectAndConsume(diag::err_expected_lparen_after,
1401 getOpenMPClauseName(Kind)))
1402 return nullptr;
1403
1404 ExprResult Val;
Alexey Bataev6402bca2015-12-28 07:25:51 +00001405 SmallVector<unsigned, 4> Arg;
1406 SmallVector<SourceLocation, 4> KLoc;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001407 if (Kind == OMPC_schedule) {
Alexey Bataev6402bca2015-12-28 07:25:51 +00001408 enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements };
1409 Arg.resize(NumberOfElements);
1410 KLoc.resize(NumberOfElements);
1411 Arg[Modifier1] = OMPC_SCHEDULE_MODIFIER_unknown;
1412 Arg[Modifier2] = OMPC_SCHEDULE_MODIFIER_unknown;
1413 Arg[ScheduleKind] = OMPC_SCHEDULE_unknown;
1414 auto KindModifier = getOpenMPSimpleClauseType(
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001415 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
Alexey Bataev6402bca2015-12-28 07:25:51 +00001416 if (KindModifier > OMPC_SCHEDULE_unknown) {
1417 // Parse 'modifier'
1418 Arg[Modifier1] = KindModifier;
1419 KLoc[Modifier1] = Tok.getLocation();
1420 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1421 Tok.isNot(tok::annot_pragma_openmp_end))
1422 ConsumeAnyToken();
1423 if (Tok.is(tok::comma)) {
1424 // Parse ',' 'modifier'
1425 ConsumeAnyToken();
1426 KindModifier = getOpenMPSimpleClauseType(
1427 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
1428 Arg[Modifier2] = KindModifier > OMPC_SCHEDULE_unknown
1429 ? KindModifier
Aaron Ballmanad8a1042015-12-28 15:52:46 +00001430 : (unsigned)OMPC_SCHEDULE_unknown;
Alexey Bataev6402bca2015-12-28 07:25:51 +00001431 KLoc[Modifier2] = Tok.getLocation();
1432 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1433 Tok.isNot(tok::annot_pragma_openmp_end))
1434 ConsumeAnyToken();
1435 }
1436 // Parse ':'
1437 if (Tok.is(tok::colon))
1438 ConsumeAnyToken();
1439 else
1440 Diag(Tok, diag::warn_pragma_expected_colon) << "schedule modifier";
1441 KindModifier = getOpenMPSimpleClauseType(
1442 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
1443 }
1444 Arg[ScheduleKind] = KindModifier;
1445 KLoc[ScheduleKind] = Tok.getLocation();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001446 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1447 Tok.isNot(tok::annot_pragma_openmp_end))
1448 ConsumeAnyToken();
Alexey Bataev6402bca2015-12-28 07:25:51 +00001449 if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static ||
1450 Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic ||
1451 Arg[ScheduleKind] == OMPC_SCHEDULE_guided) &&
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001452 Tok.is(tok::comma))
1453 DelimLoc = ConsumeAnyToken();
Carlo Bertollib4adf552016-01-15 18:50:31 +00001454 } else if (Kind == OMPC_dist_schedule) {
1455 Arg.push_back(getOpenMPSimpleClauseType(
1456 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)));
1457 KLoc.push_back(Tok.getLocation());
1458 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1459 Tok.isNot(tok::annot_pragma_openmp_end))
1460 ConsumeAnyToken();
1461 if (Arg.back() == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma))
1462 DelimLoc = ConsumeAnyToken();
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00001463 } else if (Kind == OMPC_defaultmap) {
1464 // Get a defaultmap modifier
1465 Arg.push_back(getOpenMPSimpleClauseType(
1466 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)));
1467 KLoc.push_back(Tok.getLocation());
1468 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1469 Tok.isNot(tok::annot_pragma_openmp_end))
1470 ConsumeAnyToken();
1471 // Parse ':'
1472 if (Tok.is(tok::colon))
1473 ConsumeAnyToken();
1474 else if (Arg.back() != OMPC_DEFAULTMAP_MODIFIER_unknown)
1475 Diag(Tok, diag::warn_pragma_expected_colon) << "defaultmap modifier";
1476 // Get a defaultmap kind
1477 Arg.push_back(getOpenMPSimpleClauseType(
1478 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)));
1479 KLoc.push_back(Tok.getLocation());
1480 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1481 Tok.isNot(tok::annot_pragma_openmp_end))
1482 ConsumeAnyToken();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001483 } else {
1484 assert(Kind == OMPC_if);
Alexey Bataev6402bca2015-12-28 07:25:51 +00001485 KLoc.push_back(Tok.getLocation());
Alexey Bataev2a6de8c2016-12-20 12:10:05 +00001486 TentativeParsingAction TPA(*this);
Alexey Bataev6402bca2015-12-28 07:25:51 +00001487 Arg.push_back(ParseOpenMPDirectiveKind(*this));
1488 if (Arg.back() != OMPD_unknown) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001489 ConsumeToken();
Alexey Bataev2a6de8c2016-12-20 12:10:05 +00001490 if (Tok.is(tok::colon) && getLangOpts().OpenMP > 40) {
1491 TPA.Commit();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001492 DelimLoc = ConsumeToken();
Alexey Bataev2a6de8c2016-12-20 12:10:05 +00001493 } else {
1494 TPA.Revert();
1495 Arg.back() = OMPD_unknown;
1496 }
1497 } else
1498 TPA.Revert();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001499 }
Alexey Bataev56dafe82014-06-20 07:16:17 +00001500
Carlo Bertollib4adf552016-01-15 18:50:31 +00001501 bool NeedAnExpression = (Kind == OMPC_schedule && DelimLoc.isValid()) ||
1502 (Kind == OMPC_dist_schedule && DelimLoc.isValid()) ||
1503 Kind == OMPC_if;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001504 if (NeedAnExpression) {
1505 SourceLocation ELoc = Tok.getLocation();
Alexey Bataev56dafe82014-06-20 07:16:17 +00001506 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
1507 Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional);
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001508 Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001509 }
1510
1511 // Parse ')'.
1512 T.consumeClose();
1513
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001514 if (NeedAnExpression && Val.isInvalid())
1515 return nullptr;
1516
Alexey Bataev56dafe82014-06-20 07:16:17 +00001517 return Actions.ActOnOpenMPSingleExprWithArgClause(
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001518 Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc,
Alexey Bataev56dafe82014-06-20 07:16:17 +00001519 T.getCloseLocation());
1520}
1521
Alexey Bataevc5e02582014-06-16 07:08:35 +00001522static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec,
1523 UnqualifiedId &ReductionId) {
1524 SourceLocation TemplateKWLoc;
1525 if (ReductionIdScopeSpec.isEmpty()) {
1526 auto OOK = OO_None;
1527 switch (P.getCurToken().getKind()) {
1528 case tok::plus:
1529 OOK = OO_Plus;
1530 break;
1531 case tok::minus:
1532 OOK = OO_Minus;
1533 break;
1534 case tok::star:
1535 OOK = OO_Star;
1536 break;
1537 case tok::amp:
1538 OOK = OO_Amp;
1539 break;
1540 case tok::pipe:
1541 OOK = OO_Pipe;
1542 break;
1543 case tok::caret:
1544 OOK = OO_Caret;
1545 break;
1546 case tok::ampamp:
1547 OOK = OO_AmpAmp;
1548 break;
1549 case tok::pipepipe:
1550 OOK = OO_PipePipe;
1551 break;
1552 default:
1553 break;
1554 }
1555 if (OOK != OO_None) {
1556 SourceLocation OpLoc = P.ConsumeToken();
Alexey Bataev23b69422014-06-18 07:08:49 +00001557 SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()};
Alexey Bataevc5e02582014-06-16 07:08:35 +00001558 ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations);
1559 return false;
1560 }
1561 }
1562 return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false,
1563 /*AllowDestructorName*/ false,
Richard Smith35845152017-02-07 01:37:30 +00001564 /*AllowConstructorName*/ false,
1565 /*AllowDeductionGuide*/ false,
1566 nullptr, TemplateKWLoc, ReductionId);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001567}
1568
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001569/// Parses clauses with list.
1570bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
1571 OpenMPClauseKind Kind,
1572 SmallVectorImpl<Expr *> &Vars,
1573 OpenMPVarListDataTy &Data) {
1574 UnqualifiedId UnqualifiedReductionId;
1575 bool InvalidReductionId = false;
1576 bool MapTypeModifierSpecified = false;
1577
1578 // Parse '('.
1579 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
1580 if (T.expectAndConsume(diag::err_expected_lparen_after,
1581 getOpenMPClauseName(Kind)))
1582 return true;
1583
1584 bool NeedRParenForLinear = false;
1585 BalancedDelimiterTracker LinearT(*this, tok::l_paren,
1586 tok::annot_pragma_openmp_end);
1587 // Handle reduction-identifier for reduction clause.
1588 if (Kind == OMPC_reduction) {
1589 ColonProtectionRAIIObject ColonRAII(*this);
1590 if (getLangOpts().CPlusPlus)
1591 ParseOptionalCXXScopeSpecifier(Data.ReductionIdScopeSpec,
1592 /*ObjectType=*/nullptr,
1593 /*EnteringContext=*/false);
1594 InvalidReductionId = ParseReductionId(*this, Data.ReductionIdScopeSpec,
1595 UnqualifiedReductionId);
1596 if (InvalidReductionId) {
1597 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
1598 StopBeforeMatch);
1599 }
1600 if (Tok.is(tok::colon))
1601 Data.ColonLoc = ConsumeToken();
1602 else
1603 Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier";
1604 if (!InvalidReductionId)
1605 Data.ReductionId =
1606 Actions.GetNameFromUnqualifiedId(UnqualifiedReductionId);
1607 } else if (Kind == OMPC_depend) {
1608 // Handle dependency type for depend clause.
1609 ColonProtectionRAIIObject ColonRAII(*this);
1610 Data.DepKind =
1611 static_cast<OpenMPDependClauseKind>(getOpenMPSimpleClauseType(
1612 Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
1613 Data.DepLinMapLoc = Tok.getLocation();
1614
1615 if (Data.DepKind == OMPC_DEPEND_unknown) {
1616 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
1617 StopBeforeMatch);
1618 } else {
1619 ConsumeToken();
1620 // Special processing for depend(source) clause.
1621 if (DKind == OMPD_ordered && Data.DepKind == OMPC_DEPEND_source) {
1622 // Parse ')'.
1623 T.consumeClose();
1624 return false;
1625 }
1626 }
1627 if (Tok.is(tok::colon))
1628 Data.ColonLoc = ConsumeToken();
1629 else {
1630 Diag(Tok, DKind == OMPD_ordered ? diag::warn_pragma_expected_colon_r_paren
1631 : diag::warn_pragma_expected_colon)
1632 << "dependency type";
1633 }
1634 } else if (Kind == OMPC_linear) {
1635 // Try to parse modifier if any.
1636 if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) {
1637 Data.LinKind = static_cast<OpenMPLinearClauseKind>(
1638 getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)));
1639 Data.DepLinMapLoc = ConsumeToken();
1640 LinearT.consumeOpen();
1641 NeedRParenForLinear = true;
1642 }
1643 } else if (Kind == OMPC_map) {
1644 // Handle map type for map clause.
1645 ColonProtectionRAIIObject ColonRAII(*this);
1646
1647 /// The map clause modifier token can be either a identifier or the C++
1648 /// delete keyword.
1649 auto &&IsMapClauseModifierToken = [](const Token &Tok) -> bool {
1650 return Tok.isOneOf(tok::identifier, tok::kw_delete);
1651 };
1652
1653 // The first identifier may be a list item, a map-type or a
1654 // map-type-modifier. The map modifier can also be delete which has the same
1655 // spelling of the C++ delete keyword.
1656 Data.MapType =
1657 IsMapClauseModifierToken(Tok)
1658 ? static_cast<OpenMPMapClauseKind>(
1659 getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)))
1660 : OMPC_MAP_unknown;
1661 Data.DepLinMapLoc = Tok.getLocation();
1662 bool ColonExpected = false;
1663
1664 if (IsMapClauseModifierToken(Tok)) {
1665 if (PP.LookAhead(0).is(tok::colon)) {
1666 if (Data.MapType == OMPC_MAP_unknown)
1667 Diag(Tok, diag::err_omp_unknown_map_type);
1668 else if (Data.MapType == OMPC_MAP_always)
1669 Diag(Tok, diag::err_omp_map_type_missing);
1670 ConsumeToken();
1671 } else if (PP.LookAhead(0).is(tok::comma)) {
1672 if (IsMapClauseModifierToken(PP.LookAhead(1)) &&
1673 PP.LookAhead(2).is(tok::colon)) {
1674 Data.MapTypeModifier = Data.MapType;
1675 if (Data.MapTypeModifier != OMPC_MAP_always) {
1676 Diag(Tok, diag::err_omp_unknown_map_type_modifier);
1677 Data.MapTypeModifier = OMPC_MAP_unknown;
1678 } else
1679 MapTypeModifierSpecified = true;
1680
1681 ConsumeToken();
1682 ConsumeToken();
1683
1684 Data.MapType =
1685 IsMapClauseModifierToken(Tok)
1686 ? static_cast<OpenMPMapClauseKind>(
1687 getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)))
1688 : OMPC_MAP_unknown;
1689 if (Data.MapType == OMPC_MAP_unknown ||
1690 Data.MapType == OMPC_MAP_always)
1691 Diag(Tok, diag::err_omp_unknown_map_type);
1692 ConsumeToken();
1693 } else {
1694 Data.MapType = OMPC_MAP_tofrom;
1695 Data.IsMapTypeImplicit = true;
1696 }
Carlo Bertollid8844b92017-05-03 15:28:48 +00001697 } else if (IsMapClauseModifierToken(PP.LookAhead(0))) {
1698 if (PP.LookAhead(1).is(tok::colon)) {
1699 Data.MapTypeModifier = Data.MapType;
1700 if (Data.MapTypeModifier != OMPC_MAP_always) {
1701 Diag(Tok, diag::err_omp_unknown_map_type_modifier);
1702 Data.MapTypeModifier = OMPC_MAP_unknown;
1703 } else
1704 MapTypeModifierSpecified = true;
1705
1706 ConsumeToken();
1707
1708 Data.MapType =
1709 IsMapClauseModifierToken(Tok)
1710 ? static_cast<OpenMPMapClauseKind>(
1711 getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)))
1712 : OMPC_MAP_unknown;
1713 if (Data.MapType == OMPC_MAP_unknown ||
1714 Data.MapType == OMPC_MAP_always)
1715 Diag(Tok, diag::err_omp_unknown_map_type);
1716 ConsumeToken();
1717 } else {
1718 Data.MapType = OMPC_MAP_tofrom;
1719 Data.IsMapTypeImplicit = true;
1720 }
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001721 } else {
1722 Data.MapType = OMPC_MAP_tofrom;
1723 Data.IsMapTypeImplicit = true;
1724 }
1725 } else {
1726 Data.MapType = OMPC_MAP_tofrom;
1727 Data.IsMapTypeImplicit = true;
1728 }
1729
1730 if (Tok.is(tok::colon))
1731 Data.ColonLoc = ConsumeToken();
1732 else if (ColonExpected)
1733 Diag(Tok, diag::warn_pragma_expected_colon) << "map type";
1734 }
1735
1736 bool IsComma =
1737 (Kind != OMPC_reduction && Kind != OMPC_depend && Kind != OMPC_map) ||
1738 (Kind == OMPC_reduction && !InvalidReductionId) ||
1739 (Kind == OMPC_map && Data.MapType != OMPC_MAP_unknown &&
1740 (!MapTypeModifierSpecified ||
1741 Data.MapTypeModifier == OMPC_MAP_always)) ||
1742 (Kind == OMPC_depend && Data.DepKind != OMPC_DEPEND_unknown);
1743 const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
1744 while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
1745 Tok.isNot(tok::annot_pragma_openmp_end))) {
1746 ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail);
1747 // Parse variable
1748 ExprResult VarExpr =
1749 Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
1750 if (VarExpr.isUsable())
1751 Vars.push_back(VarExpr.get());
1752 else {
1753 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
1754 StopBeforeMatch);
1755 }
1756 // Skip ',' if any
1757 IsComma = Tok.is(tok::comma);
1758 if (IsComma)
1759 ConsumeToken();
1760 else if (Tok.isNot(tok::r_paren) &&
1761 Tok.isNot(tok::annot_pragma_openmp_end) &&
1762 (!MayHaveTail || Tok.isNot(tok::colon)))
1763 Diag(Tok, diag::err_omp_expected_punc)
1764 << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush)
1765 : getOpenMPClauseName(Kind))
1766 << (Kind == OMPC_flush);
1767 }
1768
1769 // Parse ')' for linear clause with modifier.
1770 if (NeedRParenForLinear)
1771 LinearT.consumeClose();
1772
1773 // Parse ':' linear-step (or ':' alignment).
1774 const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon);
1775 if (MustHaveTail) {
1776 Data.ColonLoc = Tok.getLocation();
1777 SourceLocation ELoc = ConsumeToken();
1778 ExprResult Tail = ParseAssignmentExpression();
1779 Tail = Actions.ActOnFinishFullExpr(Tail.get(), ELoc);
1780 if (Tail.isUsable())
1781 Data.TailExpr = Tail.get();
1782 else
1783 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
1784 StopBeforeMatch);
1785 }
1786
1787 // Parse ')'.
1788 T.consumeClose();
1789 if ((Kind == OMPC_depend && Data.DepKind != OMPC_DEPEND_unknown &&
1790 Vars.empty()) ||
1791 (Kind != OMPC_depend && Kind != OMPC_map && Vars.empty()) ||
1792 (MustHaveTail && !Data.TailExpr) || InvalidReductionId)
1793 return true;
1794 return false;
1795}
1796
Alexander Musman1bb328c2014-06-04 13:06:39 +00001797/// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
Alexey Bataev6125da92014-07-21 11:26:11 +00001798/// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001799///
1800/// private-clause:
1801/// 'private' '(' list ')'
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001802/// firstprivate-clause:
1803/// 'firstprivate' '(' list ')'
Alexander Musman1bb328c2014-06-04 13:06:39 +00001804/// lastprivate-clause:
1805/// 'lastprivate' '(' list ')'
Alexey Bataev758e55e2013-09-06 18:03:48 +00001806/// shared-clause:
1807/// 'shared' '(' list ')'
Alexander Musman8dba6642014-04-22 13:09:42 +00001808/// linear-clause:
Alexey Bataev182227b2015-08-20 10:54:39 +00001809/// 'linear' '(' linear-list [ ':' linear-step ] ')'
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001810/// aligned-clause:
1811/// 'aligned' '(' list [ ':' alignment ] ')'
Alexey Bataevc5e02582014-06-16 07:08:35 +00001812/// reduction-clause:
1813/// 'reduction' '(' reduction-identifier ':' list ')'
Alexey Bataev6125da92014-07-21 11:26:11 +00001814/// copyprivate-clause:
1815/// 'copyprivate' '(' list ')'
1816/// flush-clause:
1817/// 'flush' '(' list ')'
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001818/// depend-clause:
Alexey Bataeveb482352015-12-18 05:05:56 +00001819/// 'depend' '(' in | out | inout : list | source ')'
Kelvin Li0bff7af2015-11-23 05:32:03 +00001820/// map-clause:
1821/// 'map' '(' [ [ always , ]
1822/// to | from | tofrom | alloc | release | delete ':' ] list ')';
Samuel Antao661c0902016-05-26 17:39:58 +00001823/// to-clause:
1824/// 'to' '(' list ')'
Samuel Antaoec172c62016-05-26 17:49:04 +00001825/// from-clause:
1826/// 'from' '(' list ')'
Carlo Bertolli2404b172016-07-13 15:37:16 +00001827/// use_device_ptr-clause:
1828/// 'use_device_ptr' '(' list ')'
Carlo Bertolli70594e92016-07-13 17:16:49 +00001829/// is_device_ptr-clause:
1830/// 'is_device_ptr' '(' list ')'
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001831///
Alexey Bataev182227b2015-08-20 10:54:39 +00001832/// For 'linear' clause linear-list may have the following forms:
1833/// list
1834/// modifier(list)
1835/// where modifier is 'val' (C) or 'ref', 'val' or 'uval'(C++).
Alexey Bataeveb482352015-12-18 05:05:56 +00001836OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
1837 OpenMPClauseKind Kind) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001838 SourceLocation Loc = Tok.getLocation();
1839 SourceLocation LOpen = ConsumeToken();
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001840 SmallVector<Expr *, 4> Vars;
1841 OpenMPVarListDataTy Data;
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001842
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001843 if (ParseOpenMPVarList(DKind, Kind, Vars, Data))
Craig Topper161e4db2014-05-21 06:02:52 +00001844 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001845
Alexey Bataevc5e02582014-06-16 07:08:35 +00001846 return Actions.ActOnOpenMPVarListClause(
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001847 Kind, Vars, Data.TailExpr, Loc, LOpen, Data.ColonLoc, Tok.getLocation(),
1848 Data.ReductionIdScopeSpec, Data.ReductionId, Data.DepKind, Data.LinKind,
1849 Data.MapTypeModifier, Data.MapType, Data.IsMapTypeImplicit,
1850 Data.DepLinMapLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001851}
1852