blob: a08db5490fa9e4be156a10543f06d7f324ef378a [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"
Michael Wong65f367f2015-07-21 13:44:28 +000022
Alexey Bataeva769e072013-03-22 06:34:35 +000023using namespace clang;
24
25//===----------------------------------------------------------------------===//
26// OpenMP declarative directives.
27//===----------------------------------------------------------------------===//
28
Alexey Bataev4acb8592014-07-07 13:01:15 +000029static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) {
Alexander Musmanf82886e2014-09-18 05:12:34 +000030 // Array of foldings: F[i][0] F[i][1] ===> F[i][2].
31 // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd
32 // TODO: add other combined directives in topological order.
33 const OpenMPDirectiveKind F[][3] = {
Alexey Bataev6d4ed052015-07-01 06:57:41 +000034 {OMPD_unknown /*cancellation*/, OMPD_unknown /*point*/,
35 OMPD_cancellation_point},
Michael Wong65f367f2015-07-21 13:44:28 +000036 {OMPD_target, OMPD_unknown /*data*/, OMPD_target_data},
Alexey Bataev6d4ed052015-07-01 06:57:41 +000037 {OMPD_for, OMPD_simd, OMPD_for_simd},
38 {OMPD_parallel, OMPD_for, OMPD_parallel_for},
39 {OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd},
Alexey Bataev0a6ed842015-12-03 09:40:15 +000040 {OMPD_parallel, OMPD_sections, OMPD_parallel_sections},
41 {OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd}};
Alexey Bataev4acb8592014-07-07 13:01:15 +000042 auto Tok = P.getCurToken();
43 auto DKind =
44 Tok.isAnnotation()
45 ? OMPD_unknown
46 : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
Michael Wong65f367f2015-07-21 13:44:28 +000047
Alexey Bataev6d4ed052015-07-01 06:57:41 +000048 bool TokenMatched = false;
Alexander Musmanf82886e2014-09-18 05:12:34 +000049 for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +000050 if (!Tok.isAnnotation() && DKind == OMPD_unknown) {
51 TokenMatched =
52 (i == 0) &&
53 !P.getPreprocessor().getSpelling(Tok).compare("cancellation");
54 } else {
55 TokenMatched = DKind == F[i][0] && DKind != OMPD_unknown;
56 }
Michael Wong65f367f2015-07-21 13:44:28 +000057
Alexey Bataev6d4ed052015-07-01 06:57:41 +000058 if (TokenMatched) {
Alexander Musmanf82886e2014-09-18 05:12:34 +000059 Tok = P.getPreprocessor().LookAhead(0);
Michael Wong65f367f2015-07-21 13:44:28 +000060 auto TokenIsAnnotation = Tok.isAnnotation();
Alexander Musmanf82886e2014-09-18 05:12:34 +000061 auto SDKind =
Michael Wong65f367f2015-07-21 13:44:28 +000062 TokenIsAnnotation
Alexander Musmanf82886e2014-09-18 05:12:34 +000063 ? OMPD_unknown
64 : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
Michael Wong65f367f2015-07-21 13:44:28 +000065
66 if (!TokenIsAnnotation && SDKind == OMPD_unknown) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +000067 TokenMatched =
Daniel Jasper9aea8602015-07-21 16:18:51 +000068 ((i == 0) &&
69 !P.getPreprocessor().getSpelling(Tok).compare("point")) ||
70 ((i == 1) && !P.getPreprocessor().getSpelling(Tok).compare("data"));
Alexey Bataev6d4ed052015-07-01 06:57:41 +000071 } else {
72 TokenMatched = SDKind == F[i][1] && SDKind != OMPD_unknown;
73 }
Michael Wong65f367f2015-07-21 13:44:28 +000074
Alexey Bataev6d4ed052015-07-01 06:57:41 +000075 if (TokenMatched) {
Alexander Musmanf82886e2014-09-18 05:12:34 +000076 P.ConsumeToken();
77 DKind = F[i][2];
78 }
Alexey Bataev4acb8592014-07-07 13:01:15 +000079 }
80 }
81 return DKind;
82}
83
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000084/// \brief Parsing of declarative OpenMP directives.
85///
86/// threadprivate-directive:
87/// annot_pragma_openmp 'threadprivate' simple-variable-list
Alexey Bataeva769e072013-03-22 06:34:35 +000088///
89Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() {
90 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
Alexey Bataevee6507d2013-11-18 08:17:37 +000091 ParenBraceBracketBalancer BalancerRAIIObj(*this);
Alexey Bataeva769e072013-03-22 06:34:35 +000092
93 SourceLocation Loc = ConsumeToken();
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000094 SmallVector<Expr *, 5> Identifiers;
Alexey Bataev4acb8592014-07-07 13:01:15 +000095 auto DKind = ParseOpenMPDirectiveKind(*this);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000096
97 switch (DKind) {
Alexey Bataeva769e072013-03-22 06:34:35 +000098 case OMPD_threadprivate:
99 ConsumeToken();
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000100 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, true)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000101 // The last seen token is annot_pragma_openmp_end - need to check for
102 // extra tokens.
103 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
104 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000105 << getOpenMPDirectiveName(OMPD_threadprivate);
Alp Tokerd751fa72013-12-18 19:10:49 +0000106 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataeva769e072013-03-22 06:34:35 +0000107 }
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000108 // Skip the last annot_pragma_openmp_end.
Alexey Bataeva769e072013-03-22 06:34:35 +0000109 ConsumeToken();
Alexey Bataeva55ed262014-05-28 06:15:33 +0000110 return Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers);
Alexey Bataeva769e072013-03-22 06:34:35 +0000111 }
112 break;
113 case OMPD_unknown:
114 Diag(Tok, diag::err_omp_unknown_directive);
115 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000116 case OMPD_parallel:
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000117 case OMPD_simd:
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000118 case OMPD_task:
Alexey Bataev68446b72014-07-18 07:47:19 +0000119 case OMPD_taskyield:
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000120 case OMPD_barrier:
Alexey Bataev2df347a2014-07-18 10:17:07 +0000121 case OMPD_taskwait:
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000122 case OMPD_taskgroup:
Alexey Bataev6125da92014-07-21 11:26:11 +0000123 case OMPD_flush:
Alexey Bataevf29276e2014-06-18 04:14:57 +0000124 case OMPD_for:
Alexander Musmanf82886e2014-09-18 05:12:34 +0000125 case OMPD_for_simd:
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000126 case OMPD_sections:
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000127 case OMPD_section:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000128 case OMPD_single:
Alexander Musman80c22892014-07-17 08:54:58 +0000129 case OMPD_master:
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000130 case OMPD_ordered:
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000131 case OMPD_critical:
Alexey Bataev4acb8592014-07-07 13:01:15 +0000132 case OMPD_parallel_for:
Alexander Musmane4e893b2014-09-23 09:33:00 +0000133 case OMPD_parallel_for_simd:
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000134 case OMPD_parallel_sections:
Alexey Bataev0162e452014-07-22 10:10:35 +0000135 case OMPD_atomic:
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000136 case OMPD_target:
Alexey Bataev13314bf2014-10-09 04:18:56 +0000137 case OMPD_teams:
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000138 case OMPD_cancellation_point:
Alexey Bataev80909872015-07-02 11:25:17 +0000139 case OMPD_cancel:
Samuel Antao5b0688e2015-07-22 16:02:46 +0000140 case OMPD_target_data:
Alexey Bataev49f6e782015-12-01 04:18:41 +0000141 case OMPD_taskloop:
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000142 case OMPD_taskloop_simd:
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000143 case OMPD_distribute:
Alexey Bataeva769e072013-03-22 06:34:35 +0000144 Diag(Tok, diag::err_omp_unexpected_directive)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000145 << getOpenMPDirectiveName(DKind);
Alexey Bataeva769e072013-03-22 06:34:35 +0000146 break;
147 }
Alp Tokerd751fa72013-12-18 19:10:49 +0000148 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataeva769e072013-03-22 06:34:35 +0000149 return DeclGroupPtrTy();
150}
151
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000152/// \brief Parsing of declarative or executable OpenMP directives.
153///
154/// threadprivate-directive:
155/// annot_pragma_openmp 'threadprivate' simple-variable-list
156/// annot_pragma_openmp_end
157///
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000158/// executable-directive:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000159/// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' |
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000160/// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] |
161/// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' |
Alexander Musmanf82886e2014-09-18 05:12:34 +0000162/// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' |
Michael Wong65f367f2015-07-21 13:44:28 +0000163/// 'for simd' | 'parallel for simd' | 'target' | 'target data' |
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000164/// 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' {clause} |
165/// 'distribute'
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000166/// annot_pragma_openmp_end
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000167///
Alexey Bataevc4fad652016-01-13 11:18:54 +0000168StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
169 AllowedContsructsKind Allowed) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000170 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
Alexey Bataevee6507d2013-11-18 08:17:37 +0000171 ParenBraceBracketBalancer BalancerRAIIObj(*this);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000172 SmallVector<Expr *, 5> Identifiers;
173 SmallVector<OMPClause *, 5> Clauses;
Alexey Bataev4ca40ed2014-05-12 04:23:46 +0000174 SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1>
Alexey Bataeva55ed262014-05-28 06:15:33 +0000175 FirstClauses(OMPC_unknown + 1);
Alexander Musmana8e9d2e2014-06-03 10:16:47 +0000176 unsigned ScopeFlags =
Alexey Bataeva55ed262014-05-28 06:15:33 +0000177 Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000178 SourceLocation Loc = ConsumeToken(), EndLoc;
Alexey Bataev4acb8592014-07-07 13:01:15 +0000179 auto DKind = ParseOpenMPDirectiveKind(*this);
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000180 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
Alexey Bataev758e55e2013-09-06 18:03:48 +0000181 // Name of critical directive.
182 DeclarationNameInfo DirName;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000183 StmtResult Directive = StmtError();
Alexey Bataev68446b72014-07-18 07:47:19 +0000184 bool HasAssociatedStatement = true;
Alexey Bataev6125da92014-07-21 11:26:11 +0000185 bool FlushHasClause = false;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000186
187 switch (DKind) {
188 case OMPD_threadprivate:
Alexey Bataevc4fad652016-01-13 11:18:54 +0000189 if (Allowed != ACK_Any) {
190 Diag(Tok, diag::err_omp_immediate_directive)
191 << getOpenMPDirectiveName(DKind) << 0;
192 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000193 ConsumeToken();
194 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, false)) {
195 // The last seen token is annot_pragma_openmp_end - need to check for
196 // extra tokens.
197 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
198 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000199 << getOpenMPDirectiveName(OMPD_threadprivate);
Alp Tokerd751fa72013-12-18 19:10:49 +0000200 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000201 }
202 DeclGroupPtrTy Res =
Alexey Bataeva55ed262014-05-28 06:15:33 +0000203 Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000204 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
205 }
Alp Tokerd751fa72013-12-18 19:10:49 +0000206 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000207 break;
Alexey Bataev6125da92014-07-21 11:26:11 +0000208 case OMPD_flush:
209 if (PP.LookAhead(0).is(tok::l_paren)) {
210 FlushHasClause = true;
211 // Push copy of the current token back to stream to properly parse
212 // pseudo-clause OMPFlushClause.
213 PP.EnterToken(Tok);
214 }
Alexey Bataev68446b72014-07-18 07:47:19 +0000215 case OMPD_taskyield:
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000216 case OMPD_barrier:
Alexey Bataev2df347a2014-07-18 10:17:07 +0000217 case OMPD_taskwait:
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000218 case OMPD_cancellation_point:
Alexey Bataev80909872015-07-02 11:25:17 +0000219 case OMPD_cancel:
Alexey Bataevc4fad652016-01-13 11:18:54 +0000220 if (Allowed == ACK_StatementsOpenMPNonStandalone) {
Alexey Bataev68446b72014-07-18 07:47:19 +0000221 Diag(Tok, diag::err_omp_immediate_directive)
Alexey Bataeveb482352015-12-18 05:05:56 +0000222 << getOpenMPDirectiveName(DKind) << 0;
Alexey Bataev68446b72014-07-18 07:47:19 +0000223 }
224 HasAssociatedStatement = false;
Alexey Bataev6125da92014-07-21 11:26:11 +0000225 // Fall through for further analysis.
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000226 case OMPD_parallel:
Alexey Bataevf29276e2014-06-18 04:14:57 +0000227 case OMPD_simd:
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000228 case OMPD_for:
Alexander Musmanf82886e2014-09-18 05:12:34 +0000229 case OMPD_for_simd:
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000230 case OMPD_sections:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000231 case OMPD_single:
Alexey Bataev4acb8592014-07-07 13:01:15 +0000232 case OMPD_section:
Alexander Musman80c22892014-07-17 08:54:58 +0000233 case OMPD_master:
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000234 case OMPD_critical:
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000235 case OMPD_parallel_for:
Alexander Musmane4e893b2014-09-23 09:33:00 +0000236 case OMPD_parallel_for_simd:
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000237 case OMPD_parallel_sections:
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000238 case OMPD_task:
Alexey Bataev0162e452014-07-22 10:10:35 +0000239 case OMPD_ordered:
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000240 case OMPD_atomic:
Alexey Bataev13314bf2014-10-09 04:18:56 +0000241 case OMPD_target:
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000242 case OMPD_teams:
Michael Wong65f367f2015-07-21 13:44:28 +0000243 case OMPD_taskgroup:
Alexey Bataev49f6e782015-12-01 04:18:41 +0000244 case OMPD_target_data:
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000245 case OMPD_taskloop:
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000246 case OMPD_taskloop_simd:
247 case OMPD_distribute: {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000248 ConsumeToken();
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000249 // Parse directive name of the 'critical' directive if any.
250 if (DKind == OMPD_critical) {
251 BalancedDelimiterTracker T(*this, tok::l_paren,
252 tok::annot_pragma_openmp_end);
253 if (!T.consumeOpen()) {
254 if (Tok.isAnyIdentifier()) {
255 DirName =
256 DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation());
257 ConsumeAnyToken();
258 } else {
259 Diag(Tok, diag::err_omp_expected_identifier_for_critical);
260 }
261 T.consumeClose();
262 }
Alexey Bataev80909872015-07-02 11:25:17 +0000263 } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000264 CancelRegion = ParseOpenMPDirectiveKind(*this);
265 if (Tok.isNot(tok::annot_pragma_openmp_end))
266 ConsumeToken();
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000267 }
Alexey Bataev758e55e2013-09-06 18:03:48 +0000268
Alexey Bataevf29276e2014-06-18 04:14:57 +0000269 if (isOpenMPLoopDirective(DKind))
270 ScopeFlags |= Scope::OpenMPLoopDirectiveScope;
271 if (isOpenMPSimdDirective(DKind))
272 ScopeFlags |= Scope::OpenMPSimdDirectiveScope;
273 ParseScope OMPDirectiveScope(this, ScopeFlags);
Alexey Bataevbae9a792014-06-27 10:37:06 +0000274 Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000275
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000276 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
Alexey Bataev6125da92014-07-21 11:26:11 +0000277 OpenMPClauseKind CKind =
278 Tok.isAnnotation()
279 ? OMPC_unknown
280 : FlushHasClause ? OMPC_flush
281 : getOpenMPClauseKind(PP.getSpelling(Tok));
Alexey Bataevaac108a2015-06-23 04:51:00 +0000282 Actions.StartOpenMPClause(CKind);
Alexey Bataev6125da92014-07-21 11:26:11 +0000283 FlushHasClause = false;
Alexey Bataeva55ed262014-05-28 06:15:33 +0000284 OMPClause *Clause =
285 ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000286 FirstClauses[CKind].setInt(true);
287 if (Clause) {
288 FirstClauses[CKind].setPointer(Clause);
289 Clauses.push_back(Clause);
290 }
291
292 // Skip ',' if any.
293 if (Tok.is(tok::comma))
294 ConsumeToken();
Alexey Bataevaac108a2015-06-23 04:51:00 +0000295 Actions.EndOpenMPClause();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000296 }
297 // End location of the directive.
298 EndLoc = Tok.getLocation();
299 // Consume final annot_pragma_openmp_end.
300 ConsumeToken();
301
Alexey Bataeveb482352015-12-18 05:05:56 +0000302 // OpenMP [2.13.8, ordered Construct, Syntax]
303 // If the depend clause is specified, the ordered construct is a stand-alone
304 // directive.
305 if (DKind == OMPD_ordered && FirstClauses[OMPC_depend].getInt()) {
Alexey Bataevc4fad652016-01-13 11:18:54 +0000306 if (Allowed == ACK_StatementsOpenMPNonStandalone) {
Alexey Bataeveb482352015-12-18 05:05:56 +0000307 Diag(Loc, diag::err_omp_immediate_directive)
308 << getOpenMPDirectiveName(DKind) << 1
309 << getOpenMPClauseName(OMPC_depend);
310 }
311 HasAssociatedStatement = false;
312 }
313
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000314 StmtResult AssociatedStmt;
Alexey Bataev68446b72014-07-18 07:47:19 +0000315 if (HasAssociatedStatement) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000316 // The body is a block scope like in Lambdas and Blocks.
317 Sema::CompoundScopeRAII CompoundScope(Actions);
Alexey Bataevbae9a792014-06-27 10:37:06 +0000318 Actions.ActOnOpenMPRegionStart(DKind, getCurScope());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000319 Actions.ActOnStartOfCompoundStmt();
320 // Parse statement
321 AssociatedStmt = ParseStatement();
322 Actions.ActOnFinishOfCompoundStmt();
Alexey Bataeva8d4a5432015-04-02 07:48:16 +0000323 AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000324 }
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000325 Directive = Actions.ActOnOpenMPExecutableDirective(
326 DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc,
327 EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000328
329 // Exit scope.
Alexey Bataev758e55e2013-09-06 18:03:48 +0000330 Actions.EndOpenMPDSABlock(Directive.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000331 OMPDirectiveScope.Exit();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000332 break;
Alexey Bataeva55ed262014-05-28 06:15:33 +0000333 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000334 case OMPD_unknown:
335 Diag(Tok, diag::err_omp_unknown_directive);
Alp Tokerd751fa72013-12-18 19:10:49 +0000336 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000337 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000338 }
339 return Directive;
340}
341
Alexey Bataeva769e072013-03-22 06:34:35 +0000342/// \brief Parses list of simple variables for '#pragma omp threadprivate'
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000343/// directive.
Alexey Bataeva769e072013-03-22 06:34:35 +0000344///
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000345/// simple-variable-list:
346/// '(' id-expression {, id-expression} ')'
347///
348bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind,
349 SmallVectorImpl<Expr *> &VarList,
350 bool AllowScopeSpecifier) {
351 VarList.clear();
Alexey Bataeva769e072013-03-22 06:34:35 +0000352 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000353 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000354 if (T.expectAndConsume(diag::err_expected_lparen_after,
355 getOpenMPDirectiveName(Kind)))
356 return true;
357 bool IsCorrect = true;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000358 bool NoIdentIsFound = true;
Alexey Bataeva769e072013-03-22 06:34:35 +0000359
360 // Read tokens while ')' or annot_pragma_openmp_end is not found.
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000361 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000362 CXXScopeSpec SS;
363 SourceLocation TemplateKWLoc;
364 UnqualifiedId Name;
365 // Read var name.
366 Token PrevTok = Tok;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000367 NoIdentIsFound = false;
Alexey Bataeva769e072013-03-22 06:34:35 +0000368
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000369 if (AllowScopeSpecifier && getLangOpts().CPlusPlus &&
370 ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000371 IsCorrect = false;
372 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000373 StopBeforeMatch);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000374 } else if (ParseUnqualifiedId(SS, false, false, false, ParsedType(),
375 TemplateKWLoc, Name)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000376 IsCorrect = false;
377 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000378 StopBeforeMatch);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000379 } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) &&
380 Tok.isNot(tok::annot_pragma_openmp_end)) {
381 IsCorrect = false;
382 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000383 StopBeforeMatch);
Alp Tokerec543272013-12-24 09:48:30 +0000384 Diag(PrevTok.getLocation(), diag::err_expected)
385 << tok::identifier
386 << SourceRange(PrevTok.getLocation(), PrevTokLocation);
Alexey Bataeva769e072013-03-22 06:34:35 +0000387 } else {
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000388 DeclarationNameInfo NameInfo = Actions.GetNameFromUnqualifiedId(Name);
Alexey Bataeva55ed262014-05-28 06:15:33 +0000389 ExprResult Res =
390 Actions.ActOnOpenMPIdExpression(getCurScope(), SS, NameInfo);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000391 if (Res.isUsable())
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000392 VarList.push_back(Res.get());
Alexey Bataeva769e072013-03-22 06:34:35 +0000393 }
394 // Consume ','.
395 if (Tok.is(tok::comma)) {
396 ConsumeToken();
397 }
Alexey Bataeva769e072013-03-22 06:34:35 +0000398 }
399
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000400 if (NoIdentIsFound) {
Alp Tokerec543272013-12-24 09:48:30 +0000401 Diag(Tok, diag::err_expected) << tok::identifier;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000402 IsCorrect = false;
403 }
404
405 // Parse ')'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000406 IsCorrect = !T.consumeClose() && IsCorrect;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000407
408 return !IsCorrect && VarList.empty();
Alexey Bataeva769e072013-03-22 06:34:35 +0000409}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000410
411/// \brief Parsing of OpenMP clauses.
412///
413/// clause:
Alexey Bataev3778b602014-07-17 07:32:53 +0000414/// if-clause | final-clause | num_threads-clause | safelen-clause |
415/// default-clause | private-clause | firstprivate-clause | shared-clause
416/// | linear-clause | aligned-clause | collapse-clause |
417/// lastprivate-clause | reduction-clause | proc_bind-clause |
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000418/// schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
Alexey Bataev67a4f222014-07-23 10:25:33 +0000419/// mergeable-clause | flush-clause | read-clause | write-clause |
Alexey Bataev66b15b52015-08-21 11:14:16 +0000420/// update-clause | capture-clause | seq_cst-clause | device-clause |
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000421/// simdlen-clause | threads-clause | simd-clause | num_teams-clause |
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000422/// thread_limit-clause | priority-clause | grainsize-clause |
Alexey Bataev28c75412015-12-15 08:19:24 +0000423/// nogroup-clause | num_tasks-clause | hint-clause
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000424///
425OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
426 OpenMPClauseKind CKind, bool FirstClause) {
Craig Topper161e4db2014-05-21 06:02:52 +0000427 OMPClause *Clause = nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000428 bool ErrorFound = false;
429 // Check if clause is allowed for the given directive.
430 if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) {
Alexey Bataeva55ed262014-05-28 06:15:33 +0000431 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
432 << getOpenMPDirectiveName(DKind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000433 ErrorFound = true;
434 }
435
436 switch (CKind) {
Alexey Bataev3778b602014-07-17 07:32:53 +0000437 case OMPC_final:
Alexey Bataev568a8332014-03-06 06:15:19 +0000438 case OMPC_num_threads:
Alexey Bataev62c87d22014-03-21 04:51:18 +0000439 case OMPC_safelen:
Alexey Bataev66b15b52015-08-21 11:14:16 +0000440 case OMPC_simdlen:
Alexander Musman8bd31e62014-05-27 15:12:19 +0000441 case OMPC_collapse:
Alexey Bataev10e775f2015-07-30 11:36:16 +0000442 case OMPC_ordered:
Michael Wonge710d542015-08-07 16:16:36 +0000443 case OMPC_device:
Kelvin Li099bb8c2015-11-24 20:50:12 +0000444 case OMPC_num_teams:
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000445 case OMPC_thread_limit:
Alexey Bataeva0569352015-12-01 10:17:31 +0000446 case OMPC_priority:
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000447 case OMPC_grainsize:
Alexey Bataev382967a2015-12-08 12:06:20 +0000448 case OMPC_num_tasks:
Alexey Bataev28c75412015-12-15 08:19:24 +0000449 case OMPC_hint:
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000450 // OpenMP [2.5, Restrictions]
Alexey Bataev568a8332014-03-06 06:15:19 +0000451 // At most one num_threads clause can appear on the directive.
Alexey Bataev62c87d22014-03-21 04:51:18 +0000452 // OpenMP [2.8.1, simd construct, Restrictions]
Alexander Musman8bd31e62014-05-27 15:12:19 +0000453 // Only one safelen clause can appear on a simd directive.
Alexey Bataev66b15b52015-08-21 11:14:16 +0000454 // Only one simdlen clause can appear on a simd directive.
Alexander Musman8bd31e62014-05-27 15:12:19 +0000455 // Only one collapse clause can appear on a simd directive.
Michael Wonge710d542015-08-07 16:16:36 +0000456 // OpenMP [2.9.1, target data construct, Restrictions]
457 // At most one device clause can appear on the directive.
Alexey Bataev3778b602014-07-17 07:32:53 +0000458 // OpenMP [2.11.1, task Construct, Restrictions]
459 // At most one if clause can appear on the directive.
460 // At most one final clause can appear on the directive.
Kelvin Li099bb8c2015-11-24 20:50:12 +0000461 // OpenMP [teams Construct, Restrictions]
462 // At most one num_teams clause can appear on the directive.
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000463 // At most one thread_limit clause can appear on the directive.
Alexey Bataeva0569352015-12-01 10:17:31 +0000464 // OpenMP [2.9.1, task Construct, Restrictions]
465 // At most one priority clause can appear on the directive.
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000466 // OpenMP [2.9.2, taskloop Construct, Restrictions]
467 // At most one grainsize clause can appear on the directive.
Alexey Bataev382967a2015-12-08 12:06:20 +0000468 // OpenMP [2.9.2, taskloop Construct, Restrictions]
469 // At most one num_tasks clause can appear on the directive.
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000470 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000471 Diag(Tok, diag::err_omp_more_one_clause)
472 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +0000473 ErrorFound = true;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000474 }
475
Alexey Bataev10e775f2015-07-30 11:36:16 +0000476 if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren))
477 Clause = ParseOpenMPClause(CKind);
478 else
479 Clause = ParseOpenMPSingleExprClause(CKind);
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000480 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000481 case OMPC_default:
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000482 case OMPC_proc_bind:
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000483 // OpenMP [2.14.3.1, Restrictions]
484 // Only a single default clause may be specified on a parallel, task or
485 // teams directive.
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000486 // OpenMP [2.5, parallel Construct, Restrictions]
487 // At most one proc_bind clause can appear on the directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000488 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000489 Diag(Tok, diag::err_omp_more_one_clause)
490 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +0000491 ErrorFound = true;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000492 }
493
494 Clause = ParseOpenMPSimpleClause(CKind);
495 break;
Alexey Bataev56dafe82014-06-20 07:16:17 +0000496 case OMPC_schedule:
497 // OpenMP [2.7.1, Restrictions, p. 3]
498 // Only one schedule clause can appear on a loop directive.
499 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000500 Diag(Tok, diag::err_omp_more_one_clause)
501 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +0000502 ErrorFound = true;
Alexey Bataev56dafe82014-06-20 07:16:17 +0000503 }
504
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000505 case OMPC_if:
Alexey Bataev56dafe82014-06-20 07:16:17 +0000506 Clause = ParseOpenMPSingleExprWithArgClause(CKind);
507 break;
Alexey Bataev236070f2014-06-20 11:19:47 +0000508 case OMPC_nowait:
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000509 case OMPC_untied:
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000510 case OMPC_mergeable:
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000511 case OMPC_read:
Alexey Bataevdea47612014-07-23 07:46:59 +0000512 case OMPC_write:
Alexey Bataev67a4f222014-07-23 10:25:33 +0000513 case OMPC_update:
Alexey Bataev459dec02014-07-24 06:46:57 +0000514 case OMPC_capture:
Alexey Bataev82bad8b2014-07-24 08:55:34 +0000515 case OMPC_seq_cst:
Alexey Bataev346265e2015-09-25 10:37:12 +0000516 case OMPC_threads:
Alexey Bataevd14d1e62015-09-28 06:39:35 +0000517 case OMPC_simd:
Alexey Bataevb825de12015-12-07 10:51:44 +0000518 case OMPC_nogroup:
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000519 // OpenMP [2.7.1, Restrictions, p. 9]
520 // Only one ordered clause can appear on a loop directive.
Alexey Bataev236070f2014-06-20 11:19:47 +0000521 // OpenMP [2.7.1, Restrictions, C/C++, p. 4]
522 // Only one nowait clause can appear on a for directive.
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000523 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000524 Diag(Tok, diag::err_omp_more_one_clause)
525 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +0000526 ErrorFound = true;
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000527 }
528
529 Clause = ParseOpenMPClause(CKind);
530 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000531 case OMPC_private:
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000532 case OMPC_firstprivate:
Alexander Musman1bb328c2014-06-04 13:06:39 +0000533 case OMPC_lastprivate:
Alexey Bataev758e55e2013-09-06 18:03:48 +0000534 case OMPC_shared:
Alexey Bataevc5e02582014-06-16 07:08:35 +0000535 case OMPC_reduction:
Alexander Musman8dba6642014-04-22 13:09:42 +0000536 case OMPC_linear:
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000537 case OMPC_aligned:
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000538 case OMPC_copyin:
Alexey Bataevbae9a792014-06-27 10:37:06 +0000539 case OMPC_copyprivate:
Alexey Bataev6125da92014-07-21 11:26:11 +0000540 case OMPC_flush:
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000541 case OMPC_depend:
Kelvin Li0bff7af2015-11-23 05:32:03 +0000542 case OMPC_map:
Alexey Bataeveb482352015-12-18 05:05:56 +0000543 Clause = ParseOpenMPVarListClause(DKind, CKind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000544 break;
545 case OMPC_unknown:
546 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000547 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000548 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000549 break;
550 case OMPC_threadprivate:
Alexey Bataeva55ed262014-05-28 06:15:33 +0000551 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
552 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000553 SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000554 break;
555 }
Craig Topper161e4db2014-05-21 06:02:52 +0000556 return ErrorFound ? nullptr : Clause;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000557}
558
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000559/// \brief Parsing of OpenMP clauses with single expressions like 'final',
Alexey Bataeva0569352015-12-01 10:17:31 +0000560/// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams',
Alexey Bataev28c75412015-12-15 08:19:24 +0000561/// 'thread_limit', 'simdlen', 'priority', 'grainsize', 'num_tasks' or 'hint'.
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000562///
Alexey Bataev3778b602014-07-17 07:32:53 +0000563/// final-clause:
564/// 'final' '(' expression ')'
565///
Alexey Bataev62c87d22014-03-21 04:51:18 +0000566/// num_threads-clause:
567/// 'num_threads' '(' expression ')'
568///
569/// safelen-clause:
570/// 'safelen' '(' expression ')'
571///
Alexey Bataev66b15b52015-08-21 11:14:16 +0000572/// simdlen-clause:
573/// 'simdlen' '(' expression ')'
574///
Alexander Musman8bd31e62014-05-27 15:12:19 +0000575/// collapse-clause:
576/// 'collapse' '(' expression ')'
577///
Alexey Bataeva0569352015-12-01 10:17:31 +0000578/// priority-clause:
579/// 'priority' '(' expression ')'
580///
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000581/// grainsize-clause:
582/// 'grainsize' '(' expression ')'
583///
Alexey Bataev382967a2015-12-08 12:06:20 +0000584/// num_tasks-clause:
585/// 'num_tasks' '(' expression ')'
586///
Alexey Bataev28c75412015-12-15 08:19:24 +0000587/// hint-clause:
588/// 'hint' '(' expression ')'
589///
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000590OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
591 SourceLocation Loc = ConsumeToken();
592
593 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
594 if (T.expectAndConsume(diag::err_expected_lparen_after,
595 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000596 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000597
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000598 SourceLocation ELoc = Tok.getLocation();
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000599 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
600 ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000601 Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000602
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000603 // Parse ')'.
604 T.consumeClose();
605
606 if (Val.isInvalid())
Craig Topper161e4db2014-05-21 06:02:52 +0000607 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000608
Alexey Bataeva55ed262014-05-28 06:15:33 +0000609 return Actions.ActOnOpenMPSingleExprClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000610 Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation());
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000611}
612
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000613/// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000614///
615/// default-clause:
616/// 'default' '(' 'none' | 'shared' ')
617///
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000618/// proc_bind-clause:
619/// 'proc_bind' '(' 'master' | 'close' | 'spread' ')
620///
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000621OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
622 SourceLocation Loc = Tok.getLocation();
623 SourceLocation LOpen = ConsumeToken();
624 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000625 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000626 if (T.expectAndConsume(diag::err_expected_lparen_after,
627 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000628 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000629
Alexey Bataeva55ed262014-05-28 06:15:33 +0000630 unsigned Type = getOpenMPSimpleClauseType(
631 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000632 SourceLocation TypeLoc = Tok.getLocation();
633 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
634 Tok.isNot(tok::annot_pragma_openmp_end))
635 ConsumeAnyToken();
636
637 // Parse ')'.
638 T.consumeClose();
639
640 return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc,
641 Tok.getLocation());
642}
643
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000644/// \brief Parsing of OpenMP clauses like 'ordered'.
645///
646/// ordered-clause:
647/// 'ordered'
648///
Alexey Bataev236070f2014-06-20 11:19:47 +0000649/// nowait-clause:
650/// 'nowait'
651///
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000652/// untied-clause:
653/// 'untied'
654///
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000655/// mergeable-clause:
656/// 'mergeable'
657///
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000658/// read-clause:
659/// 'read'
660///
Alexey Bataev346265e2015-09-25 10:37:12 +0000661/// threads-clause:
662/// 'threads'
663///
Alexey Bataevd14d1e62015-09-28 06:39:35 +0000664/// simd-clause:
665/// 'simd'
666///
Alexey Bataevb825de12015-12-07 10:51:44 +0000667/// nogroup-clause:
668/// 'nogroup'
669///
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000670OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
671 SourceLocation Loc = Tok.getLocation();
672 ConsumeAnyToken();
673
674 return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
675}
676
677
Alexey Bataev56dafe82014-06-20 07:16:17 +0000678/// \brief Parsing of OpenMP clauses with single expressions and some additional
679/// argument like 'schedule' or 'dist_schedule'.
680///
681/// schedule-clause:
Alexey Bataev6402bca2015-12-28 07:25:51 +0000682/// 'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression ]
683/// ')'
Alexey Bataev56dafe82014-06-20 07:16:17 +0000684///
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000685/// if-clause:
686/// 'if' '(' [ directive-name-modifier ':' ] expression ')'
687///
Alexey Bataev56dafe82014-06-20 07:16:17 +0000688OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) {
689 SourceLocation Loc = ConsumeToken();
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000690 SourceLocation DelimLoc;
Alexey Bataev56dafe82014-06-20 07:16:17 +0000691 // Parse '('.
692 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
693 if (T.expectAndConsume(diag::err_expected_lparen_after,
694 getOpenMPClauseName(Kind)))
695 return nullptr;
696
697 ExprResult Val;
Alexey Bataev6402bca2015-12-28 07:25:51 +0000698 SmallVector<unsigned, 4> Arg;
699 SmallVector<SourceLocation, 4> KLoc;
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000700 if (Kind == OMPC_schedule) {
Alexey Bataev6402bca2015-12-28 07:25:51 +0000701 enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements };
702 Arg.resize(NumberOfElements);
703 KLoc.resize(NumberOfElements);
704 Arg[Modifier1] = OMPC_SCHEDULE_MODIFIER_unknown;
705 Arg[Modifier2] = OMPC_SCHEDULE_MODIFIER_unknown;
706 Arg[ScheduleKind] = OMPC_SCHEDULE_unknown;
707 auto KindModifier = getOpenMPSimpleClauseType(
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000708 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
Alexey Bataev6402bca2015-12-28 07:25:51 +0000709 if (KindModifier > OMPC_SCHEDULE_unknown) {
710 // Parse 'modifier'
711 Arg[Modifier1] = KindModifier;
712 KLoc[Modifier1] = Tok.getLocation();
713 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
714 Tok.isNot(tok::annot_pragma_openmp_end))
715 ConsumeAnyToken();
716 if (Tok.is(tok::comma)) {
717 // Parse ',' 'modifier'
718 ConsumeAnyToken();
719 KindModifier = getOpenMPSimpleClauseType(
720 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
721 Arg[Modifier2] = KindModifier > OMPC_SCHEDULE_unknown
722 ? KindModifier
Aaron Ballmanad8a1042015-12-28 15:52:46 +0000723 : (unsigned)OMPC_SCHEDULE_unknown;
Alexey Bataev6402bca2015-12-28 07:25:51 +0000724 KLoc[Modifier2] = Tok.getLocation();
725 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
726 Tok.isNot(tok::annot_pragma_openmp_end))
727 ConsumeAnyToken();
728 }
729 // Parse ':'
730 if (Tok.is(tok::colon))
731 ConsumeAnyToken();
732 else
733 Diag(Tok, diag::warn_pragma_expected_colon) << "schedule modifier";
734 KindModifier = getOpenMPSimpleClauseType(
735 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
736 }
737 Arg[ScheduleKind] = KindModifier;
738 KLoc[ScheduleKind] = Tok.getLocation();
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000739 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
740 Tok.isNot(tok::annot_pragma_openmp_end))
741 ConsumeAnyToken();
Alexey Bataev6402bca2015-12-28 07:25:51 +0000742 if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static ||
743 Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic ||
744 Arg[ScheduleKind] == OMPC_SCHEDULE_guided) &&
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000745 Tok.is(tok::comma))
746 DelimLoc = ConsumeAnyToken();
747 } else {
748 assert(Kind == OMPC_if);
Alexey Bataev6402bca2015-12-28 07:25:51 +0000749 KLoc.push_back(Tok.getLocation());
750 Arg.push_back(ParseOpenMPDirectiveKind(*this));
751 if (Arg.back() != OMPD_unknown) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000752 ConsumeToken();
753 if (Tok.is(tok::colon))
754 DelimLoc = ConsumeToken();
755 else
756 Diag(Tok, diag::warn_pragma_expected_colon)
757 << "directive name modifier";
758 }
759 }
Alexey Bataev56dafe82014-06-20 07:16:17 +0000760
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000761 bool NeedAnExpression =
762 (Kind == OMPC_schedule && DelimLoc.isValid()) || Kind == OMPC_if;
763 if (NeedAnExpression) {
764 SourceLocation ELoc = Tok.getLocation();
Alexey Bataev56dafe82014-06-20 07:16:17 +0000765 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
766 Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional);
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000767 Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +0000768 }
769
770 // Parse ')'.
771 T.consumeClose();
772
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000773 if (NeedAnExpression && Val.isInvalid())
774 return nullptr;
775
Alexey Bataev56dafe82014-06-20 07:16:17 +0000776 return Actions.ActOnOpenMPSingleExprWithArgClause(
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000777 Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc,
Alexey Bataev56dafe82014-06-20 07:16:17 +0000778 T.getCloseLocation());
779}
780
Alexey Bataevc5e02582014-06-16 07:08:35 +0000781static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec,
782 UnqualifiedId &ReductionId) {
783 SourceLocation TemplateKWLoc;
784 if (ReductionIdScopeSpec.isEmpty()) {
785 auto OOK = OO_None;
786 switch (P.getCurToken().getKind()) {
787 case tok::plus:
788 OOK = OO_Plus;
789 break;
790 case tok::minus:
791 OOK = OO_Minus;
792 break;
793 case tok::star:
794 OOK = OO_Star;
795 break;
796 case tok::amp:
797 OOK = OO_Amp;
798 break;
799 case tok::pipe:
800 OOK = OO_Pipe;
801 break;
802 case tok::caret:
803 OOK = OO_Caret;
804 break;
805 case tok::ampamp:
806 OOK = OO_AmpAmp;
807 break;
808 case tok::pipepipe:
809 OOK = OO_PipePipe;
810 break;
811 default:
812 break;
813 }
814 if (OOK != OO_None) {
815 SourceLocation OpLoc = P.ConsumeToken();
Alexey Bataev23b69422014-06-18 07:08:49 +0000816 SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()};
Alexey Bataevc5e02582014-06-16 07:08:35 +0000817 ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations);
818 return false;
819 }
820 }
821 return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false,
822 /*AllowDestructorName*/ false,
823 /*AllowConstructorName*/ false, ParsedType(),
824 TemplateKWLoc, ReductionId);
825}
826
Alexander Musman1bb328c2014-06-04 13:06:39 +0000827/// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
Alexey Bataev6125da92014-07-21 11:26:11 +0000828/// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000829///
830/// private-clause:
831/// 'private' '(' list ')'
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000832/// firstprivate-clause:
833/// 'firstprivate' '(' list ')'
Alexander Musman1bb328c2014-06-04 13:06:39 +0000834/// lastprivate-clause:
835/// 'lastprivate' '(' list ')'
Alexey Bataev758e55e2013-09-06 18:03:48 +0000836/// shared-clause:
837/// 'shared' '(' list ')'
Alexander Musman8dba6642014-04-22 13:09:42 +0000838/// linear-clause:
Alexey Bataev182227b2015-08-20 10:54:39 +0000839/// 'linear' '(' linear-list [ ':' linear-step ] ')'
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000840/// aligned-clause:
841/// 'aligned' '(' list [ ':' alignment ] ')'
Alexey Bataevc5e02582014-06-16 07:08:35 +0000842/// reduction-clause:
843/// 'reduction' '(' reduction-identifier ':' list ')'
Alexey Bataev6125da92014-07-21 11:26:11 +0000844/// copyprivate-clause:
845/// 'copyprivate' '(' list ')'
846/// flush-clause:
847/// 'flush' '(' list ')'
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000848/// depend-clause:
Alexey Bataeveb482352015-12-18 05:05:56 +0000849/// 'depend' '(' in | out | inout : list | source ')'
Kelvin Li0bff7af2015-11-23 05:32:03 +0000850/// map-clause:
851/// 'map' '(' [ [ always , ]
852/// to | from | tofrom | alloc | release | delete ':' ] list ')';
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000853///
Alexey Bataev182227b2015-08-20 10:54:39 +0000854/// For 'linear' clause linear-list may have the following forms:
855/// list
856/// modifier(list)
857/// where modifier is 'val' (C) or 'ref', 'val' or 'uval'(C++).
Alexey Bataeveb482352015-12-18 05:05:56 +0000858OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
859 OpenMPClauseKind Kind) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000860 SourceLocation Loc = Tok.getLocation();
861 SourceLocation LOpen = ConsumeToken();
Alexander Musman8dba6642014-04-22 13:09:42 +0000862 SourceLocation ColonLoc = SourceLocation();
Alexey Bataevc5e02582014-06-16 07:08:35 +0000863 // Optional scope specifier and unqualified id for reduction identifier.
864 CXXScopeSpec ReductionIdScopeSpec;
865 UnqualifiedId ReductionId;
866 bool InvalidReductionId = false;
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000867 OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
Alexey Bataev182227b2015-08-20 10:54:39 +0000868 // OpenMP 4.1 [2.15.3.7, linear Clause]
869 // If no modifier is specified it is assumed to be val.
870 OpenMPLinearClauseKind LinearModifier = OMPC_LINEAR_val;
Kelvin Li0bff7af2015-11-23 05:32:03 +0000871 OpenMPMapClauseKind MapType = OMPC_MAP_unknown;
872 OpenMPMapClauseKind MapTypeModifier = OMPC_MAP_unknown;
873 bool MapTypeModifierSpecified = false;
874 bool UnexpectedId = false;
875 SourceLocation DepLinMapLoc;
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000876
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000877 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000878 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000879 if (T.expectAndConsume(diag::err_expected_lparen_after,
880 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000881 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000882
Alexey Bataev182227b2015-08-20 10:54:39 +0000883 bool NeedRParenForLinear = false;
884 BalancedDelimiterTracker LinearT(*this, tok::l_paren,
885 tok::annot_pragma_openmp_end);
Alexey Bataevc5e02582014-06-16 07:08:35 +0000886 // Handle reduction-identifier for reduction clause.
887 if (Kind == OMPC_reduction) {
888 ColonProtectionRAIIObject ColonRAII(*this);
889 if (getLangOpts().CPlusPlus) {
890 ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec, ParsedType(), false);
891 }
892 InvalidReductionId =
893 ParseReductionId(*this, ReductionIdScopeSpec, ReductionId);
894 if (InvalidReductionId) {
895 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
896 StopBeforeMatch);
897 }
898 if (Tok.is(tok::colon)) {
899 ColonLoc = ConsumeToken();
900 } else {
901 Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier";
902 }
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000903 } else if (Kind == OMPC_depend) {
904 // Handle dependency type for depend clause.
905 ColonProtectionRAIIObject ColonRAII(*this);
906 DepKind = static_cast<OpenMPDependClauseKind>(getOpenMPSimpleClauseType(
907 Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
Kelvin Li0bff7af2015-11-23 05:32:03 +0000908 DepLinMapLoc = Tok.getLocation();
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000909
910 if (DepKind == OMPC_DEPEND_unknown) {
911 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
912 StopBeforeMatch);
913 } else {
914 ConsumeToken();
Alexey Bataeveb482352015-12-18 05:05:56 +0000915 // Special processing for depend(source) clause.
916 if (DKind == OMPD_ordered && DepKind == OMPC_DEPEND_source) {
917 // Parse ')'.
918 T.consumeClose();
919 return Actions.ActOnOpenMPVarListClause(
920 Kind, llvm::None, /*TailExpr=*/nullptr, Loc, LOpen,
921 /*ColonLoc=*/SourceLocation(), Tok.getLocation(),
922 ReductionIdScopeSpec, DeclarationNameInfo(), DepKind,
923 LinearModifier, MapTypeModifier, MapType, DepLinMapLoc);
924 }
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000925 }
926 if (Tok.is(tok::colon)) {
927 ColonLoc = ConsumeToken();
928 } else {
Alexey Bataeveb482352015-12-18 05:05:56 +0000929 Diag(Tok, DKind == OMPD_ordered ? diag::warn_pragma_expected_colon_r_paren
930 : diag::warn_pragma_expected_colon)
931 << "dependency type";
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000932 }
Alexey Bataev182227b2015-08-20 10:54:39 +0000933 } else if (Kind == OMPC_linear) {
934 // Try to parse modifier if any.
935 if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) {
Alexey Bataev182227b2015-08-20 10:54:39 +0000936 LinearModifier = static_cast<OpenMPLinearClauseKind>(
Alexey Bataev1185e192015-08-20 12:15:57 +0000937 getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)));
Kelvin Li0bff7af2015-11-23 05:32:03 +0000938 DepLinMapLoc = ConsumeToken();
Alexey Bataev182227b2015-08-20 10:54:39 +0000939 LinearT.consumeOpen();
940 NeedRParenForLinear = true;
941 }
Kelvin Li0bff7af2015-11-23 05:32:03 +0000942 } else if (Kind == OMPC_map) {
943 // Handle map type for map clause.
944 ColonProtectionRAIIObject ColonRAII(*this);
945
946 // the first identifier may be a list item, a map-type or
947 // a map-type-modifier
948 MapType = static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType(
949 Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
950 DepLinMapLoc = Tok.getLocation();
951 bool ColonExpected = false;
952
953 if (Tok.is(tok::identifier)) {
954 if (PP.LookAhead(0).is(tok::colon)) {
955 MapType = static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType(
956 Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
957 if (MapType == OMPC_MAP_unknown) {
958 Diag(Tok, diag::err_omp_unknown_map_type);
959 } else if (MapType == OMPC_MAP_always) {
960 Diag(Tok, diag::err_omp_map_type_missing);
961 }
962 ConsumeToken();
963 } else if (PP.LookAhead(0).is(tok::comma)) {
964 if (PP.LookAhead(1).is(tok::identifier) &&
965 PP.LookAhead(2).is(tok::colon)) {
966 MapTypeModifier =
967 static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType(
968 Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
969 if (MapTypeModifier != OMPC_MAP_always) {
970 Diag(Tok, diag::err_omp_unknown_map_type_modifier);
971 MapTypeModifier = OMPC_MAP_unknown;
972 } else {
973 MapTypeModifierSpecified = true;
974 }
975
976 ConsumeToken();
977 ConsumeToken();
978
979 MapType = static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType(
980 Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
981 if (MapType == OMPC_MAP_unknown || MapType == OMPC_MAP_always) {
982 Diag(Tok, diag::err_omp_unknown_map_type);
983 }
984 ConsumeToken();
985 } else {
986 MapType = OMPC_MAP_tofrom;
987 }
988 } else {
989 MapType = OMPC_MAP_tofrom;
990 }
991 } else {
992 UnexpectedId = true;
993 }
994
995 if (Tok.is(tok::colon)) {
996 ColonLoc = ConsumeToken();
997 } else if (ColonExpected) {
998 Diag(Tok, diag::warn_pragma_expected_colon) << "map type";
999 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00001000 }
1001
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001002 SmallVector<Expr *, 5> Vars;
Kelvin Li0bff7af2015-11-23 05:32:03 +00001003 bool IsComma =
1004 ((Kind != OMPC_reduction) && (Kind != OMPC_depend) &&
1005 (Kind != OMPC_map)) ||
1006 ((Kind == OMPC_reduction) && !InvalidReductionId) ||
1007 ((Kind == OMPC_map) && (UnexpectedId || MapType != OMPC_MAP_unknown) &&
1008 (!MapTypeModifierSpecified ||
1009 (MapTypeModifierSpecified && MapTypeModifier == OMPC_MAP_always))) ||
1010 ((Kind == OMPC_depend) && DepKind != OMPC_DEPEND_unknown);
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001011 const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
Alexander Musman8dba6642014-04-22 13:09:42 +00001012 while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001013 Tok.isNot(tok::annot_pragma_openmp_end))) {
Alexander Musman8dba6642014-04-22 13:09:42 +00001014 ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001015 // Parse variable
Kaelyn Takata15867822014-11-21 18:48:04 +00001016 ExprResult VarExpr =
1017 Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001018 if (VarExpr.isUsable()) {
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001019 Vars.push_back(VarExpr.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001020 } else {
1021 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +00001022 StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001023 }
1024 // Skip ',' if any
1025 IsComma = Tok.is(tok::comma);
Alexander Musman8dba6642014-04-22 13:09:42 +00001026 if (IsComma)
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001027 ConsumeToken();
Alexander Musman8dba6642014-04-22 13:09:42 +00001028 else if (Tok.isNot(tok::r_paren) &&
1029 Tok.isNot(tok::annot_pragma_openmp_end) &&
1030 (!MayHaveTail || Tok.isNot(tok::colon)))
Alexey Bataev6125da92014-07-21 11:26:11 +00001031 Diag(Tok, diag::err_omp_expected_punc)
1032 << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush)
1033 : getOpenMPClauseName(Kind))
1034 << (Kind == OMPC_flush);
Alexander Musman8dba6642014-04-22 13:09:42 +00001035 }
1036
Alexey Bataev182227b2015-08-20 10:54:39 +00001037 // Parse ')' for linear clause with modifier.
1038 if (NeedRParenForLinear)
1039 LinearT.consumeClose();
1040
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001041 // Parse ':' linear-step (or ':' alignment).
Craig Topper161e4db2014-05-21 06:02:52 +00001042 Expr *TailExpr = nullptr;
Alexander Musman8dba6642014-04-22 13:09:42 +00001043 const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon);
1044 if (MustHaveTail) {
1045 ColonLoc = Tok.getLocation();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001046 SourceLocation ELoc = ConsumeToken();
1047 ExprResult Tail = ParseAssignmentExpression();
1048 Tail = Actions.ActOnFinishFullExpr(Tail.get(), ELoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001049 if (Tail.isUsable())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001050 TailExpr = Tail.get();
Alexander Musman8dba6642014-04-22 13:09:42 +00001051 else
1052 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
1053 StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001054 }
1055
1056 // Parse ')'.
1057 T.consumeClose();
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001058 if ((Kind == OMPC_depend && DepKind != OMPC_DEPEND_unknown && Vars.empty()) ||
1059 (Kind != OMPC_depend && Vars.empty()) || (MustHaveTail && !TailExpr) ||
Kelvin Li0bff7af2015-11-23 05:32:03 +00001060 (Kind == OMPC_map && MapType == OMPC_MAP_unknown) ||
1061 InvalidReductionId) {
Craig Topper161e4db2014-05-21 06:02:52 +00001062 return nullptr;
Kelvin Li0bff7af2015-11-23 05:32:03 +00001063 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001064
Alexey Bataevc5e02582014-06-16 07:08:35 +00001065 return Actions.ActOnOpenMPVarListClause(
1066 Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(),
1067 ReductionIdScopeSpec,
1068 ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId)
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001069 : DeclarationNameInfo(),
Kelvin Li0bff7af2015-11-23 05:32:03 +00001070 DepKind, LinearModifier, MapTypeModifier, MapType, DepLinMapLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001071}
1072