blob: 9afe26cee15f739f6d7aa628928ef83a54ddfeca [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
Chandler Carruth5553d0d2014-01-07 11:51:46 +000014#include "RAIIObjectsForParser.h"
Alexey Bataev9959db52014-05-06 10:08:46 +000015#include "clang/AST/ASTConsumer.h"
16#include "clang/AST/ASTContext.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000017#include "clang/AST/StmtOpenMP.h"
Alexey Bataeva769e072013-03-22 06:34:35 +000018#include "clang/Parse/ParseDiagnostic.h"
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000019#include "clang/Parse/Parser.h"
20#include "clang/Sema/Scope.h"
21#include "llvm/ADT/PointerIntPair.h"
Alexey Bataeva769e072013-03-22 06:34:35 +000022using namespace clang;
23
24//===----------------------------------------------------------------------===//
25// OpenMP declarative directives.
26//===----------------------------------------------------------------------===//
27
Alexey Bataev4acb8592014-07-07 13:01:15 +000028static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) {
29 auto Tok = P.getCurToken();
30 auto DKind =
31 Tok.isAnnotation()
32 ? OMPD_unknown
33 : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
34 if (DKind == OMPD_parallel) {
35 Tok = P.getPreprocessor().LookAhead(0);
36 auto SDKind =
37 Tok.isAnnotation()
38 ? OMPD_unknown
39 : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
40 if (SDKind == OMPD_for) {
41 P.ConsumeToken();
42 DKind = OMPD_parallel_for;
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000043 } else if (SDKind == OMPD_sections) {
44 P.ConsumeToken();
45 DKind = OMPD_parallel_sections;
Alexey Bataev4acb8592014-07-07 13:01:15 +000046 }
47 }
48 return DKind;
49}
50
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000051/// \brief Parsing of declarative OpenMP directives.
52///
53/// threadprivate-directive:
54/// annot_pragma_openmp 'threadprivate' simple-variable-list
Alexey Bataeva769e072013-03-22 06:34:35 +000055///
56Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() {
57 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
Alexey Bataevee6507d2013-11-18 08:17:37 +000058 ParenBraceBracketBalancer BalancerRAIIObj(*this);
Alexey Bataeva769e072013-03-22 06:34:35 +000059
60 SourceLocation Loc = ConsumeToken();
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000061 SmallVector<Expr *, 5> Identifiers;
Alexey Bataev4acb8592014-07-07 13:01:15 +000062 auto DKind = ParseOpenMPDirectiveKind(*this);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000063
64 switch (DKind) {
Alexey Bataeva769e072013-03-22 06:34:35 +000065 case OMPD_threadprivate:
66 ConsumeToken();
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000067 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, true)) {
Alexey Bataeva769e072013-03-22 06:34:35 +000068 // The last seen token is annot_pragma_openmp_end - need to check for
69 // extra tokens.
70 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
71 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +000072 << getOpenMPDirectiveName(OMPD_threadprivate);
Alp Tokerd751fa72013-12-18 19:10:49 +000073 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataeva769e072013-03-22 06:34:35 +000074 }
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000075 // Skip the last annot_pragma_openmp_end.
Alexey Bataeva769e072013-03-22 06:34:35 +000076 ConsumeToken();
Alexey Bataeva55ed262014-05-28 06:15:33 +000077 return Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers);
Alexey Bataeva769e072013-03-22 06:34:35 +000078 }
79 break;
80 case OMPD_unknown:
81 Diag(Tok, diag::err_omp_unknown_directive);
82 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000083 case OMPD_parallel:
Alexey Bataev1b59ab52014-02-27 08:29:12 +000084 case OMPD_simd:
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000085 case OMPD_task:
Alexey Bataev68446b72014-07-18 07:47:19 +000086 case OMPD_taskyield:
Alexey Bataev4d1dfea2014-07-18 09:11:51 +000087 case OMPD_barrier:
Alexey Bataev2df347a2014-07-18 10:17:07 +000088 case OMPD_taskwait:
Alexey Bataev6125da92014-07-21 11:26:11 +000089 case OMPD_flush:
Alexey Bataevf29276e2014-06-18 04:14:57 +000090 case OMPD_for:
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000091 case OMPD_sections:
Alexey Bataev1e0498a2014-06-26 08:21:58 +000092 case OMPD_section:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000093 case OMPD_single:
Alexander Musman80c22892014-07-17 08:54:58 +000094 case OMPD_master:
Alexey Bataev9fb6e642014-07-22 06:45:04 +000095 case OMPD_ordered:
Alexander Musmand9ed09f2014-07-21 09:42:05 +000096 case OMPD_critical:
Alexey Bataev4acb8592014-07-07 13:01:15 +000097 case OMPD_parallel_for:
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000098 case OMPD_parallel_sections:
Alexey Bataeva769e072013-03-22 06:34:35 +000099 Diag(Tok, diag::err_omp_unexpected_directive)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000100 << getOpenMPDirectiveName(DKind);
Alexey Bataeva769e072013-03-22 06:34:35 +0000101 break;
102 }
Alp Tokerd751fa72013-12-18 19:10:49 +0000103 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataeva769e072013-03-22 06:34:35 +0000104 return DeclGroupPtrTy();
105}
106
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000107/// \brief Parsing of declarative or executable OpenMP directives.
108///
109/// threadprivate-directive:
110/// annot_pragma_openmp 'threadprivate' simple-variable-list
111/// annot_pragma_openmp_end
112///
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000113/// executable-directive:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000114/// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' |
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000115/// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] |
116/// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' |
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000117/// 'barrier' | 'taskwait' | 'flush' | 'ordered' {clause}
118/// annot_pragma_openmp_end
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000119///
Alexey Bataev68446b72014-07-18 07:47:19 +0000120StmtResult
121Parser::ParseOpenMPDeclarativeOrExecutableDirective(bool StandAloneAllowed) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000122 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
Alexey Bataevee6507d2013-11-18 08:17:37 +0000123 ParenBraceBracketBalancer BalancerRAIIObj(*this);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000124 SmallVector<Expr *, 5> Identifiers;
125 SmallVector<OMPClause *, 5> Clauses;
Alexey Bataev4ca40ed2014-05-12 04:23:46 +0000126 SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1>
Alexey Bataeva55ed262014-05-28 06:15:33 +0000127 FirstClauses(OMPC_unknown + 1);
Alexander Musmana8e9d2e2014-06-03 10:16:47 +0000128 unsigned ScopeFlags =
Alexey Bataeva55ed262014-05-28 06:15:33 +0000129 Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000130 SourceLocation Loc = ConsumeToken(), EndLoc;
Alexey Bataev4acb8592014-07-07 13:01:15 +0000131 auto DKind = ParseOpenMPDirectiveKind(*this);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000132 // Name of critical directive.
133 DeclarationNameInfo DirName;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000134 StmtResult Directive = StmtError();
Alexey Bataev68446b72014-07-18 07:47:19 +0000135 bool HasAssociatedStatement = true;
Alexey Bataev6125da92014-07-21 11:26:11 +0000136 bool FlushHasClause = false;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000137
138 switch (DKind) {
139 case OMPD_threadprivate:
140 ConsumeToken();
141 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, false)) {
142 // The last seen token is annot_pragma_openmp_end - need to check for
143 // extra tokens.
144 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
145 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000146 << getOpenMPDirectiveName(OMPD_threadprivate);
Alp Tokerd751fa72013-12-18 19:10:49 +0000147 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000148 }
149 DeclGroupPtrTy Res =
Alexey Bataeva55ed262014-05-28 06:15:33 +0000150 Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000151 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
152 }
Alp Tokerd751fa72013-12-18 19:10:49 +0000153 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000154 break;
Alexey Bataev6125da92014-07-21 11:26:11 +0000155 case OMPD_flush:
156 if (PP.LookAhead(0).is(tok::l_paren)) {
157 FlushHasClause = true;
158 // Push copy of the current token back to stream to properly parse
159 // pseudo-clause OMPFlushClause.
160 PP.EnterToken(Tok);
161 }
Alexey Bataev68446b72014-07-18 07:47:19 +0000162 case OMPD_taskyield:
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000163 case OMPD_barrier:
Alexey Bataev2df347a2014-07-18 10:17:07 +0000164 case OMPD_taskwait:
Alexey Bataev68446b72014-07-18 07:47:19 +0000165 if (!StandAloneAllowed) {
166 Diag(Tok, diag::err_omp_immediate_directive)
167 << getOpenMPDirectiveName(DKind);
168 }
169 HasAssociatedStatement = false;
Alexey Bataev6125da92014-07-21 11:26:11 +0000170 // Fall through for further analysis.
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000171 case OMPD_parallel:
Alexey Bataevf29276e2014-06-18 04:14:57 +0000172 case OMPD_simd:
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000173 case OMPD_for:
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000174 case OMPD_sections:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000175 case OMPD_single:
Alexey Bataev4acb8592014-07-07 13:01:15 +0000176 case OMPD_section:
Alexander Musman80c22892014-07-17 08:54:58 +0000177 case OMPD_master:
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000178 case OMPD_critical:
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000179 case OMPD_parallel_for:
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000180 case OMPD_parallel_sections:
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000181 case OMPD_task:
182 case OMPD_ordered: {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000183 ConsumeToken();
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000184 // Parse directive name of the 'critical' directive if any.
185 if (DKind == OMPD_critical) {
186 BalancedDelimiterTracker T(*this, tok::l_paren,
187 tok::annot_pragma_openmp_end);
188 if (!T.consumeOpen()) {
189 if (Tok.isAnyIdentifier()) {
190 DirName =
191 DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation());
192 ConsumeAnyToken();
193 } else {
194 Diag(Tok, diag::err_omp_expected_identifier_for_critical);
195 }
196 T.consumeClose();
197 }
198 }
Alexey Bataev758e55e2013-09-06 18:03:48 +0000199
Alexey Bataevf29276e2014-06-18 04:14:57 +0000200 if (isOpenMPLoopDirective(DKind))
201 ScopeFlags |= Scope::OpenMPLoopDirectiveScope;
202 if (isOpenMPSimdDirective(DKind))
203 ScopeFlags |= Scope::OpenMPSimdDirectiveScope;
204 ParseScope OMPDirectiveScope(this, ScopeFlags);
Alexey Bataevbae9a792014-06-27 10:37:06 +0000205 Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000206
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000207 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
Alexey Bataev6125da92014-07-21 11:26:11 +0000208 OpenMPClauseKind CKind =
209 Tok.isAnnotation()
210 ? OMPC_unknown
211 : FlushHasClause ? OMPC_flush
212 : getOpenMPClauseKind(PP.getSpelling(Tok));
213 FlushHasClause = false;
Alexey Bataeva55ed262014-05-28 06:15:33 +0000214 OMPClause *Clause =
215 ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000216 FirstClauses[CKind].setInt(true);
217 if (Clause) {
218 FirstClauses[CKind].setPointer(Clause);
219 Clauses.push_back(Clause);
220 }
221
222 // Skip ',' if any.
223 if (Tok.is(tok::comma))
224 ConsumeToken();
225 }
226 // End location of the directive.
227 EndLoc = Tok.getLocation();
228 // Consume final annot_pragma_openmp_end.
229 ConsumeToken();
230
231 StmtResult AssociatedStmt;
232 bool CreateDirective = true;
Alexey Bataev68446b72014-07-18 07:47:19 +0000233 if (HasAssociatedStatement) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000234 // The body is a block scope like in Lambdas and Blocks.
235 Sema::CompoundScopeRAII CompoundScope(Actions);
Alexey Bataevbae9a792014-06-27 10:37:06 +0000236 Actions.ActOnOpenMPRegionStart(DKind, getCurScope());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000237 Actions.ActOnStartOfCompoundStmt();
238 // Parse statement
239 AssociatedStmt = ParseStatement();
240 Actions.ActOnFinishOfCompoundStmt();
241 if (!AssociatedStmt.isUsable()) {
242 Actions.ActOnCapturedRegionError();
243 CreateDirective = false;
244 } else {
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000245 AssociatedStmt = Actions.ActOnCapturedRegionEnd(AssociatedStmt.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000246 CreateDirective = AssociatedStmt.isUsable();
247 }
248 }
249 if (CreateDirective)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000250 Directive = Actions.ActOnOpenMPExecutableDirective(
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000251 DKind, DirName, Clauses, AssociatedStmt.get(), Loc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000252
253 // Exit scope.
Alexey Bataev758e55e2013-09-06 18:03:48 +0000254 Actions.EndOpenMPDSABlock(Directive.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000255 OMPDirectiveScope.Exit();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000256 break;
Alexey Bataeva55ed262014-05-28 06:15:33 +0000257 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000258 case OMPD_unknown:
259 Diag(Tok, diag::err_omp_unknown_directive);
Alp Tokerd751fa72013-12-18 19:10:49 +0000260 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000261 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000262 }
263 return Directive;
264}
265
Alexey Bataeva769e072013-03-22 06:34:35 +0000266/// \brief Parses list of simple variables for '#pragma omp threadprivate'
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000267/// directive.
Alexey Bataeva769e072013-03-22 06:34:35 +0000268///
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000269/// simple-variable-list:
270/// '(' id-expression {, id-expression} ')'
271///
272bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind,
273 SmallVectorImpl<Expr *> &VarList,
274 bool AllowScopeSpecifier) {
275 VarList.clear();
Alexey Bataeva769e072013-03-22 06:34:35 +0000276 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000277 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000278 if (T.expectAndConsume(diag::err_expected_lparen_after,
279 getOpenMPDirectiveName(Kind)))
280 return true;
281 bool IsCorrect = true;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000282 bool NoIdentIsFound = true;
Alexey Bataeva769e072013-03-22 06:34:35 +0000283
284 // Read tokens while ')' or annot_pragma_openmp_end is not found.
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000285 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000286 CXXScopeSpec SS;
287 SourceLocation TemplateKWLoc;
288 UnqualifiedId Name;
289 // Read var name.
290 Token PrevTok = Tok;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000291 NoIdentIsFound = false;
Alexey Bataeva769e072013-03-22 06:34:35 +0000292
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000293 if (AllowScopeSpecifier && getLangOpts().CPlusPlus &&
294 ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000295 IsCorrect = false;
296 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000297 StopBeforeMatch);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000298 } else if (ParseUnqualifiedId(SS, false, false, false, ParsedType(),
299 TemplateKWLoc, Name)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000300 IsCorrect = false;
301 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000302 StopBeforeMatch);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000303 } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) &&
304 Tok.isNot(tok::annot_pragma_openmp_end)) {
305 IsCorrect = false;
306 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000307 StopBeforeMatch);
Alp Tokerec543272013-12-24 09:48:30 +0000308 Diag(PrevTok.getLocation(), diag::err_expected)
309 << tok::identifier
310 << SourceRange(PrevTok.getLocation(), PrevTokLocation);
Alexey Bataeva769e072013-03-22 06:34:35 +0000311 } else {
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000312 DeclarationNameInfo NameInfo = Actions.GetNameFromUnqualifiedId(Name);
Alexey Bataeva55ed262014-05-28 06:15:33 +0000313 ExprResult Res =
314 Actions.ActOnOpenMPIdExpression(getCurScope(), SS, NameInfo);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000315 if (Res.isUsable())
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000316 VarList.push_back(Res.get());
Alexey Bataeva769e072013-03-22 06:34:35 +0000317 }
318 // Consume ','.
319 if (Tok.is(tok::comma)) {
320 ConsumeToken();
321 }
Alexey Bataeva769e072013-03-22 06:34:35 +0000322 }
323
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000324 if (NoIdentIsFound) {
Alp Tokerec543272013-12-24 09:48:30 +0000325 Diag(Tok, diag::err_expected) << tok::identifier;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000326 IsCorrect = false;
327 }
328
329 // Parse ')'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000330 IsCorrect = !T.consumeClose() && IsCorrect;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000331
332 return !IsCorrect && VarList.empty();
Alexey Bataeva769e072013-03-22 06:34:35 +0000333}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000334
335/// \brief Parsing of OpenMP clauses.
336///
337/// clause:
Alexey Bataev3778b602014-07-17 07:32:53 +0000338/// if-clause | final-clause | num_threads-clause | safelen-clause |
339/// default-clause | private-clause | firstprivate-clause | shared-clause
340/// | linear-clause | aligned-clause | collapse-clause |
341/// lastprivate-clause | reduction-clause | proc_bind-clause |
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000342/// schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
Alexey Bataev6125da92014-07-21 11:26:11 +0000343/// mergeable-clause | flush-clause
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000344///
345OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
346 OpenMPClauseKind CKind, bool FirstClause) {
Craig Topper161e4db2014-05-21 06:02:52 +0000347 OMPClause *Clause = nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000348 bool ErrorFound = false;
349 // Check if clause is allowed for the given directive.
350 if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) {
Alexey Bataeva55ed262014-05-28 06:15:33 +0000351 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
352 << getOpenMPDirectiveName(DKind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000353 ErrorFound = true;
354 }
355
356 switch (CKind) {
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000357 case OMPC_if:
Alexey Bataev3778b602014-07-17 07:32:53 +0000358 case OMPC_final:
Alexey Bataev568a8332014-03-06 06:15:19 +0000359 case OMPC_num_threads:
Alexey Bataev62c87d22014-03-21 04:51:18 +0000360 case OMPC_safelen:
Alexander Musman8bd31e62014-05-27 15:12:19 +0000361 case OMPC_collapse:
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000362 // OpenMP [2.5, Restrictions]
363 // At most one if clause can appear on the directive.
Alexey Bataev568a8332014-03-06 06:15:19 +0000364 // At most one num_threads clause can appear on the directive.
Alexey Bataev62c87d22014-03-21 04:51:18 +0000365 // OpenMP [2.8.1, simd construct, Restrictions]
Alexander Musman8bd31e62014-05-27 15:12:19 +0000366 // Only one safelen clause can appear on a simd directive.
367 // Only one collapse clause can appear on a simd directive.
Alexey Bataev3778b602014-07-17 07:32:53 +0000368 // OpenMP [2.11.1, task Construct, Restrictions]
369 // At most one if clause can appear on the directive.
370 // At most one final clause can appear on the directive.
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000371 if (!FirstClause) {
Alexey Bataeva55ed262014-05-28 06:15:33 +0000372 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
373 << getOpenMPClauseName(CKind);
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000374 }
375
376 Clause = ParseOpenMPSingleExprClause(CKind);
377 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000378 case OMPC_default:
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000379 case OMPC_proc_bind:
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000380 // OpenMP [2.14.3.1, Restrictions]
381 // Only a single default clause may be specified on a parallel, task or
382 // teams directive.
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000383 // OpenMP [2.5, parallel Construct, Restrictions]
384 // At most one proc_bind clause can appear on the directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000385 if (!FirstClause) {
Alexey Bataeva55ed262014-05-28 06:15:33 +0000386 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
387 << getOpenMPClauseName(CKind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000388 }
389
390 Clause = ParseOpenMPSimpleClause(CKind);
391 break;
Alexey Bataev56dafe82014-06-20 07:16:17 +0000392 case OMPC_schedule:
393 // OpenMP [2.7.1, Restrictions, p. 3]
394 // Only one schedule clause can appear on a loop directive.
395 if (!FirstClause) {
396 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
397 << getOpenMPClauseName(CKind);
398 }
399
400 Clause = ParseOpenMPSingleExprWithArgClause(CKind);
401 break;
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000402 case OMPC_ordered:
Alexey Bataev236070f2014-06-20 11:19:47 +0000403 case OMPC_nowait:
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000404 case OMPC_untied:
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000405 case OMPC_mergeable:
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000406 // OpenMP [2.7.1, Restrictions, p. 9]
407 // Only one ordered clause can appear on a loop directive.
Alexey Bataev236070f2014-06-20 11:19:47 +0000408 // OpenMP [2.7.1, Restrictions, C/C++, p. 4]
409 // Only one nowait clause can appear on a for directive.
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000410 if (!FirstClause) {
411 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
412 << getOpenMPClauseName(CKind);
413 }
414
415 Clause = ParseOpenMPClause(CKind);
416 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000417 case OMPC_private:
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000418 case OMPC_firstprivate:
Alexander Musman1bb328c2014-06-04 13:06:39 +0000419 case OMPC_lastprivate:
Alexey Bataev758e55e2013-09-06 18:03:48 +0000420 case OMPC_shared:
Alexey Bataevc5e02582014-06-16 07:08:35 +0000421 case OMPC_reduction:
Alexander Musman8dba6642014-04-22 13:09:42 +0000422 case OMPC_linear:
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000423 case OMPC_aligned:
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000424 case OMPC_copyin:
Alexey Bataevbae9a792014-06-27 10:37:06 +0000425 case OMPC_copyprivate:
Alexey Bataev6125da92014-07-21 11:26:11 +0000426 case OMPC_flush:
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000427 Clause = ParseOpenMPVarListClause(CKind);
428 break;
429 case OMPC_unknown:
430 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000431 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000432 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000433 break;
434 case OMPC_threadprivate:
Alexey Bataeva55ed262014-05-28 06:15:33 +0000435 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
436 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000437 SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000438 break;
439 }
Craig Topper161e4db2014-05-21 06:02:52 +0000440 return ErrorFound ? nullptr : Clause;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000441}
442
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000443/// \brief Parsing of OpenMP clauses with single expressions like 'if',
Alexey Bataev3778b602014-07-17 07:32:53 +0000444/// 'final', 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams' or
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000445/// 'thread_limit'.
446///
447/// if-clause:
448/// 'if' '(' expression ')'
449///
Alexey Bataev3778b602014-07-17 07:32:53 +0000450/// final-clause:
451/// 'final' '(' expression ')'
452///
Alexey Bataev62c87d22014-03-21 04:51:18 +0000453/// num_threads-clause:
454/// 'num_threads' '(' expression ')'
455///
456/// safelen-clause:
457/// 'safelen' '(' expression ')'
458///
Alexander Musman8bd31e62014-05-27 15:12:19 +0000459/// collapse-clause:
460/// 'collapse' '(' expression ')'
461///
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000462OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
463 SourceLocation Loc = ConsumeToken();
464
465 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
466 if (T.expectAndConsume(diag::err_expected_lparen_after,
467 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000468 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000469
470 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
471 ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
472
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000473 // Parse ')'.
474 T.consumeClose();
475
476 if (Val.isInvalid())
Craig Topper161e4db2014-05-21 06:02:52 +0000477 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000478
Alexey Bataeva55ed262014-05-28 06:15:33 +0000479 return Actions.ActOnOpenMPSingleExprClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000480 Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation());
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000481}
482
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000483/// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000484///
485/// default-clause:
486/// 'default' '(' 'none' | 'shared' ')
487///
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000488/// proc_bind-clause:
489/// 'proc_bind' '(' 'master' | 'close' | 'spread' ')
490///
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000491OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
492 SourceLocation Loc = Tok.getLocation();
493 SourceLocation LOpen = ConsumeToken();
494 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000495 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000496 if (T.expectAndConsume(diag::err_expected_lparen_after,
497 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000498 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000499
Alexey Bataeva55ed262014-05-28 06:15:33 +0000500 unsigned Type = getOpenMPSimpleClauseType(
501 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000502 SourceLocation TypeLoc = Tok.getLocation();
503 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
504 Tok.isNot(tok::annot_pragma_openmp_end))
505 ConsumeAnyToken();
506
507 // Parse ')'.
508 T.consumeClose();
509
510 return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc,
511 Tok.getLocation());
512}
513
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000514/// \brief Parsing of OpenMP clauses like 'ordered'.
515///
516/// ordered-clause:
517/// 'ordered'
518///
Alexey Bataev236070f2014-06-20 11:19:47 +0000519/// nowait-clause:
520/// 'nowait'
521///
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000522/// untied-clause:
523/// 'untied'
524///
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000525/// mergeable-clause:
526/// 'mergeable'
527///
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000528OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
529 SourceLocation Loc = Tok.getLocation();
530 ConsumeAnyToken();
531
532 return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
533}
534
535
Alexey Bataev56dafe82014-06-20 07:16:17 +0000536/// \brief Parsing of OpenMP clauses with single expressions and some additional
537/// argument like 'schedule' or 'dist_schedule'.
538///
539/// schedule-clause:
540/// 'schedule' '(' kind [',' expression ] ')'
541///
542OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) {
543 SourceLocation Loc = ConsumeToken();
544 SourceLocation CommaLoc;
545 // Parse '('.
546 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
547 if (T.expectAndConsume(diag::err_expected_lparen_after,
548 getOpenMPClauseName(Kind)))
549 return nullptr;
550
551 ExprResult Val;
552 unsigned Type = getOpenMPSimpleClauseType(
553 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
554 SourceLocation KLoc = Tok.getLocation();
555 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
556 Tok.isNot(tok::annot_pragma_openmp_end))
557 ConsumeAnyToken();
558
559 if (Kind == OMPC_schedule &&
560 (Type == OMPC_SCHEDULE_static || Type == OMPC_SCHEDULE_dynamic ||
561 Type == OMPC_SCHEDULE_guided) &&
562 Tok.is(tok::comma)) {
563 CommaLoc = ConsumeAnyToken();
564 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
565 Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional);
566 if (Val.isInvalid())
567 return nullptr;
568 }
569
570 // Parse ')'.
571 T.consumeClose();
572
573 return Actions.ActOnOpenMPSingleExprWithArgClause(
574 Kind, Type, Val.get(), Loc, T.getOpenLocation(), KLoc, CommaLoc,
575 T.getCloseLocation());
576}
577
Alexey Bataevc5e02582014-06-16 07:08:35 +0000578static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec,
579 UnqualifiedId &ReductionId) {
580 SourceLocation TemplateKWLoc;
581 if (ReductionIdScopeSpec.isEmpty()) {
582 auto OOK = OO_None;
583 switch (P.getCurToken().getKind()) {
584 case tok::plus:
585 OOK = OO_Plus;
586 break;
587 case tok::minus:
588 OOK = OO_Minus;
589 break;
590 case tok::star:
591 OOK = OO_Star;
592 break;
593 case tok::amp:
594 OOK = OO_Amp;
595 break;
596 case tok::pipe:
597 OOK = OO_Pipe;
598 break;
599 case tok::caret:
600 OOK = OO_Caret;
601 break;
602 case tok::ampamp:
603 OOK = OO_AmpAmp;
604 break;
605 case tok::pipepipe:
606 OOK = OO_PipePipe;
607 break;
608 default:
609 break;
610 }
611 if (OOK != OO_None) {
612 SourceLocation OpLoc = P.ConsumeToken();
Alexey Bataev23b69422014-06-18 07:08:49 +0000613 SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()};
Alexey Bataevc5e02582014-06-16 07:08:35 +0000614 ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations);
615 return false;
616 }
617 }
618 return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false,
619 /*AllowDestructorName*/ false,
620 /*AllowConstructorName*/ false, ParsedType(),
621 TemplateKWLoc, ReductionId);
622}
623
Alexander Musman1bb328c2014-06-04 13:06:39 +0000624/// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
Alexey Bataev6125da92014-07-21 11:26:11 +0000625/// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000626///
627/// private-clause:
628/// 'private' '(' list ')'
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000629/// firstprivate-clause:
630/// 'firstprivate' '(' list ')'
Alexander Musman1bb328c2014-06-04 13:06:39 +0000631/// lastprivate-clause:
632/// 'lastprivate' '(' list ')'
Alexey Bataev758e55e2013-09-06 18:03:48 +0000633/// shared-clause:
634/// 'shared' '(' list ')'
Alexander Musman8dba6642014-04-22 13:09:42 +0000635/// linear-clause:
636/// 'linear' '(' list [ ':' linear-step ] ')'
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000637/// aligned-clause:
638/// 'aligned' '(' list [ ':' alignment ] ')'
Alexey Bataevc5e02582014-06-16 07:08:35 +0000639/// reduction-clause:
640/// 'reduction' '(' reduction-identifier ':' list ')'
Alexey Bataev6125da92014-07-21 11:26:11 +0000641/// copyprivate-clause:
642/// 'copyprivate' '(' list ')'
643/// flush-clause:
644/// 'flush' '(' list ')'
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000645///
646OMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) {
647 SourceLocation Loc = Tok.getLocation();
648 SourceLocation LOpen = ConsumeToken();
Alexander Musman8dba6642014-04-22 13:09:42 +0000649 SourceLocation ColonLoc = SourceLocation();
Alexey Bataevc5e02582014-06-16 07:08:35 +0000650 // Optional scope specifier and unqualified id for reduction identifier.
651 CXXScopeSpec ReductionIdScopeSpec;
652 UnqualifiedId ReductionId;
653 bool InvalidReductionId = false;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000654 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000655 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000656 if (T.expectAndConsume(diag::err_expected_lparen_after,
657 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000658 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000659
Alexey Bataevc5e02582014-06-16 07:08:35 +0000660 // Handle reduction-identifier for reduction clause.
661 if (Kind == OMPC_reduction) {
662 ColonProtectionRAIIObject ColonRAII(*this);
663 if (getLangOpts().CPlusPlus) {
664 ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec, ParsedType(), false);
665 }
666 InvalidReductionId =
667 ParseReductionId(*this, ReductionIdScopeSpec, ReductionId);
668 if (InvalidReductionId) {
669 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
670 StopBeforeMatch);
671 }
672 if (Tok.is(tok::colon)) {
673 ColonLoc = ConsumeToken();
674 } else {
675 Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier";
676 }
677 }
678
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000679 SmallVector<Expr *, 5> Vars;
Alexey Bataevc5e02582014-06-16 07:08:35 +0000680 bool IsComma = !InvalidReductionId;
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000681 const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
Alexander Musman8dba6642014-04-22 13:09:42 +0000682 while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000683 Tok.isNot(tok::annot_pragma_openmp_end))) {
Alexander Musman8dba6642014-04-22 13:09:42 +0000684 ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000685 // Parse variable
686 ExprResult VarExpr = ParseAssignmentExpression();
687 if (VarExpr.isUsable()) {
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000688 Vars.push_back(VarExpr.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000689 } else {
690 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000691 StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000692 }
693 // Skip ',' if any
694 IsComma = Tok.is(tok::comma);
Alexander Musman8dba6642014-04-22 13:09:42 +0000695 if (IsComma)
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000696 ConsumeToken();
Alexander Musman8dba6642014-04-22 13:09:42 +0000697 else if (Tok.isNot(tok::r_paren) &&
698 Tok.isNot(tok::annot_pragma_openmp_end) &&
699 (!MayHaveTail || Tok.isNot(tok::colon)))
Alexey Bataev6125da92014-07-21 11:26:11 +0000700 Diag(Tok, diag::err_omp_expected_punc)
701 << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush)
702 : getOpenMPClauseName(Kind))
703 << (Kind == OMPC_flush);
Alexander Musman8dba6642014-04-22 13:09:42 +0000704 }
705
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000706 // Parse ':' linear-step (or ':' alignment).
Craig Topper161e4db2014-05-21 06:02:52 +0000707 Expr *TailExpr = nullptr;
Alexander Musman8dba6642014-04-22 13:09:42 +0000708 const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon);
709 if (MustHaveTail) {
710 ColonLoc = Tok.getLocation();
711 ConsumeToken();
712 ExprResult Tail = ParseAssignmentExpression();
713 if (Tail.isUsable())
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000714 TailExpr = Tail.get();
Alexander Musman8dba6642014-04-22 13:09:42 +0000715 else
716 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
717 StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000718 }
719
720 // Parse ')'.
721 T.consumeClose();
Alexey Bataevc5e02582014-06-16 07:08:35 +0000722 if (Vars.empty() || (MustHaveTail && !TailExpr) || InvalidReductionId)
Craig Topper161e4db2014-05-21 06:02:52 +0000723 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000724
Alexey Bataevc5e02582014-06-16 07:08:35 +0000725 return Actions.ActOnOpenMPVarListClause(
726 Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(),
727 ReductionIdScopeSpec,
728 ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId)
729 : DeclarationNameInfo());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000730}
731