blob: 6c8fd640f97fb2f0cebcde2b626247a06ed839a1 [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 Bataev67a4f222014-07-23 10:25:33 +0000345/// mergeable-clause | flush-clause | read-clause | write-clause |
Alexey Bataev459dec02014-07-24 06:46:57 +0000346/// update-clause | capture-clause
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000347///
348OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
349 OpenMPClauseKind CKind, bool FirstClause) {
Craig Topper161e4db2014-05-21 06:02:52 +0000350 OMPClause *Clause = nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000351 bool ErrorFound = false;
352 // Check if clause is allowed for the given directive.
353 if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) {
Alexey Bataeva55ed262014-05-28 06:15:33 +0000354 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
355 << getOpenMPDirectiveName(DKind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000356 ErrorFound = true;
357 }
358
359 switch (CKind) {
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000360 case OMPC_if:
Alexey Bataev3778b602014-07-17 07:32:53 +0000361 case OMPC_final:
Alexey Bataev568a8332014-03-06 06:15:19 +0000362 case OMPC_num_threads:
Alexey Bataev62c87d22014-03-21 04:51:18 +0000363 case OMPC_safelen:
Alexander Musman8bd31e62014-05-27 15:12:19 +0000364 case OMPC_collapse:
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000365 // OpenMP [2.5, Restrictions]
366 // At most one if clause can appear on the directive.
Alexey Bataev568a8332014-03-06 06:15:19 +0000367 // At most one num_threads clause can appear on the directive.
Alexey Bataev62c87d22014-03-21 04:51:18 +0000368 // OpenMP [2.8.1, simd construct, Restrictions]
Alexander Musman8bd31e62014-05-27 15:12:19 +0000369 // Only one safelen clause can appear on a simd directive.
370 // Only one collapse clause can appear on a simd directive.
Alexey Bataev3778b602014-07-17 07:32:53 +0000371 // OpenMP [2.11.1, task Construct, Restrictions]
372 // At most one if clause can appear on the directive.
373 // At most one final clause can appear on the directive.
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000374 if (!FirstClause) {
Alexey Bataeva55ed262014-05-28 06:15:33 +0000375 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
376 << getOpenMPClauseName(CKind);
Alexey Bataevdea47612014-07-23 07:46:59 +0000377 ErrorFound = true;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000378 }
379
380 Clause = ParseOpenMPSingleExprClause(CKind);
381 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000382 case OMPC_default:
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000383 case OMPC_proc_bind:
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000384 // OpenMP [2.14.3.1, Restrictions]
385 // Only a single default clause may be specified on a parallel, task or
386 // teams directive.
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000387 // OpenMP [2.5, parallel Construct, Restrictions]
388 // At most one proc_bind clause can appear on the directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000389 if (!FirstClause) {
Alexey Bataeva55ed262014-05-28 06:15:33 +0000390 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
391 << getOpenMPClauseName(CKind);
Alexey Bataevdea47612014-07-23 07:46:59 +0000392 ErrorFound = true;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000393 }
394
395 Clause = ParseOpenMPSimpleClause(CKind);
396 break;
Alexey Bataev56dafe82014-06-20 07:16:17 +0000397 case OMPC_schedule:
398 // OpenMP [2.7.1, Restrictions, p. 3]
399 // Only one schedule clause can appear on a loop directive.
400 if (!FirstClause) {
401 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
402 << getOpenMPClauseName(CKind);
Alexey Bataevdea47612014-07-23 07:46:59 +0000403 ErrorFound = true;
Alexey Bataev56dafe82014-06-20 07:16:17 +0000404 }
405
406 Clause = ParseOpenMPSingleExprWithArgClause(CKind);
407 break;
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000408 case OMPC_ordered:
Alexey Bataev236070f2014-06-20 11:19:47 +0000409 case OMPC_nowait:
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000410 case OMPC_untied:
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000411 case OMPC_mergeable:
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000412 case OMPC_read:
Alexey Bataevdea47612014-07-23 07:46:59 +0000413 case OMPC_write:
Alexey Bataev67a4f222014-07-23 10:25:33 +0000414 case OMPC_update:
Alexey Bataev459dec02014-07-24 06:46:57 +0000415 case OMPC_capture:
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000416 // OpenMP [2.7.1, Restrictions, p. 9]
417 // Only one ordered clause can appear on a loop directive.
Alexey Bataev236070f2014-06-20 11:19:47 +0000418 // OpenMP [2.7.1, Restrictions, C/C++, p. 4]
419 // Only one nowait clause can appear on a for directive.
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000420 if (!FirstClause) {
421 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
422 << getOpenMPClauseName(CKind);
Alexey Bataevdea47612014-07-23 07:46:59 +0000423 ErrorFound = true;
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000424 }
425
426 Clause = ParseOpenMPClause(CKind);
427 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000428 case OMPC_private:
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000429 case OMPC_firstprivate:
Alexander Musman1bb328c2014-06-04 13:06:39 +0000430 case OMPC_lastprivate:
Alexey Bataev758e55e2013-09-06 18:03:48 +0000431 case OMPC_shared:
Alexey Bataevc5e02582014-06-16 07:08:35 +0000432 case OMPC_reduction:
Alexander Musman8dba6642014-04-22 13:09:42 +0000433 case OMPC_linear:
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000434 case OMPC_aligned:
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000435 case OMPC_copyin:
Alexey Bataevbae9a792014-06-27 10:37:06 +0000436 case OMPC_copyprivate:
Alexey Bataev6125da92014-07-21 11:26:11 +0000437 case OMPC_flush:
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000438 Clause = ParseOpenMPVarListClause(CKind);
439 break;
440 case OMPC_unknown:
441 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000442 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000443 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000444 break;
445 case OMPC_threadprivate:
Alexey Bataeva55ed262014-05-28 06:15:33 +0000446 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
447 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000448 SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000449 break;
450 }
Craig Topper161e4db2014-05-21 06:02:52 +0000451 return ErrorFound ? nullptr : Clause;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000452}
453
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000454/// \brief Parsing of OpenMP clauses with single expressions like 'if',
Alexey Bataev3778b602014-07-17 07:32:53 +0000455/// 'final', 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams' or
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000456/// 'thread_limit'.
457///
458/// if-clause:
459/// 'if' '(' expression ')'
460///
Alexey Bataev3778b602014-07-17 07:32:53 +0000461/// final-clause:
462/// 'final' '(' expression ')'
463///
Alexey Bataev62c87d22014-03-21 04:51:18 +0000464/// num_threads-clause:
465/// 'num_threads' '(' expression ')'
466///
467/// safelen-clause:
468/// 'safelen' '(' expression ')'
469///
Alexander Musman8bd31e62014-05-27 15:12:19 +0000470/// collapse-clause:
471/// 'collapse' '(' expression ')'
472///
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000473OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
474 SourceLocation Loc = ConsumeToken();
475
476 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
477 if (T.expectAndConsume(diag::err_expected_lparen_after,
478 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000479 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000480
481 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
482 ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
483
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000484 // Parse ')'.
485 T.consumeClose();
486
487 if (Val.isInvalid())
Craig Topper161e4db2014-05-21 06:02:52 +0000488 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000489
Alexey Bataeva55ed262014-05-28 06:15:33 +0000490 return Actions.ActOnOpenMPSingleExprClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000491 Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation());
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000492}
493
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000494/// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000495///
496/// default-clause:
497/// 'default' '(' 'none' | 'shared' ')
498///
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000499/// proc_bind-clause:
500/// 'proc_bind' '(' 'master' | 'close' | 'spread' ')
501///
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000502OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
503 SourceLocation Loc = Tok.getLocation();
504 SourceLocation LOpen = ConsumeToken();
505 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000506 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000507 if (T.expectAndConsume(diag::err_expected_lparen_after,
508 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000509 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000510
Alexey Bataeva55ed262014-05-28 06:15:33 +0000511 unsigned Type = getOpenMPSimpleClauseType(
512 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000513 SourceLocation TypeLoc = Tok.getLocation();
514 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
515 Tok.isNot(tok::annot_pragma_openmp_end))
516 ConsumeAnyToken();
517
518 // Parse ')'.
519 T.consumeClose();
520
521 return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc,
522 Tok.getLocation());
523}
524
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000525/// \brief Parsing of OpenMP clauses like 'ordered'.
526///
527/// ordered-clause:
528/// 'ordered'
529///
Alexey Bataev236070f2014-06-20 11:19:47 +0000530/// nowait-clause:
531/// 'nowait'
532///
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000533/// untied-clause:
534/// 'untied'
535///
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000536/// mergeable-clause:
537/// 'mergeable'
538///
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000539/// read-clause:
540/// 'read'
541///
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000542OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
543 SourceLocation Loc = Tok.getLocation();
544 ConsumeAnyToken();
545
546 return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
547}
548
549
Alexey Bataev56dafe82014-06-20 07:16:17 +0000550/// \brief Parsing of OpenMP clauses with single expressions and some additional
551/// argument like 'schedule' or 'dist_schedule'.
552///
553/// schedule-clause:
554/// 'schedule' '(' kind [',' expression ] ')'
555///
556OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) {
557 SourceLocation Loc = ConsumeToken();
558 SourceLocation CommaLoc;
559 // Parse '('.
560 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
561 if (T.expectAndConsume(diag::err_expected_lparen_after,
562 getOpenMPClauseName(Kind)))
563 return nullptr;
564
565 ExprResult Val;
566 unsigned Type = getOpenMPSimpleClauseType(
567 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
568 SourceLocation KLoc = Tok.getLocation();
569 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
570 Tok.isNot(tok::annot_pragma_openmp_end))
571 ConsumeAnyToken();
572
573 if (Kind == OMPC_schedule &&
574 (Type == OMPC_SCHEDULE_static || Type == OMPC_SCHEDULE_dynamic ||
575 Type == OMPC_SCHEDULE_guided) &&
576 Tok.is(tok::comma)) {
577 CommaLoc = ConsumeAnyToken();
578 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
579 Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional);
580 if (Val.isInvalid())
581 return nullptr;
582 }
583
584 // Parse ')'.
585 T.consumeClose();
586
587 return Actions.ActOnOpenMPSingleExprWithArgClause(
588 Kind, Type, Val.get(), Loc, T.getOpenLocation(), KLoc, CommaLoc,
589 T.getCloseLocation());
590}
591
Alexey Bataevc5e02582014-06-16 07:08:35 +0000592static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec,
593 UnqualifiedId &ReductionId) {
594 SourceLocation TemplateKWLoc;
595 if (ReductionIdScopeSpec.isEmpty()) {
596 auto OOK = OO_None;
597 switch (P.getCurToken().getKind()) {
598 case tok::plus:
599 OOK = OO_Plus;
600 break;
601 case tok::minus:
602 OOK = OO_Minus;
603 break;
604 case tok::star:
605 OOK = OO_Star;
606 break;
607 case tok::amp:
608 OOK = OO_Amp;
609 break;
610 case tok::pipe:
611 OOK = OO_Pipe;
612 break;
613 case tok::caret:
614 OOK = OO_Caret;
615 break;
616 case tok::ampamp:
617 OOK = OO_AmpAmp;
618 break;
619 case tok::pipepipe:
620 OOK = OO_PipePipe;
621 break;
622 default:
623 break;
624 }
625 if (OOK != OO_None) {
626 SourceLocation OpLoc = P.ConsumeToken();
Alexey Bataev23b69422014-06-18 07:08:49 +0000627 SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()};
Alexey Bataevc5e02582014-06-16 07:08:35 +0000628 ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations);
629 return false;
630 }
631 }
632 return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false,
633 /*AllowDestructorName*/ false,
634 /*AllowConstructorName*/ false, ParsedType(),
635 TemplateKWLoc, ReductionId);
636}
637
Alexander Musman1bb328c2014-06-04 13:06:39 +0000638/// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
Alexey Bataev6125da92014-07-21 11:26:11 +0000639/// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000640///
641/// private-clause:
642/// 'private' '(' list ')'
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000643/// firstprivate-clause:
644/// 'firstprivate' '(' list ')'
Alexander Musman1bb328c2014-06-04 13:06:39 +0000645/// lastprivate-clause:
646/// 'lastprivate' '(' list ')'
Alexey Bataev758e55e2013-09-06 18:03:48 +0000647/// shared-clause:
648/// 'shared' '(' list ')'
Alexander Musman8dba6642014-04-22 13:09:42 +0000649/// linear-clause:
650/// 'linear' '(' list [ ':' linear-step ] ')'
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000651/// aligned-clause:
652/// 'aligned' '(' list [ ':' alignment ] ')'
Alexey Bataevc5e02582014-06-16 07:08:35 +0000653/// reduction-clause:
654/// 'reduction' '(' reduction-identifier ':' list ')'
Alexey Bataev6125da92014-07-21 11:26:11 +0000655/// copyprivate-clause:
656/// 'copyprivate' '(' list ')'
657/// flush-clause:
658/// 'flush' '(' list ')'
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000659///
660OMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) {
661 SourceLocation Loc = Tok.getLocation();
662 SourceLocation LOpen = ConsumeToken();
Alexander Musman8dba6642014-04-22 13:09:42 +0000663 SourceLocation ColonLoc = SourceLocation();
Alexey Bataevc5e02582014-06-16 07:08:35 +0000664 // Optional scope specifier and unqualified id for reduction identifier.
665 CXXScopeSpec ReductionIdScopeSpec;
666 UnqualifiedId ReductionId;
667 bool InvalidReductionId = false;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000668 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000669 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000670 if (T.expectAndConsume(diag::err_expected_lparen_after,
671 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000672 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000673
Alexey Bataevc5e02582014-06-16 07:08:35 +0000674 // Handle reduction-identifier for reduction clause.
675 if (Kind == OMPC_reduction) {
676 ColonProtectionRAIIObject ColonRAII(*this);
677 if (getLangOpts().CPlusPlus) {
678 ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec, ParsedType(), false);
679 }
680 InvalidReductionId =
681 ParseReductionId(*this, ReductionIdScopeSpec, ReductionId);
682 if (InvalidReductionId) {
683 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
684 StopBeforeMatch);
685 }
686 if (Tok.is(tok::colon)) {
687 ColonLoc = ConsumeToken();
688 } else {
689 Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier";
690 }
691 }
692
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000693 SmallVector<Expr *, 5> Vars;
Alexey Bataevc5e02582014-06-16 07:08:35 +0000694 bool IsComma = !InvalidReductionId;
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000695 const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
Alexander Musman8dba6642014-04-22 13:09:42 +0000696 while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000697 Tok.isNot(tok::annot_pragma_openmp_end))) {
Alexander Musman8dba6642014-04-22 13:09:42 +0000698 ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000699 // Parse variable
700 ExprResult VarExpr = ParseAssignmentExpression();
701 if (VarExpr.isUsable()) {
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000702 Vars.push_back(VarExpr.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000703 } else {
704 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000705 StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000706 }
707 // Skip ',' if any
708 IsComma = Tok.is(tok::comma);
Alexander Musman8dba6642014-04-22 13:09:42 +0000709 if (IsComma)
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000710 ConsumeToken();
Alexander Musman8dba6642014-04-22 13:09:42 +0000711 else if (Tok.isNot(tok::r_paren) &&
712 Tok.isNot(tok::annot_pragma_openmp_end) &&
713 (!MayHaveTail || Tok.isNot(tok::colon)))
Alexey Bataev6125da92014-07-21 11:26:11 +0000714 Diag(Tok, diag::err_omp_expected_punc)
715 << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush)
716 : getOpenMPClauseName(Kind))
717 << (Kind == OMPC_flush);
Alexander Musman8dba6642014-04-22 13:09:42 +0000718 }
719
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000720 // Parse ':' linear-step (or ':' alignment).
Craig Topper161e4db2014-05-21 06:02:52 +0000721 Expr *TailExpr = nullptr;
Alexander Musman8dba6642014-04-22 13:09:42 +0000722 const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon);
723 if (MustHaveTail) {
724 ColonLoc = Tok.getLocation();
725 ConsumeToken();
726 ExprResult Tail = ParseAssignmentExpression();
727 if (Tail.isUsable())
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000728 TailExpr = Tail.get();
Alexander Musman8dba6642014-04-22 13:09:42 +0000729 else
730 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
731 StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000732 }
733
734 // Parse ')'.
735 T.consumeClose();
Alexey Bataevc5e02582014-06-16 07:08:35 +0000736 if (Vars.empty() || (MustHaveTail && !TailExpr) || InvalidReductionId)
Craig Topper161e4db2014-05-21 06:02:52 +0000737 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000738
Alexey Bataevc5e02582014-06-16 07:08:35 +0000739 return Actions.ActOnOpenMPVarListClause(
740 Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(),
741 ReductionIdScopeSpec,
742 ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId)
743 : DeclarationNameInfo());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000744}
745