]> granicus.if.org Git - clang/blob - lib/Parse/ParseOpenMP.cpp
[OpenMP] Parsing + sema for defaultmap clause.
[clang] / lib / Parse / ParseOpenMP.cpp
1 //===--- 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
14 #include "RAIIObjectsForParser.h"
15 #include "clang/AST/ASTConsumer.h"
16 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/StmtOpenMP.h"
18 #include "clang/Parse/ParseDiagnostic.h"
19 #include "clang/Parse/Parser.h"
20 #include "clang/Sema/Scope.h"
21 #include "llvm/ADT/PointerIntPair.h"
22
23 using namespace clang;
24
25 //===----------------------------------------------------------------------===//
26 // OpenMP declarative directives.
27 //===----------------------------------------------------------------------===//
28
29 static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) {
30   // Array of foldings: F[i][0] F[i][1] ===> F[i][2].
31   // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd
32   // TODO: add other combined directives in topological order.
33   const OpenMPDirectiveKind F[][3] = {
34       {OMPD_unknown /*cancellation*/, OMPD_unknown /*point*/,
35        OMPD_cancellation_point},
36       {OMPD_target, OMPD_unknown /*data*/, OMPD_target_data},
37       {OMPD_target, OMPD_unknown /*enter/exit*/,
38        OMPD_unknown /*target enter/exit*/},
39       {OMPD_unknown /*target enter*/, OMPD_unknown /*data*/,
40        OMPD_target_enter_data},
41       {OMPD_unknown /*target exit*/, OMPD_unknown /*data*/,
42        OMPD_target_exit_data},
43       {OMPD_for, OMPD_simd, OMPD_for_simd},
44       {OMPD_parallel, OMPD_for, OMPD_parallel_for},
45       {OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd},
46       {OMPD_parallel, OMPD_sections, OMPD_parallel_sections},
47       {OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd}};
48   auto Tok = P.getCurToken();
49   auto DKind =
50       Tok.isAnnotation()
51           ? OMPD_unknown
52           : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
53
54   bool TokenMatched = false;
55   for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) {
56     if (!Tok.isAnnotation() && DKind == OMPD_unknown) {
57       TokenMatched =
58           ((i == 0) &&
59            !P.getPreprocessor().getSpelling(Tok).compare("cancellation")) ||
60           ((i == 3) &&
61            !P.getPreprocessor().getSpelling(Tok).compare("enter")) ||
62           ((i == 4) && !P.getPreprocessor().getSpelling(Tok).compare("exit"));
63     } else {
64       TokenMatched = DKind == F[i][0] && DKind != OMPD_unknown;
65     }
66
67     if (TokenMatched) {
68       Tok = P.getPreprocessor().LookAhead(0);
69       auto TokenIsAnnotation = Tok.isAnnotation();
70       auto SDKind =
71           TokenIsAnnotation
72               ? OMPD_unknown
73               : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
74
75       if (!TokenIsAnnotation && SDKind == OMPD_unknown) {
76         TokenMatched =
77             ((i == 0) &&
78              !P.getPreprocessor().getSpelling(Tok).compare("point")) ||
79             ((i == 1 || i == 3 || i == 4) &&
80              !P.getPreprocessor().getSpelling(Tok).compare("data")) ||
81             ((i == 2) &&
82              (!P.getPreprocessor().getSpelling(Tok).compare("enter") ||
83               !P.getPreprocessor().getSpelling(Tok).compare("exit")));
84       } else {
85         TokenMatched = SDKind == F[i][1] && SDKind != OMPD_unknown;
86       }
87
88       if (TokenMatched) {
89         P.ConsumeToken();
90         DKind = F[i][2];
91       }
92     }
93   }
94   return DKind;
95 }
96
97 /// \brief Parsing of declarative OpenMP directives.
98 ///
99 ///       threadprivate-directive:
100 ///         annot_pragma_openmp 'threadprivate' simple-variable-list
101 ///
102 Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() {
103   assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
104   ParenBraceBracketBalancer BalancerRAIIObj(*this);
105
106   SourceLocation Loc = ConsumeToken();
107   SmallVector<Expr *, 5> Identifiers;
108   auto DKind = ParseOpenMPDirectiveKind(*this);
109
110   switch (DKind) {
111   case OMPD_threadprivate:
112     ConsumeToken();
113     if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, true)) {
114       // The last seen token is annot_pragma_openmp_end - need to check for
115       // extra tokens.
116       if (Tok.isNot(tok::annot_pragma_openmp_end)) {
117         Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
118             << getOpenMPDirectiveName(OMPD_threadprivate);
119         SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
120       }
121       // Skip the last annot_pragma_openmp_end.
122       ConsumeToken();
123       return Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers);
124     }
125     break;
126   case OMPD_unknown:
127     Diag(Tok, diag::err_omp_unknown_directive);
128     break;
129   case OMPD_parallel:
130   case OMPD_simd:
131   case OMPD_task:
132   case OMPD_taskyield:
133   case OMPD_barrier:
134   case OMPD_taskwait:
135   case OMPD_taskgroup:
136   case OMPD_flush:
137   case OMPD_for:
138   case OMPD_for_simd:
139   case OMPD_sections:
140   case OMPD_section:
141   case OMPD_single:
142   case OMPD_master:
143   case OMPD_ordered:
144   case OMPD_critical:
145   case OMPD_parallel_for:
146   case OMPD_parallel_for_simd:
147   case OMPD_parallel_sections:
148   case OMPD_atomic:
149   case OMPD_target:
150   case OMPD_teams:
151   case OMPD_cancellation_point:
152   case OMPD_cancel:
153   case OMPD_target_data:
154   case OMPD_target_enter_data:
155   case OMPD_target_exit_data:
156   case OMPD_taskloop:
157   case OMPD_taskloop_simd:
158   case OMPD_distribute:
159     Diag(Tok, diag::err_omp_unexpected_directive)
160         << getOpenMPDirectiveName(DKind);
161     break;
162   }
163   SkipUntil(tok::annot_pragma_openmp_end);
164   return nullptr;
165 }
166
167 /// \brief Parsing of declarative or executable OpenMP directives.
168 ///
169 ///       threadprivate-directive:
170 ///         annot_pragma_openmp 'threadprivate' simple-variable-list
171 ///         annot_pragma_openmp_end
172 ///
173 ///       executable-directive:
174 ///         annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' |
175 ///         'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] |
176 ///         'parallel for' | 'parallel sections' | 'task' | 'taskyield' |
177 ///         'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' |
178 ///         'for simd' | 'parallel for simd' | 'target' | 'target data' |
179 ///         'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' {clause} |
180 ///         'distribute' | 'target enter data' | 'target exit data'
181 ///         annot_pragma_openmp_end
182 ///
183 StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
184     AllowedContsructsKind Allowed) {
185   assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
186   ParenBraceBracketBalancer BalancerRAIIObj(*this);
187   SmallVector<Expr *, 5> Identifiers;
188   SmallVector<OMPClause *, 5> Clauses;
189   SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1>
190   FirstClauses(OMPC_unknown + 1);
191   unsigned ScopeFlags =
192       Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope;
193   SourceLocation Loc = ConsumeToken(), EndLoc;
194   auto DKind = ParseOpenMPDirectiveKind(*this);
195   OpenMPDirectiveKind CancelRegion = OMPD_unknown;
196   // Name of critical directive.
197   DeclarationNameInfo DirName;
198   StmtResult Directive = StmtError();
199   bool HasAssociatedStatement = true;
200   bool FlushHasClause = false;
201
202   switch (DKind) {
203   case OMPD_threadprivate:
204     if (Allowed != ACK_Any) {
205       Diag(Tok, diag::err_omp_immediate_directive)
206           << getOpenMPDirectiveName(DKind) << 0;
207     }
208     ConsumeToken();
209     if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, false)) {
210       // The last seen token is annot_pragma_openmp_end - need to check for
211       // extra tokens.
212       if (Tok.isNot(tok::annot_pragma_openmp_end)) {
213         Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
214             << getOpenMPDirectiveName(OMPD_threadprivate);
215         SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
216       }
217       DeclGroupPtrTy Res =
218           Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers);
219       Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
220     }
221     SkipUntil(tok::annot_pragma_openmp_end);
222     break;
223   case OMPD_flush:
224     if (PP.LookAhead(0).is(tok::l_paren)) {
225       FlushHasClause = true;
226       // Push copy of the current token back to stream to properly parse
227       // pseudo-clause OMPFlushClause.
228       PP.EnterToken(Tok);
229     }
230   case OMPD_taskyield:
231   case OMPD_barrier:
232   case OMPD_taskwait:
233   case OMPD_cancellation_point:
234   case OMPD_cancel:
235   case OMPD_target_enter_data:
236   case OMPD_target_exit_data:
237     if (Allowed == ACK_StatementsOpenMPNonStandalone) {
238       Diag(Tok, diag::err_omp_immediate_directive)
239           << getOpenMPDirectiveName(DKind) << 0;
240     }
241     HasAssociatedStatement = false;
242     // Fall through for further analysis.
243   case OMPD_parallel:
244   case OMPD_simd:
245   case OMPD_for:
246   case OMPD_for_simd:
247   case OMPD_sections:
248   case OMPD_single:
249   case OMPD_section:
250   case OMPD_master:
251   case OMPD_critical:
252   case OMPD_parallel_for:
253   case OMPD_parallel_for_simd:
254   case OMPD_parallel_sections:
255   case OMPD_task:
256   case OMPD_ordered:
257   case OMPD_atomic:
258   case OMPD_target:
259   case OMPD_teams:
260   case OMPD_taskgroup:
261   case OMPD_target_data:
262   case OMPD_taskloop:
263   case OMPD_taskloop_simd:
264   case OMPD_distribute: {
265     ConsumeToken();
266     // Parse directive name of the 'critical' directive if any.
267     if (DKind == OMPD_critical) {
268       BalancedDelimiterTracker T(*this, tok::l_paren,
269                                  tok::annot_pragma_openmp_end);
270       if (!T.consumeOpen()) {
271         if (Tok.isAnyIdentifier()) {
272           DirName =
273               DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation());
274           ConsumeAnyToken();
275         } else {
276           Diag(Tok, diag::err_omp_expected_identifier_for_critical);
277         }
278         T.consumeClose();
279       }
280     } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) {
281       CancelRegion = ParseOpenMPDirectiveKind(*this);
282       if (Tok.isNot(tok::annot_pragma_openmp_end))
283         ConsumeToken();
284     }
285
286     if (isOpenMPLoopDirective(DKind))
287       ScopeFlags |= Scope::OpenMPLoopDirectiveScope;
288     if (isOpenMPSimdDirective(DKind))
289       ScopeFlags |= Scope::OpenMPSimdDirectiveScope;
290     ParseScope OMPDirectiveScope(this, ScopeFlags);
291     Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc);
292
293     while (Tok.isNot(tok::annot_pragma_openmp_end)) {
294       OpenMPClauseKind CKind =
295           Tok.isAnnotation()
296               ? OMPC_unknown
297               : FlushHasClause ? OMPC_flush
298                                : getOpenMPClauseKind(PP.getSpelling(Tok));
299       Actions.StartOpenMPClause(CKind);
300       FlushHasClause = false;
301       OMPClause *Clause =
302           ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt());
303       FirstClauses[CKind].setInt(true);
304       if (Clause) {
305         FirstClauses[CKind].setPointer(Clause);
306         Clauses.push_back(Clause);
307       }
308
309       // Skip ',' if any.
310       if (Tok.is(tok::comma))
311         ConsumeToken();
312       Actions.EndOpenMPClause();
313     }
314     // End location of the directive.
315     EndLoc = Tok.getLocation();
316     // Consume final annot_pragma_openmp_end.
317     ConsumeToken();
318
319     // OpenMP [2.13.8, ordered Construct, Syntax]
320     // If the depend clause is specified, the ordered construct is a stand-alone
321     // directive.
322     if (DKind == OMPD_ordered && FirstClauses[OMPC_depend].getInt()) {
323       if (Allowed == ACK_StatementsOpenMPNonStandalone) {
324         Diag(Loc, diag::err_omp_immediate_directive)
325             << getOpenMPDirectiveName(DKind) << 1
326             << getOpenMPClauseName(OMPC_depend);
327       }
328       HasAssociatedStatement = false;
329     }
330
331     StmtResult AssociatedStmt;
332     if (HasAssociatedStatement) {
333       // The body is a block scope like in Lambdas and Blocks.
334       Sema::CompoundScopeRAII CompoundScope(Actions);
335       Actions.ActOnOpenMPRegionStart(DKind, getCurScope());
336       Actions.ActOnStartOfCompoundStmt();
337       // Parse statement
338       AssociatedStmt = ParseStatement();
339       Actions.ActOnFinishOfCompoundStmt();
340       AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
341     }
342     Directive = Actions.ActOnOpenMPExecutableDirective(
343         DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc,
344         EndLoc);
345
346     // Exit scope.
347     Actions.EndOpenMPDSABlock(Directive.get());
348     OMPDirectiveScope.Exit();
349     break;
350   }
351   case OMPD_unknown:
352     Diag(Tok, diag::err_omp_unknown_directive);
353     SkipUntil(tok::annot_pragma_openmp_end);
354     break;
355   }
356   return Directive;
357 }
358
359 /// \brief Parses list of simple variables for '#pragma omp threadprivate'
360 /// directive.
361 ///
362 ///   simple-variable-list:
363 ///         '(' id-expression {, id-expression} ')'
364 ///
365 bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind,
366                                       SmallVectorImpl<Expr *> &VarList,
367                                       bool AllowScopeSpecifier) {
368   VarList.clear();
369   // Parse '('.
370   BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
371   if (T.expectAndConsume(diag::err_expected_lparen_after,
372                          getOpenMPDirectiveName(Kind)))
373     return true;
374   bool IsCorrect = true;
375   bool NoIdentIsFound = true;
376
377   // Read tokens while ')' or annot_pragma_openmp_end is not found.
378   while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
379     CXXScopeSpec SS;
380     SourceLocation TemplateKWLoc;
381     UnqualifiedId Name;
382     // Read var name.
383     Token PrevTok = Tok;
384     NoIdentIsFound = false;
385
386     if (AllowScopeSpecifier && getLangOpts().CPlusPlus &&
387         ParseOptionalCXXScopeSpecifier(SS, nullptr, false)) {
388       IsCorrect = false;
389       SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
390                 StopBeforeMatch);
391     } else if (ParseUnqualifiedId(SS, false, false, false, nullptr,
392                                   TemplateKWLoc, Name)) {
393       IsCorrect = false;
394       SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
395                 StopBeforeMatch);
396     } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) &&
397                Tok.isNot(tok::annot_pragma_openmp_end)) {
398       IsCorrect = false;
399       SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
400                 StopBeforeMatch);
401       Diag(PrevTok.getLocation(), diag::err_expected)
402           << tok::identifier
403           << SourceRange(PrevTok.getLocation(), PrevTokLocation);
404     } else {
405       DeclarationNameInfo NameInfo = Actions.GetNameFromUnqualifiedId(Name);
406       ExprResult Res =
407           Actions.ActOnOpenMPIdExpression(getCurScope(), SS, NameInfo);
408       if (Res.isUsable())
409         VarList.push_back(Res.get());
410     }
411     // Consume ','.
412     if (Tok.is(tok::comma)) {
413       ConsumeToken();
414     }
415   }
416
417   if (NoIdentIsFound) {
418     Diag(Tok, diag::err_expected) << tok::identifier;
419     IsCorrect = false;
420   }
421
422   // Parse ')'.
423   IsCorrect = !T.consumeClose() && IsCorrect;
424
425   return !IsCorrect && VarList.empty();
426 }
427
428 /// \brief Parsing of OpenMP clauses.
429 ///
430 ///    clause:
431 ///       if-clause | final-clause | num_threads-clause | safelen-clause |
432 ///       default-clause | private-clause | firstprivate-clause | shared-clause
433 ///       | linear-clause | aligned-clause | collapse-clause |
434 ///       lastprivate-clause | reduction-clause | proc_bind-clause |
435 ///       schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
436 ///       mergeable-clause | flush-clause | read-clause | write-clause |
437 ///       update-clause | capture-clause | seq_cst-clause | device-clause |
438 ///       simdlen-clause | threads-clause | simd-clause | num_teams-clause |
439 ///       thread_limit-clause | priority-clause | grainsize-clause |
440 ///       nogroup-clause | num_tasks-clause | hint-clause
441 ///
442 OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
443                                      OpenMPClauseKind CKind, bool FirstClause) {
444   OMPClause *Clause = nullptr;
445   bool ErrorFound = false;
446   // Check if clause is allowed for the given directive.
447   if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) {
448     Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
449                                                << getOpenMPDirectiveName(DKind);
450     ErrorFound = true;
451   }
452
453   switch (CKind) {
454   case OMPC_final:
455   case OMPC_num_threads:
456   case OMPC_safelen:
457   case OMPC_simdlen:
458   case OMPC_collapse:
459   case OMPC_ordered:
460   case OMPC_device:
461   case OMPC_num_teams:
462   case OMPC_thread_limit:
463   case OMPC_priority:
464   case OMPC_grainsize:
465   case OMPC_num_tasks:
466   case OMPC_hint:
467     // OpenMP [2.5, Restrictions]
468     //  At most one num_threads clause can appear on the directive.
469     // OpenMP [2.8.1, simd construct, Restrictions]
470     //  Only one safelen  clause can appear on a simd directive.
471     //  Only one simdlen  clause can appear on a simd directive.
472     //  Only one collapse clause can appear on a simd directive.
473     // OpenMP [2.9.1, target data construct, Restrictions]
474     //  At most one device clause can appear on the directive.
475     // OpenMP [2.11.1, task Construct, Restrictions]
476     //  At most one if clause can appear on the directive.
477     //  At most one final clause can appear on the directive.
478     // OpenMP [teams Construct, Restrictions]
479     //  At most one num_teams clause can appear on the directive.
480     //  At most one thread_limit clause can appear on the directive.
481     // OpenMP [2.9.1, task Construct, Restrictions]
482     // At most one priority clause can appear on the directive.
483     // OpenMP [2.9.2, taskloop Construct, Restrictions]
484     // At most one grainsize clause can appear on the directive.
485     // OpenMP [2.9.2, taskloop Construct, Restrictions]
486     // At most one num_tasks clause can appear on the directive.
487     if (!FirstClause) {
488       Diag(Tok, diag::err_omp_more_one_clause)
489           << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
490       ErrorFound = true;
491     }
492
493     if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren))
494       Clause = ParseOpenMPClause(CKind);
495     else
496       Clause = ParseOpenMPSingleExprClause(CKind);
497     break;
498   case OMPC_default:
499   case OMPC_proc_bind:
500     // OpenMP [2.14.3.1, Restrictions]
501     //  Only a single default clause may be specified on a parallel, task or
502     //  teams directive.
503     // OpenMP [2.5, parallel Construct, Restrictions]
504     //  At most one proc_bind clause can appear on the directive.
505     if (!FirstClause) {
506       Diag(Tok, diag::err_omp_more_one_clause)
507           << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
508       ErrorFound = true;
509     }
510
511     Clause = ParseOpenMPSimpleClause(CKind);
512     break;
513   case OMPC_schedule:
514   case OMPC_dist_schedule:
515   case OMPC_defaultmap:
516     // OpenMP [2.7.1, Restrictions, p. 3]
517     //  Only one schedule clause can appear on a loop directive.
518     // OpenMP [2.10.4, Restrictions, p. 106]
519     //  At most one defaultmap clause can appear on the directive.
520     if (!FirstClause) {
521       Diag(Tok, diag::err_omp_more_one_clause)
522           << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
523       ErrorFound = true;
524     }
525
526   case OMPC_if:
527     Clause = ParseOpenMPSingleExprWithArgClause(CKind);
528     break;
529   case OMPC_nowait:
530   case OMPC_untied:
531   case OMPC_mergeable:
532   case OMPC_read:
533   case OMPC_write:
534   case OMPC_update:
535   case OMPC_capture:
536   case OMPC_seq_cst:
537   case OMPC_threads:
538   case OMPC_simd:
539   case OMPC_nogroup:
540     // OpenMP [2.7.1, Restrictions, p. 9]
541     //  Only one ordered clause can appear on a loop directive.
542     // OpenMP [2.7.1, Restrictions, C/C++, p. 4]
543     //  Only one nowait clause can appear on a for directive.
544     if (!FirstClause) {
545       Diag(Tok, diag::err_omp_more_one_clause)
546           << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
547       ErrorFound = true;
548     }
549
550     Clause = ParseOpenMPClause(CKind);
551     break;
552   case OMPC_private:
553   case OMPC_firstprivate:
554   case OMPC_lastprivate:
555   case OMPC_shared:
556   case OMPC_reduction:
557   case OMPC_linear:
558   case OMPC_aligned:
559   case OMPC_copyin:
560   case OMPC_copyprivate:
561   case OMPC_flush:
562   case OMPC_depend:
563   case OMPC_map:
564     Clause = ParseOpenMPVarListClause(DKind, CKind);
565     break;
566   case OMPC_unknown:
567     Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
568         << getOpenMPDirectiveName(DKind);
569     SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
570     break;
571   case OMPC_threadprivate:
572     Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
573                                                << getOpenMPDirectiveName(DKind);
574     SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
575     break;
576   }
577   return ErrorFound ? nullptr : Clause;
578 }
579
580 /// \brief Parsing of OpenMP clauses with single expressions like 'final',
581 /// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams',
582 /// 'thread_limit', 'simdlen', 'priority', 'grainsize', 'num_tasks' or 'hint'.
583 ///
584 ///    final-clause:
585 ///      'final' '(' expression ')'
586 ///
587 ///    num_threads-clause:
588 ///      'num_threads' '(' expression ')'
589 ///
590 ///    safelen-clause:
591 ///      'safelen' '(' expression ')'
592 ///
593 ///    simdlen-clause:
594 ///      'simdlen' '(' expression ')'
595 ///
596 ///    collapse-clause:
597 ///      'collapse' '(' expression ')'
598 ///
599 ///    priority-clause:
600 ///      'priority' '(' expression ')'
601 ///
602 ///    grainsize-clause:
603 ///      'grainsize' '(' expression ')'
604 ///
605 ///    num_tasks-clause:
606 ///      'num_tasks' '(' expression ')'
607 ///
608 ///    hint-clause:
609 ///      'hint' '(' expression ')'
610 ///
611 OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
612   SourceLocation Loc = ConsumeToken();
613
614   BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
615   if (T.expectAndConsume(diag::err_expected_lparen_after,
616                          getOpenMPClauseName(Kind)))
617     return nullptr;
618
619   SourceLocation ELoc = Tok.getLocation();
620   ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
621   ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
622   Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc);
623
624   // Parse ')'.
625   T.consumeClose();
626
627   if (Val.isInvalid())
628     return nullptr;
629
630   return Actions.ActOnOpenMPSingleExprClause(
631       Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation());
632 }
633
634 /// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'.
635 ///
636 ///    default-clause:
637 ///         'default' '(' 'none' | 'shared' ')
638 ///
639 ///    proc_bind-clause:
640 ///         'proc_bind' '(' 'master' | 'close' | 'spread' ')
641 ///
642 OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
643   SourceLocation Loc = Tok.getLocation();
644   SourceLocation LOpen = ConsumeToken();
645   // Parse '('.
646   BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
647   if (T.expectAndConsume(diag::err_expected_lparen_after,
648                          getOpenMPClauseName(Kind)))
649     return nullptr;
650
651   unsigned Type = getOpenMPSimpleClauseType(
652       Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
653   SourceLocation TypeLoc = Tok.getLocation();
654   if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
655       Tok.isNot(tok::annot_pragma_openmp_end))
656     ConsumeAnyToken();
657
658   // Parse ')'.
659   T.consumeClose();
660
661   return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc,
662                                          Tok.getLocation());
663 }
664
665 /// \brief Parsing of OpenMP clauses like 'ordered'.
666 ///
667 ///    ordered-clause:
668 ///         'ordered'
669 ///
670 ///    nowait-clause:
671 ///         'nowait'
672 ///
673 ///    untied-clause:
674 ///         'untied'
675 ///
676 ///    mergeable-clause:
677 ///         'mergeable'
678 ///
679 ///    read-clause:
680 ///         'read'
681 ///
682 ///    threads-clause:
683 ///         'threads'
684 ///
685 ///    simd-clause:
686 ///         'simd'
687 ///
688 ///    nogroup-clause:
689 ///         'nogroup'
690 ///
691 OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
692   SourceLocation Loc = Tok.getLocation();
693   ConsumeAnyToken();
694
695   return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
696 }
697
698
699 /// \brief Parsing of OpenMP clauses with single expressions and some additional
700 /// argument like 'schedule' or 'dist_schedule'.
701 ///
702 ///    schedule-clause:
703 ///      'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression ]
704 ///      ')'
705 ///
706 ///    if-clause:
707 ///      'if' '(' [ directive-name-modifier ':' ] expression ')'
708 ///
709 ///    defaultmap:
710 ///      'defaultmap' '(' modifier ':' kind ')'
711 ///
712 OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) {
713   SourceLocation Loc = ConsumeToken();
714   SourceLocation DelimLoc;
715   // Parse '('.
716   BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
717   if (T.expectAndConsume(diag::err_expected_lparen_after,
718                          getOpenMPClauseName(Kind)))
719     return nullptr;
720
721   ExprResult Val;
722   SmallVector<unsigned, 4> Arg;
723   SmallVector<SourceLocation, 4> KLoc;
724   if (Kind == OMPC_schedule) {
725     enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements };
726     Arg.resize(NumberOfElements);
727     KLoc.resize(NumberOfElements);
728     Arg[Modifier1] = OMPC_SCHEDULE_MODIFIER_unknown;
729     Arg[Modifier2] = OMPC_SCHEDULE_MODIFIER_unknown;
730     Arg[ScheduleKind] = OMPC_SCHEDULE_unknown;
731     auto KindModifier = getOpenMPSimpleClauseType(
732         Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
733     if (KindModifier > OMPC_SCHEDULE_unknown) {
734       // Parse 'modifier'
735       Arg[Modifier1] = KindModifier;
736       KLoc[Modifier1] = Tok.getLocation();
737       if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
738           Tok.isNot(tok::annot_pragma_openmp_end))
739         ConsumeAnyToken();
740       if (Tok.is(tok::comma)) {
741         // Parse ',' 'modifier'
742         ConsumeAnyToken();
743         KindModifier = getOpenMPSimpleClauseType(
744             Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
745         Arg[Modifier2] = KindModifier > OMPC_SCHEDULE_unknown
746                              ? KindModifier
747                              : (unsigned)OMPC_SCHEDULE_unknown;
748         KLoc[Modifier2] = Tok.getLocation();
749         if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
750             Tok.isNot(tok::annot_pragma_openmp_end))
751           ConsumeAnyToken();
752       }
753       // Parse ':'
754       if (Tok.is(tok::colon))
755         ConsumeAnyToken();
756       else
757         Diag(Tok, diag::warn_pragma_expected_colon) << "schedule modifier";
758       KindModifier = getOpenMPSimpleClauseType(
759           Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
760     }
761     Arg[ScheduleKind] = KindModifier;
762     KLoc[ScheduleKind] = Tok.getLocation();
763     if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
764         Tok.isNot(tok::annot_pragma_openmp_end))
765       ConsumeAnyToken();
766     if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static ||
767          Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic ||
768          Arg[ScheduleKind] == OMPC_SCHEDULE_guided) &&
769         Tok.is(tok::comma))
770       DelimLoc = ConsumeAnyToken();
771   } else if (Kind == OMPC_dist_schedule) {
772     Arg.push_back(getOpenMPSimpleClauseType(
773         Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)));
774     KLoc.push_back(Tok.getLocation());
775     if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
776         Tok.isNot(tok::annot_pragma_openmp_end))
777       ConsumeAnyToken();
778     if (Arg.back() == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma))
779       DelimLoc = ConsumeAnyToken();
780   } else if (Kind == OMPC_defaultmap) {
781     // Get a defaultmap modifier
782     Arg.push_back(getOpenMPSimpleClauseType(
783         Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)));
784     KLoc.push_back(Tok.getLocation());
785     if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
786         Tok.isNot(tok::annot_pragma_openmp_end))
787       ConsumeAnyToken();
788     // Parse ':'
789     if (Tok.is(tok::colon))
790       ConsumeAnyToken();
791     else if (Arg.back() != OMPC_DEFAULTMAP_MODIFIER_unknown)
792       Diag(Tok, diag::warn_pragma_expected_colon) << "defaultmap modifier";
793     // Get a defaultmap kind
794     Arg.push_back(getOpenMPSimpleClauseType(
795         Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)));
796     KLoc.push_back(Tok.getLocation());
797     if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
798         Tok.isNot(tok::annot_pragma_openmp_end))
799       ConsumeAnyToken();
800   } else {
801     assert(Kind == OMPC_if);
802     KLoc.push_back(Tok.getLocation());
803     Arg.push_back(ParseOpenMPDirectiveKind(*this));
804     if (Arg.back() != OMPD_unknown) {
805       ConsumeToken();
806       if (Tok.is(tok::colon))
807         DelimLoc = ConsumeToken();
808       else
809         Diag(Tok, diag::warn_pragma_expected_colon)
810             << "directive name modifier";
811     }
812   }
813
814   bool NeedAnExpression = (Kind == OMPC_schedule && DelimLoc.isValid()) ||
815                           (Kind == OMPC_dist_schedule && DelimLoc.isValid()) ||
816                           Kind == OMPC_if;
817   if (NeedAnExpression) {
818     SourceLocation ELoc = Tok.getLocation();
819     ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
820     Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional);
821     Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc);
822   }
823
824   // Parse ')'.
825   T.consumeClose();
826
827   if (NeedAnExpression && Val.isInvalid())
828     return nullptr;
829
830   return Actions.ActOnOpenMPSingleExprWithArgClause(
831       Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc,
832       T.getCloseLocation());
833 }
834
835 static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec,
836                              UnqualifiedId &ReductionId) {
837   SourceLocation TemplateKWLoc;
838   if (ReductionIdScopeSpec.isEmpty()) {
839     auto OOK = OO_None;
840     switch (P.getCurToken().getKind()) {
841     case tok::plus:
842       OOK = OO_Plus;
843       break;
844     case tok::minus:
845       OOK = OO_Minus;
846       break;
847     case tok::star:
848       OOK = OO_Star;
849       break;
850     case tok::amp:
851       OOK = OO_Amp;
852       break;
853     case tok::pipe:
854       OOK = OO_Pipe;
855       break;
856     case tok::caret:
857       OOK = OO_Caret;
858       break;
859     case tok::ampamp:
860       OOK = OO_AmpAmp;
861       break;
862     case tok::pipepipe:
863       OOK = OO_PipePipe;
864       break;
865     default:
866       break;
867     }
868     if (OOK != OO_None) {
869       SourceLocation OpLoc = P.ConsumeToken();
870       SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()};
871       ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations);
872       return false;
873     }
874   }
875   return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false,
876                               /*AllowDestructorName*/ false,
877                               /*AllowConstructorName*/ false, nullptr,
878                               TemplateKWLoc, ReductionId);
879 }
880
881 /// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
882 /// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'.
883 ///
884 ///    private-clause:
885 ///       'private' '(' list ')'
886 ///    firstprivate-clause:
887 ///       'firstprivate' '(' list ')'
888 ///    lastprivate-clause:
889 ///       'lastprivate' '(' list ')'
890 ///    shared-clause:
891 ///       'shared' '(' list ')'
892 ///    linear-clause:
893 ///       'linear' '(' linear-list [ ':' linear-step ] ')'
894 ///    aligned-clause:
895 ///       'aligned' '(' list [ ':' alignment ] ')'
896 ///    reduction-clause:
897 ///       'reduction' '(' reduction-identifier ':' list ')'
898 ///    copyprivate-clause:
899 ///       'copyprivate' '(' list ')'
900 ///    flush-clause:
901 ///       'flush' '(' list ')'
902 ///    depend-clause:
903 ///       'depend' '(' in | out | inout : list | source ')'
904 ///    map-clause:
905 ///       'map' '(' [ [ always , ]
906 ///          to | from | tofrom | alloc | release | delete ':' ] list ')';
907 ///
908 /// For 'linear' clause linear-list may have the following forms:
909 ///  list
910 ///  modifier(list)
911 /// where modifier is 'val' (C) or 'ref', 'val' or 'uval'(C++).
912 OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
913                                             OpenMPClauseKind Kind) {
914   SourceLocation Loc = Tok.getLocation();
915   SourceLocation LOpen = ConsumeToken();
916   SourceLocation ColonLoc = SourceLocation();
917   // Optional scope specifier and unqualified id for reduction identifier.
918   CXXScopeSpec ReductionIdScopeSpec;
919   UnqualifiedId ReductionId;
920   bool InvalidReductionId = false;
921   OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
922   // OpenMP 4.1 [2.15.3.7, linear Clause]
923   //  If no modifier is specified it is assumed to be val.
924   OpenMPLinearClauseKind LinearModifier = OMPC_LINEAR_val;
925   OpenMPMapClauseKind MapType = OMPC_MAP_unknown;
926   OpenMPMapClauseKind MapTypeModifier = OMPC_MAP_unknown;
927   bool MapTypeIsImplicit = false;
928   bool MapTypeModifierSpecified = false;
929   SourceLocation DepLinMapLoc;
930
931   // Parse '('.
932   BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
933   if (T.expectAndConsume(diag::err_expected_lparen_after,
934                          getOpenMPClauseName(Kind)))
935     return nullptr;
936
937   bool NeedRParenForLinear = false;
938   BalancedDelimiterTracker LinearT(*this, tok::l_paren,
939                                   tok::annot_pragma_openmp_end);
940   // Handle reduction-identifier for reduction clause.
941   if (Kind == OMPC_reduction) {
942     ColonProtectionRAIIObject ColonRAII(*this);
943     if (getLangOpts().CPlusPlus) {
944       ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec, nullptr, false);
945     }
946     InvalidReductionId =
947         ParseReductionId(*this, ReductionIdScopeSpec, ReductionId);
948     if (InvalidReductionId) {
949       SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
950                 StopBeforeMatch);
951     }
952     if (Tok.is(tok::colon)) {
953       ColonLoc = ConsumeToken();
954     } else {
955       Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier";
956     }
957   } else if (Kind == OMPC_depend) {
958   // Handle dependency type for depend clause.
959     ColonProtectionRAIIObject ColonRAII(*this);
960     DepKind = static_cast<OpenMPDependClauseKind>(getOpenMPSimpleClauseType(
961         Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
962     DepLinMapLoc = Tok.getLocation();
963
964     if (DepKind == OMPC_DEPEND_unknown) {
965       SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
966                 StopBeforeMatch);
967     } else {
968       ConsumeToken();
969       // Special processing for depend(source) clause.
970       if (DKind == OMPD_ordered && DepKind == OMPC_DEPEND_source) {
971         // Parse ')'.
972         T.consumeClose();
973         return Actions.ActOnOpenMPVarListClause(
974             Kind, llvm::None, /*TailExpr=*/nullptr, Loc, LOpen,
975             /*ColonLoc=*/SourceLocation(), Tok.getLocation(),
976             ReductionIdScopeSpec, DeclarationNameInfo(), DepKind,
977             LinearModifier, MapTypeModifier, MapType, MapTypeIsImplicit,
978             DepLinMapLoc);
979       }
980     }
981     if (Tok.is(tok::colon)) {
982       ColonLoc = ConsumeToken();
983     } else {
984       Diag(Tok, DKind == OMPD_ordered ? diag::warn_pragma_expected_colon_r_paren
985                                       : diag::warn_pragma_expected_colon)
986           << "dependency type";
987     }
988   } else if (Kind == OMPC_linear) {
989     // Try to parse modifier if any.
990     if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) {
991       LinearModifier = static_cast<OpenMPLinearClauseKind>(
992           getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)));
993       DepLinMapLoc = ConsumeToken();
994       LinearT.consumeOpen();
995       NeedRParenForLinear = true;
996     }
997   } else if (Kind == OMPC_map) {
998     // Handle map type for map clause.
999     ColonProtectionRAIIObject ColonRAII(*this);
1000
1001     // the first identifier may be a list item, a map-type or
1002     //   a map-type-modifier
1003     MapType = static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType(
1004         Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
1005     DepLinMapLoc = Tok.getLocation();
1006     bool ColonExpected = false;
1007
1008     if (Tok.is(tok::identifier)) {
1009       if (PP.LookAhead(0).is(tok::colon)) {
1010         MapType = static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType(
1011             Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
1012         if (MapType == OMPC_MAP_unknown) {
1013           Diag(Tok, diag::err_omp_unknown_map_type);
1014         } else if (MapType == OMPC_MAP_always) {
1015           Diag(Tok, diag::err_omp_map_type_missing);
1016         }
1017         ConsumeToken();
1018       } else if (PP.LookAhead(0).is(tok::comma)) {
1019         if (PP.LookAhead(1).is(tok::identifier) &&
1020             PP.LookAhead(2).is(tok::colon)) {
1021           MapTypeModifier =
1022               static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType(
1023                    Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
1024           if (MapTypeModifier != OMPC_MAP_always) {
1025             Diag(Tok, diag::err_omp_unknown_map_type_modifier);
1026             MapTypeModifier = OMPC_MAP_unknown;
1027           } else {
1028             MapTypeModifierSpecified = true;
1029           }
1030
1031           ConsumeToken();
1032           ConsumeToken();
1033
1034           MapType = static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType(
1035               Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
1036           if (MapType == OMPC_MAP_unknown || MapType == OMPC_MAP_always) {
1037             Diag(Tok, diag::err_omp_unknown_map_type);
1038           }
1039           ConsumeToken();
1040         } else {
1041           MapType = OMPC_MAP_tofrom;
1042           MapTypeIsImplicit = true;
1043         }
1044       } else {
1045         MapType = OMPC_MAP_tofrom;
1046         MapTypeIsImplicit = true;
1047       }
1048     } else {
1049       MapType = OMPC_MAP_tofrom;
1050       MapTypeIsImplicit = true;
1051     }
1052
1053     if (Tok.is(tok::colon)) {
1054       ColonLoc = ConsumeToken();
1055     } else if (ColonExpected) {
1056       Diag(Tok, diag::warn_pragma_expected_colon) << "map type";
1057     }
1058   }
1059
1060   SmallVector<Expr *, 5> Vars;
1061   bool IsComma =
1062       ((Kind != OMPC_reduction) && (Kind != OMPC_depend) &&
1063        (Kind != OMPC_map)) ||
1064       ((Kind == OMPC_reduction) && !InvalidReductionId) ||
1065       ((Kind == OMPC_map) && (MapType != OMPC_MAP_unknown) &&
1066        (!MapTypeModifierSpecified ||
1067         (MapTypeModifierSpecified && MapTypeModifier == OMPC_MAP_always))) ||
1068       ((Kind == OMPC_depend) && DepKind != OMPC_DEPEND_unknown);
1069   const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
1070   while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
1071                      Tok.isNot(tok::annot_pragma_openmp_end))) {
1072     ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail);
1073     // Parse variable
1074     ExprResult VarExpr =
1075         Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
1076     if (VarExpr.isUsable()) {
1077       Vars.push_back(VarExpr.get());
1078     } else {
1079       SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
1080                 StopBeforeMatch);
1081     }
1082     // Skip ',' if any
1083     IsComma = Tok.is(tok::comma);
1084     if (IsComma)
1085       ConsumeToken();
1086     else if (Tok.isNot(tok::r_paren) &&
1087              Tok.isNot(tok::annot_pragma_openmp_end) &&
1088              (!MayHaveTail || Tok.isNot(tok::colon)))
1089       Diag(Tok, diag::err_omp_expected_punc)
1090           << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush)
1091                                    : getOpenMPClauseName(Kind))
1092           << (Kind == OMPC_flush);
1093   }
1094
1095   // Parse ')' for linear clause with modifier.
1096   if (NeedRParenForLinear)
1097     LinearT.consumeClose();
1098
1099   // Parse ':' linear-step (or ':' alignment).
1100   Expr *TailExpr = nullptr;
1101   const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon);
1102   if (MustHaveTail) {
1103     ColonLoc = Tok.getLocation();
1104     SourceLocation ELoc = ConsumeToken();
1105     ExprResult Tail = ParseAssignmentExpression();
1106     Tail = Actions.ActOnFinishFullExpr(Tail.get(), ELoc);
1107     if (Tail.isUsable())
1108       TailExpr = Tail.get();
1109     else
1110       SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
1111                 StopBeforeMatch);
1112   }
1113
1114   // Parse ')'.
1115   T.consumeClose();
1116   if ((Kind == OMPC_depend && DepKind != OMPC_DEPEND_unknown && Vars.empty()) ||
1117       (Kind != OMPC_depend && Kind != OMPC_map && Vars.empty()) ||
1118       (MustHaveTail && !TailExpr) || InvalidReductionId) {
1119     return nullptr;
1120   }
1121
1122   return Actions.ActOnOpenMPVarListClause(
1123       Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(),
1124       ReductionIdScopeSpec,
1125       ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId)
1126                             : DeclarationNameInfo(),
1127       DepKind, LinearModifier, MapTypeModifier, MapType, MapTypeIsImplicit,
1128       DepLinMapLoc);
1129 }
1130