blob: 4044b112c82bfc198f7191954c22bbe4b6d7fc75 [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 Bataev82bad8b2014-07-24 08:55:34 +0000346/// update-clause | capture-clause | seq_cst-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 Bataev82bad8b2014-07-24 08:55:34 +0000416 case OMPC_seq_cst:
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000417 // OpenMP [2.7.1, Restrictions, p. 9]
418 // Only one ordered clause can appear on a loop directive.
Alexey Bataev236070f2014-06-20 11:19:47 +0000419 // OpenMP [2.7.1, Restrictions, C/C++, p. 4]
420 // Only one nowait clause can appear on a for directive.
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000421 if (!FirstClause) {
422 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
423 << getOpenMPClauseName(CKind);
Alexey Bataevdea47612014-07-23 07:46:59 +0000424 ErrorFound = true;
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000425 }
426
427 Clause = ParseOpenMPClause(CKind);
428 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000429 case OMPC_private:
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000430 case OMPC_firstprivate:
Alexander Musman1bb328c2014-06-04 13:06:39 +0000431 case OMPC_lastprivate:
Alexey Bataev758e55e2013-09-06 18:03:48 +0000432 case OMPC_shared:
Alexey Bataevc5e02582014-06-16 07:08:35 +0000433 case OMPC_reduction:
Alexander Musman8dba6642014-04-22 13:09:42 +0000434 case OMPC_linear:
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000435 case OMPC_aligned:
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000436 case OMPC_copyin:
Alexey Bataevbae9a792014-06-27 10:37:06 +0000437 case OMPC_copyprivate:
Alexey Bataev6125da92014-07-21 11:26:11 +0000438 case OMPC_flush:
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000439 Clause = ParseOpenMPVarListClause(CKind);
440 break;
441 case OMPC_unknown:
442 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000443 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000444 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000445 break;
446 case OMPC_threadprivate:
Alexey Bataeva55ed262014-05-28 06:15:33 +0000447 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
448 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000449 SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000450 break;
451 }
Craig Topper161e4db2014-05-21 06:02:52 +0000452 return ErrorFound ? nullptr : Clause;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000453}
454
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000455/// \brief Parsing of OpenMP clauses with single expressions like 'if',
Alexey Bataev3778b602014-07-17 07:32:53 +0000456/// 'final', 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams' or
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000457/// 'thread_limit'.
458///
459/// if-clause:
460/// 'if' '(' expression ')'
461///
Alexey Bataev3778b602014-07-17 07:32:53 +0000462/// final-clause:
463/// 'final' '(' expression ')'
464///
Alexey Bataev62c87d22014-03-21 04:51:18 +0000465/// num_threads-clause:
466/// 'num_threads' '(' expression ')'
467///
468/// safelen-clause:
469/// 'safelen' '(' expression ')'
470///
Alexander Musman8bd31e62014-05-27 15:12:19 +0000471/// collapse-clause:
472/// 'collapse' '(' expression ')'
473///
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000474OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
475 SourceLocation Loc = ConsumeToken();
476
477 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
478 if (T.expectAndConsume(diag::err_expected_lparen_after,
479 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000480 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000481
482 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
483 ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
484
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000485 // Parse ')'.
486 T.consumeClose();
487
488 if (Val.isInvalid())
Craig Topper161e4db2014-05-21 06:02:52 +0000489 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000490
Alexey Bataeva55ed262014-05-28 06:15:33 +0000491 return Actions.ActOnOpenMPSingleExprClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000492 Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation());
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000493}
494
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000495/// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000496///
497/// default-clause:
498/// 'default' '(' 'none' | 'shared' ')
499///
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000500/// proc_bind-clause:
501/// 'proc_bind' '(' 'master' | 'close' | 'spread' ')
502///
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000503OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
504 SourceLocation Loc = Tok.getLocation();
505 SourceLocation LOpen = ConsumeToken();
506 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000507 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000508 if (T.expectAndConsume(diag::err_expected_lparen_after,
509 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000510 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000511
Alexey Bataeva55ed262014-05-28 06:15:33 +0000512 unsigned Type = getOpenMPSimpleClauseType(
513 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000514 SourceLocation TypeLoc = Tok.getLocation();
515 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
516 Tok.isNot(tok::annot_pragma_openmp_end))
517 ConsumeAnyToken();
518
519 // Parse ')'.
520 T.consumeClose();
521
522 return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc,
523 Tok.getLocation());
524}
525
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000526/// \brief Parsing of OpenMP clauses like 'ordered'.
527///
528/// ordered-clause:
529/// 'ordered'
530///
Alexey Bataev236070f2014-06-20 11:19:47 +0000531/// nowait-clause:
532/// 'nowait'
533///
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000534/// untied-clause:
535/// 'untied'
536///
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000537/// mergeable-clause:
538/// 'mergeable'
539///
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000540/// read-clause:
541/// 'read'
542///
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000543OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
544 SourceLocation Loc = Tok.getLocation();
545 ConsumeAnyToken();
546
547 return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
548}
549
550
Alexey Bataev56dafe82014-06-20 07:16:17 +0000551/// \brief Parsing of OpenMP clauses with single expressions and some additional
552/// argument like 'schedule' or 'dist_schedule'.
553///
554/// schedule-clause:
555/// 'schedule' '(' kind [',' expression ] ')'
556///
557OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) {
558 SourceLocation Loc = ConsumeToken();
559 SourceLocation CommaLoc;
560 // Parse '('.
561 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
562 if (T.expectAndConsume(diag::err_expected_lparen_after,
563 getOpenMPClauseName(Kind)))
564 return nullptr;
565
566 ExprResult Val;
567 unsigned Type = getOpenMPSimpleClauseType(
568 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
569 SourceLocation KLoc = Tok.getLocation();
570 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
571 Tok.isNot(tok::annot_pragma_openmp_end))
572 ConsumeAnyToken();
573
574 if (Kind == OMPC_schedule &&
575 (Type == OMPC_SCHEDULE_static || Type == OMPC_SCHEDULE_dynamic ||
576 Type == OMPC_SCHEDULE_guided) &&
577 Tok.is(tok::comma)) {
578 CommaLoc = ConsumeAnyToken();
579 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
580 Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional);
581 if (Val.isInvalid())
582 return nullptr;
583 }
584
585 // Parse ')'.
586 T.consumeClose();
587
588 return Actions.ActOnOpenMPSingleExprWithArgClause(
589 Kind, Type, Val.get(), Loc, T.getOpenLocation(), KLoc, CommaLoc,
590 T.getCloseLocation());
591}
592
Alexey Bataevc5e02582014-06-16 07:08:35 +0000593static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec,
594 UnqualifiedId &ReductionId) {
595 SourceLocation TemplateKWLoc;
596 if (ReductionIdScopeSpec.isEmpty()) {
597 auto OOK = OO_None;
598 switch (P.getCurToken().getKind()) {
599 case tok::plus:
600 OOK = OO_Plus;
601 break;
602 case tok::minus:
603 OOK = OO_Minus;
604 break;
605 case tok::star:
606 OOK = OO_Star;
607 break;
608 case tok::amp:
609 OOK = OO_Amp;
610 break;
611 case tok::pipe:
612 OOK = OO_Pipe;
613 break;
614 case tok::caret:
615 OOK = OO_Caret;
616 break;
617 case tok::ampamp:
618 OOK = OO_AmpAmp;
619 break;
620 case tok::pipepipe:
621 OOK = OO_PipePipe;
622 break;
623 default:
624 break;
625 }
626 if (OOK != OO_None) {
627 SourceLocation OpLoc = P.ConsumeToken();
Alexey Bataev23b69422014-06-18 07:08:49 +0000628 SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()};
Alexey Bataevc5e02582014-06-16 07:08:35 +0000629 ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations);
630 return false;
631 }
632 }
633 return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false,
634 /*AllowDestructorName*/ false,
635 /*AllowConstructorName*/ false, ParsedType(),
636 TemplateKWLoc, ReductionId);
637}
638
Alexander Musman1bb328c2014-06-04 13:06:39 +0000639/// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
Alexey Bataev6125da92014-07-21 11:26:11 +0000640/// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000641///
642/// private-clause:
643/// 'private' '(' list ')'
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000644/// firstprivate-clause:
645/// 'firstprivate' '(' list ')'
Alexander Musman1bb328c2014-06-04 13:06:39 +0000646/// lastprivate-clause:
647/// 'lastprivate' '(' list ')'
Alexey Bataev758e55e2013-09-06 18:03:48 +0000648/// shared-clause:
649/// 'shared' '(' list ')'
Alexander Musman8dba6642014-04-22 13:09:42 +0000650/// linear-clause:
651/// 'linear' '(' list [ ':' linear-step ] ')'
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000652/// aligned-clause:
653/// 'aligned' '(' list [ ':' alignment ] ')'
Alexey Bataevc5e02582014-06-16 07:08:35 +0000654/// reduction-clause:
655/// 'reduction' '(' reduction-identifier ':' list ')'
Alexey Bataev6125da92014-07-21 11:26:11 +0000656/// copyprivate-clause:
657/// 'copyprivate' '(' list ')'
658/// flush-clause:
659/// 'flush' '(' list ')'
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000660///
661OMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) {
662 SourceLocation Loc = Tok.getLocation();
663 SourceLocation LOpen = ConsumeToken();
Alexander Musman8dba6642014-04-22 13:09:42 +0000664 SourceLocation ColonLoc = SourceLocation();
Alexey Bataevc5e02582014-06-16 07:08:35 +0000665 // Optional scope specifier and unqualified id for reduction identifier.
666 CXXScopeSpec ReductionIdScopeSpec;
667 UnqualifiedId ReductionId;
668 bool InvalidReductionId = false;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000669 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000670 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000671 if (T.expectAndConsume(diag::err_expected_lparen_after,
672 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000673 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000674
Alexey Bataevc5e02582014-06-16 07:08:35 +0000675 // Handle reduction-identifier for reduction clause.
676 if (Kind == OMPC_reduction) {
677 ColonProtectionRAIIObject ColonRAII(*this);
678 if (getLangOpts().CPlusPlus) {
679 ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec, ParsedType(), false);
680 }
681 InvalidReductionId =
682 ParseReductionId(*this, ReductionIdScopeSpec, ReductionId);
683 if (InvalidReductionId) {
684 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
685 StopBeforeMatch);
686 }
687 if (Tok.is(tok::colon)) {
688 ColonLoc = ConsumeToken();
689 } else {
690 Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier";
691 }
692 }
693
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000694 SmallVector<Expr *, 5> Vars;
Alexey Bataevc5e02582014-06-16 07:08:35 +0000695 bool IsComma = !InvalidReductionId;
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000696 const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
Alexander Musman8dba6642014-04-22 13:09:42 +0000697 while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000698 Tok.isNot(tok::annot_pragma_openmp_end))) {
Alexander Musman8dba6642014-04-22 13:09:42 +0000699 ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000700 // Parse variable
701 ExprResult VarExpr = ParseAssignmentExpression();
702 if (VarExpr.isUsable()) {
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000703 Vars.push_back(VarExpr.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000704 } else {
705 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000706 StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000707 }
708 // Skip ',' if any
709 IsComma = Tok.is(tok::comma);
Alexander Musman8dba6642014-04-22 13:09:42 +0000710 if (IsComma)
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000711 ConsumeToken();
Alexander Musman8dba6642014-04-22 13:09:42 +0000712 else if (Tok.isNot(tok::r_paren) &&
713 Tok.isNot(tok::annot_pragma_openmp_end) &&
714 (!MayHaveTail || Tok.isNot(tok::colon)))
Alexey Bataev6125da92014-07-21 11:26:11 +0000715 Diag(Tok, diag::err_omp_expected_punc)
716 << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush)
717 : getOpenMPClauseName(Kind))
718 << (Kind == OMPC_flush);
Alexander Musman8dba6642014-04-22 13:09:42 +0000719 }
720
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000721 // Parse ':' linear-step (or ':' alignment).
Craig Topper161e4db2014-05-21 06:02:52 +0000722 Expr *TailExpr = nullptr;
Alexander Musman8dba6642014-04-22 13:09:42 +0000723 const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon);
724 if (MustHaveTail) {
725 ColonLoc = Tok.getLocation();
726 ConsumeToken();
727 ExprResult Tail = ParseAssignmentExpression();
728 if (Tail.isUsable())
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000729 TailExpr = Tail.get();
Alexander Musman8dba6642014-04-22 13:09:42 +0000730 else
731 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
732 StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000733 }
734
735 // Parse ')'.
736 T.consumeClose();
Alexey Bataevc5e02582014-06-16 07:08:35 +0000737 if (Vars.empty() || (MustHaveTail && !TailExpr) || InvalidReductionId)
Craig Topper161e4db2014-05-21 06:02:52 +0000738 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000739
Alexey Bataevc5e02582014-06-16 07:08:35 +0000740 return Actions.ActOnOpenMPVarListClause(
741 Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(),
742 ReductionIdScopeSpec,
743 ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId)
744 : DeclarationNameInfo());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000745}
746