blob: f5ccb7c14e4cb2c4ea3a81de651b01b263418733 [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 Bataev0162e452014-07-22 10:10:35 +000099 case OMPD_atomic:
Alexey Bataeva769e072013-03-22 06:34:35 +0000100 Diag(Tok, diag::err_omp_unexpected_directive)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000101 << getOpenMPDirectiveName(DKind);
Alexey Bataeva769e072013-03-22 06:34:35 +0000102 break;
103 }
Alp Tokerd751fa72013-12-18 19:10:49 +0000104 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataeva769e072013-03-22 06:34:35 +0000105 return DeclGroupPtrTy();
106}
107
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000108/// \brief Parsing of declarative or executable OpenMP directives.
109///
110/// threadprivate-directive:
111/// annot_pragma_openmp 'threadprivate' simple-variable-list
112/// annot_pragma_openmp_end
113///
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000114/// executable-directive:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000115/// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' |
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000116/// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] |
117/// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' |
Alexey Bataev0162e452014-07-22 10:10:35 +0000118/// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' {clause}
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000119/// annot_pragma_openmp_end
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000120///
Alexey Bataev68446b72014-07-18 07:47:19 +0000121StmtResult
122Parser::ParseOpenMPDeclarativeOrExecutableDirective(bool StandAloneAllowed) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000123 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
Alexey Bataevee6507d2013-11-18 08:17:37 +0000124 ParenBraceBracketBalancer BalancerRAIIObj(*this);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000125 SmallVector<Expr *, 5> Identifiers;
126 SmallVector<OMPClause *, 5> Clauses;
Alexey Bataev4ca40ed2014-05-12 04:23:46 +0000127 SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1>
Alexey Bataeva55ed262014-05-28 06:15:33 +0000128 FirstClauses(OMPC_unknown + 1);
Alexander Musmana8e9d2e2014-06-03 10:16:47 +0000129 unsigned ScopeFlags =
Alexey Bataeva55ed262014-05-28 06:15:33 +0000130 Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000131 SourceLocation Loc = ConsumeToken(), EndLoc;
Alexey Bataev4acb8592014-07-07 13:01:15 +0000132 auto DKind = ParseOpenMPDirectiveKind(*this);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000133 // Name of critical directive.
134 DeclarationNameInfo DirName;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000135 StmtResult Directive = StmtError();
Alexey Bataev68446b72014-07-18 07:47:19 +0000136 bool HasAssociatedStatement = true;
Alexey Bataev6125da92014-07-21 11:26:11 +0000137 bool FlushHasClause = false;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000138
139 switch (DKind) {
140 case OMPD_threadprivate:
141 ConsumeToken();
142 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, false)) {
143 // The last seen token is annot_pragma_openmp_end - need to check for
144 // extra tokens.
145 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
146 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000147 << getOpenMPDirectiveName(OMPD_threadprivate);
Alp Tokerd751fa72013-12-18 19:10:49 +0000148 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000149 }
150 DeclGroupPtrTy Res =
Alexey Bataeva55ed262014-05-28 06:15:33 +0000151 Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000152 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
153 }
Alp Tokerd751fa72013-12-18 19:10:49 +0000154 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000155 break;
Alexey Bataev6125da92014-07-21 11:26:11 +0000156 case OMPD_flush:
157 if (PP.LookAhead(0).is(tok::l_paren)) {
158 FlushHasClause = true;
159 // Push copy of the current token back to stream to properly parse
160 // pseudo-clause OMPFlushClause.
161 PP.EnterToken(Tok);
162 }
Alexey Bataev68446b72014-07-18 07:47:19 +0000163 case OMPD_taskyield:
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000164 case OMPD_barrier:
Alexey Bataev2df347a2014-07-18 10:17:07 +0000165 case OMPD_taskwait:
Alexey Bataev68446b72014-07-18 07:47:19 +0000166 if (!StandAloneAllowed) {
167 Diag(Tok, diag::err_omp_immediate_directive)
168 << getOpenMPDirectiveName(DKind);
169 }
170 HasAssociatedStatement = false;
Alexey Bataev6125da92014-07-21 11:26:11 +0000171 // Fall through for further analysis.
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000172 case OMPD_parallel:
Alexey Bataevf29276e2014-06-18 04:14:57 +0000173 case OMPD_simd:
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000174 case OMPD_for:
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000175 case OMPD_sections:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000176 case OMPD_single:
Alexey Bataev4acb8592014-07-07 13:01:15 +0000177 case OMPD_section:
Alexander Musman80c22892014-07-17 08:54:58 +0000178 case OMPD_master:
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000179 case OMPD_critical:
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000180 case OMPD_parallel_for:
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000181 case OMPD_parallel_sections:
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000182 case OMPD_task:
Alexey Bataev0162e452014-07-22 10:10:35 +0000183 case OMPD_ordered:
184 case OMPD_atomic: {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000185 ConsumeToken();
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000186 // Parse directive name of the 'critical' directive if any.
187 if (DKind == OMPD_critical) {
188 BalancedDelimiterTracker T(*this, tok::l_paren,
189 tok::annot_pragma_openmp_end);
190 if (!T.consumeOpen()) {
191 if (Tok.isAnyIdentifier()) {
192 DirName =
193 DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation());
194 ConsumeAnyToken();
195 } else {
196 Diag(Tok, diag::err_omp_expected_identifier_for_critical);
197 }
198 T.consumeClose();
199 }
200 }
Alexey Bataev758e55e2013-09-06 18:03:48 +0000201
Alexey Bataevf29276e2014-06-18 04:14:57 +0000202 if (isOpenMPLoopDirective(DKind))
203 ScopeFlags |= Scope::OpenMPLoopDirectiveScope;
204 if (isOpenMPSimdDirective(DKind))
205 ScopeFlags |= Scope::OpenMPSimdDirectiveScope;
206 ParseScope OMPDirectiveScope(this, ScopeFlags);
Alexey Bataevbae9a792014-06-27 10:37:06 +0000207 Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000208
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000209 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
Alexey Bataev6125da92014-07-21 11:26:11 +0000210 OpenMPClauseKind CKind =
211 Tok.isAnnotation()
212 ? OMPC_unknown
213 : FlushHasClause ? OMPC_flush
214 : getOpenMPClauseKind(PP.getSpelling(Tok));
215 FlushHasClause = false;
Alexey Bataeva55ed262014-05-28 06:15:33 +0000216 OMPClause *Clause =
217 ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000218 FirstClauses[CKind].setInt(true);
219 if (Clause) {
220 FirstClauses[CKind].setPointer(Clause);
221 Clauses.push_back(Clause);
222 }
223
224 // Skip ',' if any.
225 if (Tok.is(tok::comma))
226 ConsumeToken();
227 }
228 // End location of the directive.
229 EndLoc = Tok.getLocation();
230 // Consume final annot_pragma_openmp_end.
231 ConsumeToken();
232
233 StmtResult AssociatedStmt;
234 bool CreateDirective = true;
Alexey Bataev68446b72014-07-18 07:47:19 +0000235 if (HasAssociatedStatement) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000236 // The body is a block scope like in Lambdas and Blocks.
237 Sema::CompoundScopeRAII CompoundScope(Actions);
Alexey Bataevbae9a792014-06-27 10:37:06 +0000238 Actions.ActOnOpenMPRegionStart(DKind, getCurScope());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000239 Actions.ActOnStartOfCompoundStmt();
240 // Parse statement
241 AssociatedStmt = ParseStatement();
242 Actions.ActOnFinishOfCompoundStmt();
243 if (!AssociatedStmt.isUsable()) {
244 Actions.ActOnCapturedRegionError();
245 CreateDirective = false;
246 } else {
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000247 AssociatedStmt = Actions.ActOnCapturedRegionEnd(AssociatedStmt.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000248 CreateDirective = AssociatedStmt.isUsable();
249 }
250 }
251 if (CreateDirective)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000252 Directive = Actions.ActOnOpenMPExecutableDirective(
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000253 DKind, DirName, Clauses, AssociatedStmt.get(), Loc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000254
255 // Exit scope.
Alexey Bataev758e55e2013-09-06 18:03:48 +0000256 Actions.EndOpenMPDSABlock(Directive.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000257 OMPDirectiveScope.Exit();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000258 break;
Alexey Bataeva55ed262014-05-28 06:15:33 +0000259 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000260 case OMPD_unknown:
261 Diag(Tok, diag::err_omp_unknown_directive);
Alp Tokerd751fa72013-12-18 19:10:49 +0000262 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000263 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000264 }
265 return Directive;
266}
267
Alexey Bataeva769e072013-03-22 06:34:35 +0000268/// \brief Parses list of simple variables for '#pragma omp threadprivate'
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000269/// directive.
Alexey Bataeva769e072013-03-22 06:34:35 +0000270///
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000271/// simple-variable-list:
272/// '(' id-expression {, id-expression} ')'
273///
274bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind,
275 SmallVectorImpl<Expr *> &VarList,
276 bool AllowScopeSpecifier) {
277 VarList.clear();
Alexey Bataeva769e072013-03-22 06:34:35 +0000278 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000279 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000280 if (T.expectAndConsume(diag::err_expected_lparen_after,
281 getOpenMPDirectiveName(Kind)))
282 return true;
283 bool IsCorrect = true;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000284 bool NoIdentIsFound = true;
Alexey Bataeva769e072013-03-22 06:34:35 +0000285
286 // Read tokens while ')' or annot_pragma_openmp_end is not found.
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000287 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000288 CXXScopeSpec SS;
289 SourceLocation TemplateKWLoc;
290 UnqualifiedId Name;
291 // Read var name.
292 Token PrevTok = Tok;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000293 NoIdentIsFound = false;
Alexey Bataeva769e072013-03-22 06:34:35 +0000294
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000295 if (AllowScopeSpecifier && getLangOpts().CPlusPlus &&
296 ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000297 IsCorrect = false;
298 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000299 StopBeforeMatch);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000300 } else if (ParseUnqualifiedId(SS, false, false, false, ParsedType(),
301 TemplateKWLoc, Name)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000302 IsCorrect = false;
303 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000304 StopBeforeMatch);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000305 } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) &&
306 Tok.isNot(tok::annot_pragma_openmp_end)) {
307 IsCorrect = false;
308 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000309 StopBeforeMatch);
Alp Tokerec543272013-12-24 09:48:30 +0000310 Diag(PrevTok.getLocation(), diag::err_expected)
311 << tok::identifier
312 << SourceRange(PrevTok.getLocation(), PrevTokLocation);
Alexey Bataeva769e072013-03-22 06:34:35 +0000313 } else {
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000314 DeclarationNameInfo NameInfo = Actions.GetNameFromUnqualifiedId(Name);
Alexey Bataeva55ed262014-05-28 06:15:33 +0000315 ExprResult Res =
316 Actions.ActOnOpenMPIdExpression(getCurScope(), SS, NameInfo);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000317 if (Res.isUsable())
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000318 VarList.push_back(Res.get());
Alexey Bataeva769e072013-03-22 06:34:35 +0000319 }
320 // Consume ','.
321 if (Tok.is(tok::comma)) {
322 ConsumeToken();
323 }
Alexey Bataeva769e072013-03-22 06:34:35 +0000324 }
325
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000326 if (NoIdentIsFound) {
Alp Tokerec543272013-12-24 09:48:30 +0000327 Diag(Tok, diag::err_expected) << tok::identifier;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000328 IsCorrect = false;
329 }
330
331 // Parse ')'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000332 IsCorrect = !T.consumeClose() && IsCorrect;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000333
334 return !IsCorrect && VarList.empty();
Alexey Bataeva769e072013-03-22 06:34:35 +0000335}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000336
337/// \brief Parsing of OpenMP clauses.
338///
339/// clause:
Alexey Bataev3778b602014-07-17 07:32:53 +0000340/// if-clause | final-clause | num_threads-clause | safelen-clause |
341/// default-clause | private-clause | firstprivate-clause | shared-clause
342/// | linear-clause | aligned-clause | collapse-clause |
343/// lastprivate-clause | reduction-clause | proc_bind-clause |
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000344/// schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
Alexey Bataev6125da92014-07-21 11:26:11 +0000345/// mergeable-clause | flush-clause
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000346///
347OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
348 OpenMPClauseKind CKind, bool FirstClause) {
Craig Topper161e4db2014-05-21 06:02:52 +0000349 OMPClause *Clause = nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000350 bool ErrorFound = false;
351 // Check if clause is allowed for the given directive.
352 if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) {
Alexey Bataeva55ed262014-05-28 06:15:33 +0000353 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
354 << getOpenMPDirectiveName(DKind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000355 ErrorFound = true;
356 }
357
358 switch (CKind) {
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000359 case OMPC_if:
Alexey Bataev3778b602014-07-17 07:32:53 +0000360 case OMPC_final:
Alexey Bataev568a8332014-03-06 06:15:19 +0000361 case OMPC_num_threads:
Alexey Bataev62c87d22014-03-21 04:51:18 +0000362 case OMPC_safelen:
Alexander Musman8bd31e62014-05-27 15:12:19 +0000363 case OMPC_collapse:
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000364 // OpenMP [2.5, Restrictions]
365 // At most one if clause can appear on the directive.
Alexey Bataev568a8332014-03-06 06:15:19 +0000366 // At most one num_threads clause can appear on the directive.
Alexey Bataev62c87d22014-03-21 04:51:18 +0000367 // OpenMP [2.8.1, simd construct, Restrictions]
Alexander Musman8bd31e62014-05-27 15:12:19 +0000368 // Only one safelen clause can appear on a simd directive.
369 // Only one collapse clause can appear on a simd directive.
Alexey Bataev3778b602014-07-17 07:32:53 +0000370 // OpenMP [2.11.1, task Construct, Restrictions]
371 // At most one if clause can appear on the directive.
372 // At most one final clause can appear on the directive.
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000373 if (!FirstClause) {
Alexey Bataeva55ed262014-05-28 06:15:33 +0000374 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
375 << getOpenMPClauseName(CKind);
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000376 }
377
378 Clause = ParseOpenMPSingleExprClause(CKind);
379 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000380 case OMPC_default:
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000381 case OMPC_proc_bind:
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000382 // OpenMP [2.14.3.1, Restrictions]
383 // Only a single default clause may be specified on a parallel, task or
384 // teams directive.
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000385 // OpenMP [2.5, parallel Construct, Restrictions]
386 // At most one proc_bind clause can appear on the directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000387 if (!FirstClause) {
Alexey Bataeva55ed262014-05-28 06:15:33 +0000388 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
389 << getOpenMPClauseName(CKind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000390 }
391
392 Clause = ParseOpenMPSimpleClause(CKind);
393 break;
Alexey Bataev56dafe82014-06-20 07:16:17 +0000394 case OMPC_schedule:
395 // OpenMP [2.7.1, Restrictions, p. 3]
396 // Only one schedule clause can appear on a loop directive.
397 if (!FirstClause) {
398 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
399 << getOpenMPClauseName(CKind);
400 }
401
402 Clause = ParseOpenMPSingleExprWithArgClause(CKind);
403 break;
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000404 case OMPC_ordered:
Alexey Bataev236070f2014-06-20 11:19:47 +0000405 case OMPC_nowait:
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000406 case OMPC_untied:
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000407 case OMPC_mergeable:
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000408 // OpenMP [2.7.1, Restrictions, p. 9]
409 // Only one ordered clause can appear on a loop directive.
Alexey Bataev236070f2014-06-20 11:19:47 +0000410 // OpenMP [2.7.1, Restrictions, C/C++, p. 4]
411 // Only one nowait clause can appear on a for directive.
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000412 if (!FirstClause) {
413 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
414 << getOpenMPClauseName(CKind);
415 }
416
417 Clause = ParseOpenMPClause(CKind);
418 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000419 case OMPC_private:
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000420 case OMPC_firstprivate:
Alexander Musman1bb328c2014-06-04 13:06:39 +0000421 case OMPC_lastprivate:
Alexey Bataev758e55e2013-09-06 18:03:48 +0000422 case OMPC_shared:
Alexey Bataevc5e02582014-06-16 07:08:35 +0000423 case OMPC_reduction:
Alexander Musman8dba6642014-04-22 13:09:42 +0000424 case OMPC_linear:
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000425 case OMPC_aligned:
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000426 case OMPC_copyin:
Alexey Bataevbae9a792014-06-27 10:37:06 +0000427 case OMPC_copyprivate:
Alexey Bataev6125da92014-07-21 11:26:11 +0000428 case OMPC_flush:
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000429 Clause = ParseOpenMPVarListClause(CKind);
430 break;
431 case OMPC_unknown:
432 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000433 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000434 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000435 break;
436 case OMPC_threadprivate:
Alexey Bataeva55ed262014-05-28 06:15:33 +0000437 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
438 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000439 SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000440 break;
441 }
Craig Topper161e4db2014-05-21 06:02:52 +0000442 return ErrorFound ? nullptr : Clause;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000443}
444
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000445/// \brief Parsing of OpenMP clauses with single expressions like 'if',
Alexey Bataev3778b602014-07-17 07:32:53 +0000446/// 'final', 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams' or
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000447/// 'thread_limit'.
448///
449/// if-clause:
450/// 'if' '(' expression ')'
451///
Alexey Bataev3778b602014-07-17 07:32:53 +0000452/// final-clause:
453/// 'final' '(' expression ')'
454///
Alexey Bataev62c87d22014-03-21 04:51:18 +0000455/// num_threads-clause:
456/// 'num_threads' '(' expression ')'
457///
458/// safelen-clause:
459/// 'safelen' '(' expression ')'
460///
Alexander Musman8bd31e62014-05-27 15:12:19 +0000461/// collapse-clause:
462/// 'collapse' '(' expression ')'
463///
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000464OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
465 SourceLocation Loc = ConsumeToken();
466
467 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
468 if (T.expectAndConsume(diag::err_expected_lparen_after,
469 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000470 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000471
472 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
473 ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
474
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000475 // Parse ')'.
476 T.consumeClose();
477
478 if (Val.isInvalid())
Craig Topper161e4db2014-05-21 06:02:52 +0000479 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000480
Alexey Bataeva55ed262014-05-28 06:15:33 +0000481 return Actions.ActOnOpenMPSingleExprClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000482 Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation());
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000483}
484
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000485/// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000486///
487/// default-clause:
488/// 'default' '(' 'none' | 'shared' ')
489///
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000490/// proc_bind-clause:
491/// 'proc_bind' '(' 'master' | 'close' | 'spread' ')
492///
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000493OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
494 SourceLocation Loc = Tok.getLocation();
495 SourceLocation LOpen = ConsumeToken();
496 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000497 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000498 if (T.expectAndConsume(diag::err_expected_lparen_after,
499 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000500 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000501
Alexey Bataeva55ed262014-05-28 06:15:33 +0000502 unsigned Type = getOpenMPSimpleClauseType(
503 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000504 SourceLocation TypeLoc = Tok.getLocation();
505 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
506 Tok.isNot(tok::annot_pragma_openmp_end))
507 ConsumeAnyToken();
508
509 // Parse ')'.
510 T.consumeClose();
511
512 return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc,
513 Tok.getLocation());
514}
515
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000516/// \brief Parsing of OpenMP clauses like 'ordered'.
517///
518/// ordered-clause:
519/// 'ordered'
520///
Alexey Bataev236070f2014-06-20 11:19:47 +0000521/// nowait-clause:
522/// 'nowait'
523///
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000524/// untied-clause:
525/// 'untied'
526///
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000527/// mergeable-clause:
528/// 'mergeable'
529///
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000530OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
531 SourceLocation Loc = Tok.getLocation();
532 ConsumeAnyToken();
533
534 return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
535}
536
537
Alexey Bataev56dafe82014-06-20 07:16:17 +0000538/// \brief Parsing of OpenMP clauses with single expressions and some additional
539/// argument like 'schedule' or 'dist_schedule'.
540///
541/// schedule-clause:
542/// 'schedule' '(' kind [',' expression ] ')'
543///
544OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) {
545 SourceLocation Loc = ConsumeToken();
546 SourceLocation CommaLoc;
547 // Parse '('.
548 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
549 if (T.expectAndConsume(diag::err_expected_lparen_after,
550 getOpenMPClauseName(Kind)))
551 return nullptr;
552
553 ExprResult Val;
554 unsigned Type = getOpenMPSimpleClauseType(
555 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
556 SourceLocation KLoc = Tok.getLocation();
557 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
558 Tok.isNot(tok::annot_pragma_openmp_end))
559 ConsumeAnyToken();
560
561 if (Kind == OMPC_schedule &&
562 (Type == OMPC_SCHEDULE_static || Type == OMPC_SCHEDULE_dynamic ||
563 Type == OMPC_SCHEDULE_guided) &&
564 Tok.is(tok::comma)) {
565 CommaLoc = ConsumeAnyToken();
566 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
567 Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional);
568 if (Val.isInvalid())
569 return nullptr;
570 }
571
572 // Parse ')'.
573 T.consumeClose();
574
575 return Actions.ActOnOpenMPSingleExprWithArgClause(
576 Kind, Type, Val.get(), Loc, T.getOpenLocation(), KLoc, CommaLoc,
577 T.getCloseLocation());
578}
579
Alexey Bataevc5e02582014-06-16 07:08:35 +0000580static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec,
581 UnqualifiedId &ReductionId) {
582 SourceLocation TemplateKWLoc;
583 if (ReductionIdScopeSpec.isEmpty()) {
584 auto OOK = OO_None;
585 switch (P.getCurToken().getKind()) {
586 case tok::plus:
587 OOK = OO_Plus;
588 break;
589 case tok::minus:
590 OOK = OO_Minus;
591 break;
592 case tok::star:
593 OOK = OO_Star;
594 break;
595 case tok::amp:
596 OOK = OO_Amp;
597 break;
598 case tok::pipe:
599 OOK = OO_Pipe;
600 break;
601 case tok::caret:
602 OOK = OO_Caret;
603 break;
604 case tok::ampamp:
605 OOK = OO_AmpAmp;
606 break;
607 case tok::pipepipe:
608 OOK = OO_PipePipe;
609 break;
610 default:
611 break;
612 }
613 if (OOK != OO_None) {
614 SourceLocation OpLoc = P.ConsumeToken();
Alexey Bataev23b69422014-06-18 07:08:49 +0000615 SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()};
Alexey Bataevc5e02582014-06-16 07:08:35 +0000616 ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations);
617 return false;
618 }
619 }
620 return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false,
621 /*AllowDestructorName*/ false,
622 /*AllowConstructorName*/ false, ParsedType(),
623 TemplateKWLoc, ReductionId);
624}
625
Alexander Musman1bb328c2014-06-04 13:06:39 +0000626/// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
Alexey Bataev6125da92014-07-21 11:26:11 +0000627/// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000628///
629/// private-clause:
630/// 'private' '(' list ')'
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000631/// firstprivate-clause:
632/// 'firstprivate' '(' list ')'
Alexander Musman1bb328c2014-06-04 13:06:39 +0000633/// lastprivate-clause:
634/// 'lastprivate' '(' list ')'
Alexey Bataev758e55e2013-09-06 18:03:48 +0000635/// shared-clause:
636/// 'shared' '(' list ')'
Alexander Musman8dba6642014-04-22 13:09:42 +0000637/// linear-clause:
638/// 'linear' '(' list [ ':' linear-step ] ')'
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000639/// aligned-clause:
640/// 'aligned' '(' list [ ':' alignment ] ')'
Alexey Bataevc5e02582014-06-16 07:08:35 +0000641/// reduction-clause:
642/// 'reduction' '(' reduction-identifier ':' list ')'
Alexey Bataev6125da92014-07-21 11:26:11 +0000643/// copyprivate-clause:
644/// 'copyprivate' '(' list ')'
645/// flush-clause:
646/// 'flush' '(' list ')'
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000647///
648OMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) {
649 SourceLocation Loc = Tok.getLocation();
650 SourceLocation LOpen = ConsumeToken();
Alexander Musman8dba6642014-04-22 13:09:42 +0000651 SourceLocation ColonLoc = SourceLocation();
Alexey Bataevc5e02582014-06-16 07:08:35 +0000652 // Optional scope specifier and unqualified id for reduction identifier.
653 CXXScopeSpec ReductionIdScopeSpec;
654 UnqualifiedId ReductionId;
655 bool InvalidReductionId = false;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000656 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000657 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000658 if (T.expectAndConsume(diag::err_expected_lparen_after,
659 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000660 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000661
Alexey Bataevc5e02582014-06-16 07:08:35 +0000662 // Handle reduction-identifier for reduction clause.
663 if (Kind == OMPC_reduction) {
664 ColonProtectionRAIIObject ColonRAII(*this);
665 if (getLangOpts().CPlusPlus) {
666 ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec, ParsedType(), false);
667 }
668 InvalidReductionId =
669 ParseReductionId(*this, ReductionIdScopeSpec, ReductionId);
670 if (InvalidReductionId) {
671 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
672 StopBeforeMatch);
673 }
674 if (Tok.is(tok::colon)) {
675 ColonLoc = ConsumeToken();
676 } else {
677 Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier";
678 }
679 }
680
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000681 SmallVector<Expr *, 5> Vars;
Alexey Bataevc5e02582014-06-16 07:08:35 +0000682 bool IsComma = !InvalidReductionId;
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000683 const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
Alexander Musman8dba6642014-04-22 13:09:42 +0000684 while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000685 Tok.isNot(tok::annot_pragma_openmp_end))) {
Alexander Musman8dba6642014-04-22 13:09:42 +0000686 ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000687 // Parse variable
688 ExprResult VarExpr = ParseAssignmentExpression();
689 if (VarExpr.isUsable()) {
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000690 Vars.push_back(VarExpr.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000691 } else {
692 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000693 StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000694 }
695 // Skip ',' if any
696 IsComma = Tok.is(tok::comma);
Alexander Musman8dba6642014-04-22 13:09:42 +0000697 if (IsComma)
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000698 ConsumeToken();
Alexander Musman8dba6642014-04-22 13:09:42 +0000699 else if (Tok.isNot(tok::r_paren) &&
700 Tok.isNot(tok::annot_pragma_openmp_end) &&
701 (!MayHaveTail || Tok.isNot(tok::colon)))
Alexey Bataev6125da92014-07-21 11:26:11 +0000702 Diag(Tok, diag::err_omp_expected_punc)
703 << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush)
704 : getOpenMPClauseName(Kind))
705 << (Kind == OMPC_flush);
Alexander Musman8dba6642014-04-22 13:09:42 +0000706 }
707
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000708 // Parse ':' linear-step (or ':' alignment).
Craig Topper161e4db2014-05-21 06:02:52 +0000709 Expr *TailExpr = nullptr;
Alexander Musman8dba6642014-04-22 13:09:42 +0000710 const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon);
711 if (MustHaveTail) {
712 ColonLoc = Tok.getLocation();
713 ConsumeToken();
714 ExprResult Tail = ParseAssignmentExpression();
715 if (Tail.isUsable())
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000716 TailExpr = Tail.get();
Alexander Musman8dba6642014-04-22 13:09:42 +0000717 else
718 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
719 StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000720 }
721
722 // Parse ')'.
723 T.consumeClose();
Alexey Bataevc5e02582014-06-16 07:08:35 +0000724 if (Vars.empty() || (MustHaveTail && !TailExpr) || InvalidReductionId)
Craig Topper161e4db2014-05-21 06:02:52 +0000725 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000726
Alexey Bataevc5e02582014-06-16 07:08:35 +0000727 return Actions.ActOnOpenMPVarListClause(
728 Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(),
729 ReductionIdScopeSpec,
730 ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId)
731 : DeclarationNameInfo());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000732}
733