blob: a5bc4a4494201312af595569cccfb2901722e6cf [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 Bataevdea47612014-07-23 07:46:59 +0000345/// mergeable-clause | flush-clause | read-clause | write-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 Bataevdea47612014-07-23 07:46:59 +0000376 ErrorFound = true;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000377 }
378
379 Clause = ParseOpenMPSingleExprClause(CKind);
380 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000381 case OMPC_default:
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000382 case OMPC_proc_bind:
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000383 // OpenMP [2.14.3.1, Restrictions]
384 // Only a single default clause may be specified on a parallel, task or
385 // teams directive.
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000386 // OpenMP [2.5, parallel Construct, Restrictions]
387 // At most one proc_bind clause can appear on the directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000388 if (!FirstClause) {
Alexey Bataeva55ed262014-05-28 06:15:33 +0000389 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
390 << getOpenMPClauseName(CKind);
Alexey Bataevdea47612014-07-23 07:46:59 +0000391 ErrorFound = true;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000392 }
393
394 Clause = ParseOpenMPSimpleClause(CKind);
395 break;
Alexey Bataev56dafe82014-06-20 07:16:17 +0000396 case OMPC_schedule:
397 // OpenMP [2.7.1, Restrictions, p. 3]
398 // Only one schedule clause can appear on a loop directive.
399 if (!FirstClause) {
400 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
401 << getOpenMPClauseName(CKind);
Alexey Bataevdea47612014-07-23 07:46:59 +0000402 ErrorFound = true;
Alexey Bataev56dafe82014-06-20 07:16:17 +0000403 }
404
405 Clause = ParseOpenMPSingleExprWithArgClause(CKind);
406 break;
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000407 case OMPC_ordered:
Alexey Bataev236070f2014-06-20 11:19:47 +0000408 case OMPC_nowait:
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000409 case OMPC_untied:
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000410 case OMPC_mergeable:
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000411 case OMPC_read:
Alexey Bataevdea47612014-07-23 07:46:59 +0000412 case OMPC_write:
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000413 // OpenMP [2.7.1, Restrictions, p. 9]
414 // Only one ordered clause can appear on a loop directive.
Alexey Bataev236070f2014-06-20 11:19:47 +0000415 // OpenMP [2.7.1, Restrictions, C/C++, p. 4]
416 // Only one nowait clause can appear on a for directive.
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000417 if (!FirstClause) {
418 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
419 << getOpenMPClauseName(CKind);
Alexey Bataevdea47612014-07-23 07:46:59 +0000420 ErrorFound = true;
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000421 }
422
423 Clause = ParseOpenMPClause(CKind);
424 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000425 case OMPC_private:
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000426 case OMPC_firstprivate:
Alexander Musman1bb328c2014-06-04 13:06:39 +0000427 case OMPC_lastprivate:
Alexey Bataev758e55e2013-09-06 18:03:48 +0000428 case OMPC_shared:
Alexey Bataevc5e02582014-06-16 07:08:35 +0000429 case OMPC_reduction:
Alexander Musman8dba6642014-04-22 13:09:42 +0000430 case OMPC_linear:
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000431 case OMPC_aligned:
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000432 case OMPC_copyin:
Alexey Bataevbae9a792014-06-27 10:37:06 +0000433 case OMPC_copyprivate:
Alexey Bataev6125da92014-07-21 11:26:11 +0000434 case OMPC_flush:
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000435 Clause = ParseOpenMPVarListClause(CKind);
436 break;
437 case OMPC_unknown:
438 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000439 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000440 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000441 break;
442 case OMPC_threadprivate:
Alexey Bataeva55ed262014-05-28 06:15:33 +0000443 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
444 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000445 SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000446 break;
447 }
Craig Topper161e4db2014-05-21 06:02:52 +0000448 return ErrorFound ? nullptr : Clause;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000449}
450
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000451/// \brief Parsing of OpenMP clauses with single expressions like 'if',
Alexey Bataev3778b602014-07-17 07:32:53 +0000452/// 'final', 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams' or
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000453/// 'thread_limit'.
454///
455/// if-clause:
456/// 'if' '(' expression ')'
457///
Alexey Bataev3778b602014-07-17 07:32:53 +0000458/// final-clause:
459/// 'final' '(' expression ')'
460///
Alexey Bataev62c87d22014-03-21 04:51:18 +0000461/// num_threads-clause:
462/// 'num_threads' '(' expression ')'
463///
464/// safelen-clause:
465/// 'safelen' '(' expression ')'
466///
Alexander Musman8bd31e62014-05-27 15:12:19 +0000467/// collapse-clause:
468/// 'collapse' '(' expression ')'
469///
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000470OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
471 SourceLocation Loc = ConsumeToken();
472
473 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
474 if (T.expectAndConsume(diag::err_expected_lparen_after,
475 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000476 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000477
478 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
479 ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
480
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000481 // Parse ')'.
482 T.consumeClose();
483
484 if (Val.isInvalid())
Craig Topper161e4db2014-05-21 06:02:52 +0000485 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000486
Alexey Bataeva55ed262014-05-28 06:15:33 +0000487 return Actions.ActOnOpenMPSingleExprClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000488 Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation());
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000489}
490
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000491/// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000492///
493/// default-clause:
494/// 'default' '(' 'none' | 'shared' ')
495///
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000496/// proc_bind-clause:
497/// 'proc_bind' '(' 'master' | 'close' | 'spread' ')
498///
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000499OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
500 SourceLocation Loc = Tok.getLocation();
501 SourceLocation LOpen = ConsumeToken();
502 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000503 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000504 if (T.expectAndConsume(diag::err_expected_lparen_after,
505 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000506 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000507
Alexey Bataeva55ed262014-05-28 06:15:33 +0000508 unsigned Type = getOpenMPSimpleClauseType(
509 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000510 SourceLocation TypeLoc = Tok.getLocation();
511 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
512 Tok.isNot(tok::annot_pragma_openmp_end))
513 ConsumeAnyToken();
514
515 // Parse ')'.
516 T.consumeClose();
517
518 return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc,
519 Tok.getLocation());
520}
521
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000522/// \brief Parsing of OpenMP clauses like 'ordered'.
523///
524/// ordered-clause:
525/// 'ordered'
526///
Alexey Bataev236070f2014-06-20 11:19:47 +0000527/// nowait-clause:
528/// 'nowait'
529///
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000530/// untied-clause:
531/// 'untied'
532///
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000533/// mergeable-clause:
534/// 'mergeable'
535///
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000536/// read-clause:
537/// 'read'
538///
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000539OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
540 SourceLocation Loc = Tok.getLocation();
541 ConsumeAnyToken();
542
543 return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
544}
545
546
Alexey Bataev56dafe82014-06-20 07:16:17 +0000547/// \brief Parsing of OpenMP clauses with single expressions and some additional
548/// argument like 'schedule' or 'dist_schedule'.
549///
550/// schedule-clause:
551/// 'schedule' '(' kind [',' expression ] ')'
552///
553OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) {
554 SourceLocation Loc = ConsumeToken();
555 SourceLocation CommaLoc;
556 // Parse '('.
557 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
558 if (T.expectAndConsume(diag::err_expected_lparen_after,
559 getOpenMPClauseName(Kind)))
560 return nullptr;
561
562 ExprResult Val;
563 unsigned Type = getOpenMPSimpleClauseType(
564 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
565 SourceLocation KLoc = Tok.getLocation();
566 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
567 Tok.isNot(tok::annot_pragma_openmp_end))
568 ConsumeAnyToken();
569
570 if (Kind == OMPC_schedule &&
571 (Type == OMPC_SCHEDULE_static || Type == OMPC_SCHEDULE_dynamic ||
572 Type == OMPC_SCHEDULE_guided) &&
573 Tok.is(tok::comma)) {
574 CommaLoc = ConsumeAnyToken();
575 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
576 Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional);
577 if (Val.isInvalid())
578 return nullptr;
579 }
580
581 // Parse ')'.
582 T.consumeClose();
583
584 return Actions.ActOnOpenMPSingleExprWithArgClause(
585 Kind, Type, Val.get(), Loc, T.getOpenLocation(), KLoc, CommaLoc,
586 T.getCloseLocation());
587}
588
Alexey Bataevc5e02582014-06-16 07:08:35 +0000589static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec,
590 UnqualifiedId &ReductionId) {
591 SourceLocation TemplateKWLoc;
592 if (ReductionIdScopeSpec.isEmpty()) {
593 auto OOK = OO_None;
594 switch (P.getCurToken().getKind()) {
595 case tok::plus:
596 OOK = OO_Plus;
597 break;
598 case tok::minus:
599 OOK = OO_Minus;
600 break;
601 case tok::star:
602 OOK = OO_Star;
603 break;
604 case tok::amp:
605 OOK = OO_Amp;
606 break;
607 case tok::pipe:
608 OOK = OO_Pipe;
609 break;
610 case tok::caret:
611 OOK = OO_Caret;
612 break;
613 case tok::ampamp:
614 OOK = OO_AmpAmp;
615 break;
616 case tok::pipepipe:
617 OOK = OO_PipePipe;
618 break;
619 default:
620 break;
621 }
622 if (OOK != OO_None) {
623 SourceLocation OpLoc = P.ConsumeToken();
Alexey Bataev23b69422014-06-18 07:08:49 +0000624 SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()};
Alexey Bataevc5e02582014-06-16 07:08:35 +0000625 ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations);
626 return false;
627 }
628 }
629 return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false,
630 /*AllowDestructorName*/ false,
631 /*AllowConstructorName*/ false, ParsedType(),
632 TemplateKWLoc, ReductionId);
633}
634
Alexander Musman1bb328c2014-06-04 13:06:39 +0000635/// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
Alexey Bataev6125da92014-07-21 11:26:11 +0000636/// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000637///
638/// private-clause:
639/// 'private' '(' list ')'
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000640/// firstprivate-clause:
641/// 'firstprivate' '(' list ')'
Alexander Musman1bb328c2014-06-04 13:06:39 +0000642/// lastprivate-clause:
643/// 'lastprivate' '(' list ')'
Alexey Bataev758e55e2013-09-06 18:03:48 +0000644/// shared-clause:
645/// 'shared' '(' list ')'
Alexander Musman8dba6642014-04-22 13:09:42 +0000646/// linear-clause:
647/// 'linear' '(' list [ ':' linear-step ] ')'
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000648/// aligned-clause:
649/// 'aligned' '(' list [ ':' alignment ] ')'
Alexey Bataevc5e02582014-06-16 07:08:35 +0000650/// reduction-clause:
651/// 'reduction' '(' reduction-identifier ':' list ')'
Alexey Bataev6125da92014-07-21 11:26:11 +0000652/// copyprivate-clause:
653/// 'copyprivate' '(' list ')'
654/// flush-clause:
655/// 'flush' '(' list ')'
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000656///
657OMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) {
658 SourceLocation Loc = Tok.getLocation();
659 SourceLocation LOpen = ConsumeToken();
Alexander Musman8dba6642014-04-22 13:09:42 +0000660 SourceLocation ColonLoc = SourceLocation();
Alexey Bataevc5e02582014-06-16 07:08:35 +0000661 // Optional scope specifier and unqualified id for reduction identifier.
662 CXXScopeSpec ReductionIdScopeSpec;
663 UnqualifiedId ReductionId;
664 bool InvalidReductionId = false;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000665 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000666 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000667 if (T.expectAndConsume(diag::err_expected_lparen_after,
668 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000669 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000670
Alexey Bataevc5e02582014-06-16 07:08:35 +0000671 // Handle reduction-identifier for reduction clause.
672 if (Kind == OMPC_reduction) {
673 ColonProtectionRAIIObject ColonRAII(*this);
674 if (getLangOpts().CPlusPlus) {
675 ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec, ParsedType(), false);
676 }
677 InvalidReductionId =
678 ParseReductionId(*this, ReductionIdScopeSpec, ReductionId);
679 if (InvalidReductionId) {
680 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
681 StopBeforeMatch);
682 }
683 if (Tok.is(tok::colon)) {
684 ColonLoc = ConsumeToken();
685 } else {
686 Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier";
687 }
688 }
689
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000690 SmallVector<Expr *, 5> Vars;
Alexey Bataevc5e02582014-06-16 07:08:35 +0000691 bool IsComma = !InvalidReductionId;
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000692 const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
Alexander Musman8dba6642014-04-22 13:09:42 +0000693 while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000694 Tok.isNot(tok::annot_pragma_openmp_end))) {
Alexander Musman8dba6642014-04-22 13:09:42 +0000695 ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000696 // Parse variable
697 ExprResult VarExpr = ParseAssignmentExpression();
698 if (VarExpr.isUsable()) {
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000699 Vars.push_back(VarExpr.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000700 } else {
701 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000702 StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000703 }
704 // Skip ',' if any
705 IsComma = Tok.is(tok::comma);
Alexander Musman8dba6642014-04-22 13:09:42 +0000706 if (IsComma)
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000707 ConsumeToken();
Alexander Musman8dba6642014-04-22 13:09:42 +0000708 else if (Tok.isNot(tok::r_paren) &&
709 Tok.isNot(tok::annot_pragma_openmp_end) &&
710 (!MayHaveTail || Tok.isNot(tok::colon)))
Alexey Bataev6125da92014-07-21 11:26:11 +0000711 Diag(Tok, diag::err_omp_expected_punc)
712 << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush)
713 : getOpenMPClauseName(Kind))
714 << (Kind == OMPC_flush);
Alexander Musman8dba6642014-04-22 13:09:42 +0000715 }
716
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000717 // Parse ':' linear-step (or ':' alignment).
Craig Topper161e4db2014-05-21 06:02:52 +0000718 Expr *TailExpr = nullptr;
Alexander Musman8dba6642014-04-22 13:09:42 +0000719 const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon);
720 if (MustHaveTail) {
721 ColonLoc = Tok.getLocation();
722 ConsumeToken();
723 ExprResult Tail = ParseAssignmentExpression();
724 if (Tail.isUsable())
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000725 TailExpr = Tail.get();
Alexander Musman8dba6642014-04-22 13:09:42 +0000726 else
727 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
728 StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000729 }
730
731 // Parse ')'.
732 T.consumeClose();
Alexey Bataevc5e02582014-06-16 07:08:35 +0000733 if (Vars.empty() || (MustHaveTail && !TailExpr) || InvalidReductionId)
Craig Topper161e4db2014-05-21 06:02:52 +0000734 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000735
Alexey Bataevc5e02582014-06-16 07:08:35 +0000736 return Actions.ActOnOpenMPVarListClause(
737 Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(),
738 ReductionIdScopeSpec,
739 ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId)
740 : DeclarationNameInfo());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000741}
742