Bug Summary

File:clang/lib/Parse/ParseOpenMP.cpp
Warning:line 2494, column 7
Value stored to 'HasImplicitClause' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ParseOpenMP.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -relaxed-aliasing -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/build-llvm/tools/clang/lib/Parse -resource-dir /usr/lib/llvm-13/lib/clang/13.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/build-llvm/tools/clang/lib/Parse -I /build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse -I /build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/include -I /build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/build-llvm/include -I /build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/llvm/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-13/lib/clang/13.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/build-llvm/tools/clang/lib/Parse -fdebug-prefix-map=/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c=. -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -o /tmp/scan-build-2021-03-08-182450-10039-1 -x c++ /build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp
1//===--- ParseOpenMP.cpp - OpenMP directives parsing ----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// This file implements parsing of all OpenMP directives and clauses.
10///
11//===----------------------------------------------------------------------===//
12
13#include "clang/AST/ASTContext.h"
14#include "clang/AST/OpenMPClause.h"
15#include "clang/AST/StmtOpenMP.h"
16#include "clang/Basic/OpenMPKinds.h"
17#include "clang/Basic/TargetInfo.h"
18#include "clang/Basic/TokenKinds.h"
19#include "clang/Parse/ParseDiagnostic.h"
20#include "clang/Parse/Parser.h"
21#include "clang/Parse/RAIIObjectsForParser.h"
22#include "clang/Sema/Scope.h"
23#include "llvm/ADT/PointerIntPair.h"
24#include "llvm/ADT/StringSwitch.h"
25#include "llvm/ADT/UniqueVector.h"
26#include "llvm/Frontend/OpenMP/OMPContext.h"
27
28using namespace clang;
29using namespace llvm::omp;
30
31//===----------------------------------------------------------------------===//
32// OpenMP declarative directives.
33//===----------------------------------------------------------------------===//
34
35namespace {
36enum OpenMPDirectiveKindEx {
37 OMPD_cancellation = llvm::omp::Directive_enumSize + 1,
38 OMPD_data,
39 OMPD_declare,
40 OMPD_end,
41 OMPD_end_declare,
42 OMPD_enter,
43 OMPD_exit,
44 OMPD_point,
45 OMPD_reduction,
46 OMPD_target_enter,
47 OMPD_target_exit,
48 OMPD_update,
49 OMPD_distribute_parallel,
50 OMPD_teams_distribute_parallel,
51 OMPD_target_teams_distribute_parallel,
52 OMPD_mapper,
53 OMPD_variant,
54 OMPD_begin,
55 OMPD_begin_declare,
56};
57
58// Helper to unify the enum class OpenMPDirectiveKind with its extension
59// the OpenMPDirectiveKindEx enum which allows to use them together as if they
60// are unsigned values.
61struct OpenMPDirectiveKindExWrapper {
62 OpenMPDirectiveKindExWrapper(unsigned Value) : Value(Value) {}
63 OpenMPDirectiveKindExWrapper(OpenMPDirectiveKind DK) : Value(unsigned(DK)) {}
64 bool operator==(OpenMPDirectiveKindExWrapper V) const {
65 return Value == V.Value;
66 }
67 bool operator!=(OpenMPDirectiveKindExWrapper V) const {
68 return Value != V.Value;
69 }
70 bool operator==(OpenMPDirectiveKind V) const { return Value == unsigned(V); }
71 bool operator!=(OpenMPDirectiveKind V) const { return Value != unsigned(V); }
72 bool operator<(OpenMPDirectiveKind V) const { return Value < unsigned(V); }
73 operator unsigned() const { return Value; }
74 operator OpenMPDirectiveKind() const { return OpenMPDirectiveKind(Value); }
75 unsigned Value;
76};
77
78class DeclDirectiveListParserHelper final {
79 SmallVector<Expr *, 4> Identifiers;
80 Parser *P;
81 OpenMPDirectiveKind Kind;
82
83public:
84 DeclDirectiveListParserHelper(Parser *P, OpenMPDirectiveKind Kind)
85 : P(P), Kind(Kind) {}
86 void operator()(CXXScopeSpec &SS, DeclarationNameInfo NameInfo) {
87 ExprResult Res = P->getActions().ActOnOpenMPIdExpression(
88 P->getCurScope(), SS, NameInfo, Kind);
89 if (Res.isUsable())
90 Identifiers.push_back(Res.get());
91 }
92 llvm::ArrayRef<Expr *> getIdentifiers() const { return Identifiers; }
93};
94} // namespace
95
96// Map token string to extended OMP token kind that are
97// OpenMPDirectiveKind + OpenMPDirectiveKindEx.
98static unsigned getOpenMPDirectiveKindEx(StringRef S) {
99 OpenMPDirectiveKindExWrapper DKind = getOpenMPDirectiveKind(S);
100 if (DKind != OMPD_unknown)
101 return DKind;
102
103 return llvm::StringSwitch<OpenMPDirectiveKindExWrapper>(S)
104 .Case("cancellation", OMPD_cancellation)
105 .Case("data", OMPD_data)
106 .Case("declare", OMPD_declare)
107 .Case("end", OMPD_end)
108 .Case("enter", OMPD_enter)
109 .Case("exit", OMPD_exit)
110 .Case("point", OMPD_point)
111 .Case("reduction", OMPD_reduction)
112 .Case("update", OMPD_update)
113 .Case("mapper", OMPD_mapper)
114 .Case("variant", OMPD_variant)
115 .Case("begin", OMPD_begin)
116 .Default(OMPD_unknown);
117}
118
119static OpenMPDirectiveKindExWrapper parseOpenMPDirectiveKind(Parser &P) {
120 // Array of foldings: F[i][0] F[i][1] ===> F[i][2].
121 // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd
122 // TODO: add other combined directives in topological order.
123 static const OpenMPDirectiveKindExWrapper F[][3] = {
124 {OMPD_begin, OMPD_declare, OMPD_begin_declare},
125 {OMPD_begin, OMPD_assumes, OMPD_begin_assumes},
126 {OMPD_end, OMPD_declare, OMPD_end_declare},
127 {OMPD_end, OMPD_assumes, OMPD_end_assumes},
128 {OMPD_cancellation, OMPD_point, OMPD_cancellation_point},
129 {OMPD_declare, OMPD_reduction, OMPD_declare_reduction},
130 {OMPD_declare, OMPD_mapper, OMPD_declare_mapper},
131 {OMPD_declare, OMPD_simd, OMPD_declare_simd},
132 {OMPD_declare, OMPD_target, OMPD_declare_target},
133 {OMPD_declare, OMPD_variant, OMPD_declare_variant},
134 {OMPD_begin_declare, OMPD_variant, OMPD_begin_declare_variant},
135 {OMPD_end_declare, OMPD_variant, OMPD_end_declare_variant},
136 {OMPD_distribute, OMPD_parallel, OMPD_distribute_parallel},
137 {OMPD_distribute_parallel, OMPD_for, OMPD_distribute_parallel_for},
138 {OMPD_distribute_parallel_for, OMPD_simd,
139 OMPD_distribute_parallel_for_simd},
140 {OMPD_distribute, OMPD_simd, OMPD_distribute_simd},
141 {OMPD_end_declare, OMPD_target, OMPD_end_declare_target},
142 {OMPD_target, OMPD_data, OMPD_target_data},
143 {OMPD_target, OMPD_enter, OMPD_target_enter},
144 {OMPD_target, OMPD_exit, OMPD_target_exit},
145 {OMPD_target, OMPD_update, OMPD_target_update},
146 {OMPD_target_enter, OMPD_data, OMPD_target_enter_data},
147 {OMPD_target_exit, OMPD_data, OMPD_target_exit_data},
148 {OMPD_for, OMPD_simd, OMPD_for_simd},
149 {OMPD_parallel, OMPD_for, OMPD_parallel_for},
150 {OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd},
151 {OMPD_parallel, OMPD_sections, OMPD_parallel_sections},
152 {OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd},
153 {OMPD_target, OMPD_parallel, OMPD_target_parallel},
154 {OMPD_target, OMPD_simd, OMPD_target_simd},
155 {OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for},
156 {OMPD_target_parallel_for, OMPD_simd, OMPD_target_parallel_for_simd},
157 {OMPD_teams, OMPD_distribute, OMPD_teams_distribute},
158 {OMPD_teams_distribute, OMPD_simd, OMPD_teams_distribute_simd},
159 {OMPD_teams_distribute, OMPD_parallel, OMPD_teams_distribute_parallel},
160 {OMPD_teams_distribute_parallel, OMPD_for,
161 OMPD_teams_distribute_parallel_for},
162 {OMPD_teams_distribute_parallel_for, OMPD_simd,
163 OMPD_teams_distribute_parallel_for_simd},
164 {OMPD_target, OMPD_teams, OMPD_target_teams},
165 {OMPD_target_teams, OMPD_distribute, OMPD_target_teams_distribute},
166 {OMPD_target_teams_distribute, OMPD_parallel,
167 OMPD_target_teams_distribute_parallel},
168 {OMPD_target_teams_distribute, OMPD_simd,
169 OMPD_target_teams_distribute_simd},
170 {OMPD_target_teams_distribute_parallel, OMPD_for,
171 OMPD_target_teams_distribute_parallel_for},
172 {OMPD_target_teams_distribute_parallel_for, OMPD_simd,
173 OMPD_target_teams_distribute_parallel_for_simd},
174 {OMPD_master, OMPD_taskloop, OMPD_master_taskloop},
175 {OMPD_master_taskloop, OMPD_simd, OMPD_master_taskloop_simd},
176 {OMPD_parallel, OMPD_master, OMPD_parallel_master},
177 {OMPD_parallel_master, OMPD_taskloop, OMPD_parallel_master_taskloop},
178 {OMPD_parallel_master_taskloop, OMPD_simd,
179 OMPD_parallel_master_taskloop_simd}};
180 enum { CancellationPoint = 0, DeclareReduction = 1, TargetData = 2 };
181 Token Tok = P.getCurToken();
182 OpenMPDirectiveKindExWrapper DKind =
183 Tok.isAnnotation()
184 ? static_cast<unsigned>(OMPD_unknown)
185 : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok));
186 if (DKind == OMPD_unknown)
187 return OMPD_unknown;
188
189 for (unsigned I = 0; I < llvm::array_lengthof(F); ++I) {
190 if (DKind != F[I][0])
191 continue;
192
193 Tok = P.getPreprocessor().LookAhead(0);
194 OpenMPDirectiveKindExWrapper SDKind =
195 Tok.isAnnotation()
196 ? static_cast<unsigned>(OMPD_unknown)
197 : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok));
198 if (SDKind == OMPD_unknown)
199 continue;
200
201 if (SDKind == F[I][1]) {
202 P.ConsumeToken();
203 DKind = F[I][2];
204 }
205 }
206 return unsigned(DKind) < llvm::omp::Directive_enumSize
207 ? static_cast<OpenMPDirectiveKind>(DKind)
208 : OMPD_unknown;
209}
210
211static DeclarationName parseOpenMPReductionId(Parser &P) {
212 Token Tok = P.getCurToken();
213 Sema &Actions = P.getActions();
214 OverloadedOperatorKind OOK = OO_None;
215 // Allow to use 'operator' keyword for C++ operators
216 bool WithOperator = false;
217 if (Tok.is(tok::kw_operator)) {
218 P.ConsumeToken();
219 Tok = P.getCurToken();
220 WithOperator = true;
221 }
222 switch (Tok.getKind()) {
223 case tok::plus: // '+'
224 OOK = OO_Plus;
225 break;
226 case tok::minus: // '-'
227 OOK = OO_Minus;
228 break;
229 case tok::star: // '*'
230 OOK = OO_Star;
231 break;
232 case tok::amp: // '&'
233 OOK = OO_Amp;
234 break;
235 case tok::pipe: // '|'
236 OOK = OO_Pipe;
237 break;
238 case tok::caret: // '^'
239 OOK = OO_Caret;
240 break;
241 case tok::ampamp: // '&&'
242 OOK = OO_AmpAmp;
243 break;
244 case tok::pipepipe: // '||'
245 OOK = OO_PipePipe;
246 break;
247 case tok::identifier: // identifier
248 if (!WithOperator)
249 break;
250 LLVM_FALLTHROUGH[[gnu::fallthrough]];
251 default:
252 P.Diag(Tok.getLocation(), diag::err_omp_expected_reduction_identifier);
253 P.SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
254 Parser::StopBeforeMatch);
255 return DeclarationName();
256 }
257 P.ConsumeToken();
258 auto &DeclNames = Actions.getASTContext().DeclarationNames;
259 return OOK == OO_None ? DeclNames.getIdentifier(Tok.getIdentifierInfo())
260 : DeclNames.getCXXOperatorName(OOK);
261}
262
263/// Parse 'omp declare reduction' construct.
264///
265/// declare-reduction-directive:
266/// annot_pragma_openmp 'declare' 'reduction'
267/// '(' <reduction_id> ':' <type> {',' <type>} ':' <expression> ')'
268/// ['initializer' '(' ('omp_priv' '=' <expression>)|<function_call> ')']
269/// annot_pragma_openmp_end
270/// <reduction_id> is either a base language identifier or one of the following
271/// operators: '+', '-', '*', '&', '|', '^', '&&' and '||'.
272///
273Parser::DeclGroupPtrTy
274Parser::ParseOpenMPDeclareReductionDirective(AccessSpecifier AS) {
275 // Parse '('.
276 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
277 if (T.expectAndConsume(
278 diag::err_expected_lparen_after,
279 getOpenMPDirectiveName(OMPD_declare_reduction).data())) {
280 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
281 return DeclGroupPtrTy();
282 }
283
284 DeclarationName Name = parseOpenMPReductionId(*this);
285 if (Name.isEmpty() && Tok.is(tok::annot_pragma_openmp_end))
286 return DeclGroupPtrTy();
287
288 // Consume ':'.
289 bool IsCorrect = !ExpectAndConsume(tok::colon);
290
291 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
292 return DeclGroupPtrTy();
293
294 IsCorrect = IsCorrect && !Name.isEmpty();
295
296 if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end)) {
297 Diag(Tok.getLocation(), diag::err_expected_type);
298 IsCorrect = false;
299 }
300
301 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
302 return DeclGroupPtrTy();
303
304 SmallVector<std::pair<QualType, SourceLocation>, 8> ReductionTypes;
305 // Parse list of types until ':' token.
306 do {
307 ColonProtectionRAIIObject ColonRAII(*this);
308 SourceRange Range;
309 TypeResult TR = ParseTypeName(&Range, DeclaratorContext::Prototype, AS);
310 if (TR.isUsable()) {
311 QualType ReductionType =
312 Actions.ActOnOpenMPDeclareReductionType(Range.getBegin(), TR);
313 if (!ReductionType.isNull()) {
314 ReductionTypes.push_back(
315 std::make_pair(ReductionType, Range.getBegin()));
316 }
317 } else {
318 SkipUntil(tok::comma, tok::colon, tok::annot_pragma_openmp_end,
319 StopBeforeMatch);
320 }
321
322 if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end))
323 break;
324
325 // Consume ','.
326 if (ExpectAndConsume(tok::comma)) {
327 IsCorrect = false;
328 if (Tok.is(tok::annot_pragma_openmp_end)) {
329 Diag(Tok.getLocation(), diag::err_expected_type);
330 return DeclGroupPtrTy();
331 }
332 }
333 } while (Tok.isNot(tok::annot_pragma_openmp_end));
334
335 if (ReductionTypes.empty()) {
336 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
337 return DeclGroupPtrTy();
338 }
339
340 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
341 return DeclGroupPtrTy();
342
343 // Consume ':'.
344 if (ExpectAndConsume(tok::colon))
345 IsCorrect = false;
346
347 if (Tok.is(tok::annot_pragma_openmp_end)) {
348 Diag(Tok.getLocation(), diag::err_expected_expression);
349 return DeclGroupPtrTy();
350 }
351
352 DeclGroupPtrTy DRD = Actions.ActOnOpenMPDeclareReductionDirectiveStart(
353 getCurScope(), Actions.getCurLexicalContext(), Name, ReductionTypes, AS);
354
355 // Parse <combiner> expression and then parse initializer if any for each
356 // correct type.
357 unsigned I = 0, E = ReductionTypes.size();
358 for (Decl *D : DRD.get()) {
359 TentativeParsingAction TPA(*this);
360 ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope |
361 Scope::CompoundStmtScope |
362 Scope::OpenMPDirectiveScope);
363 // Parse <combiner> expression.
364 Actions.ActOnOpenMPDeclareReductionCombinerStart(getCurScope(), D);
365 ExprResult CombinerResult = Actions.ActOnFinishFullExpr(
366 ParseExpression().get(), D->getLocation(), /*DiscardedValue*/ false);
367 Actions.ActOnOpenMPDeclareReductionCombinerEnd(D, CombinerResult.get());
368
369 if (CombinerResult.isInvalid() && Tok.isNot(tok::r_paren) &&
370 Tok.isNot(tok::annot_pragma_openmp_end)) {
371 TPA.Commit();
372 IsCorrect = false;
373 break;
374 }
375 IsCorrect = !T.consumeClose() && IsCorrect && CombinerResult.isUsable();
376 ExprResult InitializerResult;
377 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
378 // Parse <initializer> expression.
379 if (Tok.is(tok::identifier) &&
380 Tok.getIdentifierInfo()->isStr("initializer")) {
381 ConsumeToken();
382 } else {
383 Diag(Tok.getLocation(), diag::err_expected) << "'initializer'";
384 TPA.Commit();
385 IsCorrect = false;
386 break;
387 }
388 // Parse '('.
389 BalancedDelimiterTracker T(*this, tok::l_paren,
390 tok::annot_pragma_openmp_end);
391 IsCorrect =
392 !T.expectAndConsume(diag::err_expected_lparen_after, "initializer") &&
393 IsCorrect;
394 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
395 ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope |
396 Scope::CompoundStmtScope |
397 Scope::OpenMPDirectiveScope);
398 // Parse expression.
399 VarDecl *OmpPrivParm =
400 Actions.ActOnOpenMPDeclareReductionInitializerStart(getCurScope(),
401 D);
402 // Check if initializer is omp_priv <init_expr> or something else.
403 if (Tok.is(tok::identifier) &&
404 Tok.getIdentifierInfo()->isStr("omp_priv")) {
405 ConsumeToken();
406 ParseOpenMPReductionInitializerForDecl(OmpPrivParm);
407 } else {
408 InitializerResult = Actions.ActOnFinishFullExpr(
409 ParseAssignmentExpression().get(), D->getLocation(),
410 /*DiscardedValue*/ false);
411 }
412 Actions.ActOnOpenMPDeclareReductionInitializerEnd(
413 D, InitializerResult.get(), OmpPrivParm);
414 if (InitializerResult.isInvalid() && Tok.isNot(tok::r_paren) &&
415 Tok.isNot(tok::annot_pragma_openmp_end)) {
416 TPA.Commit();
417 IsCorrect = false;
418 break;
419 }
420 IsCorrect =
421 !T.consumeClose() && IsCorrect && !InitializerResult.isInvalid();
422 }
423 }
424
425 ++I;
426 // Revert parsing if not the last type, otherwise accept it, we're done with
427 // parsing.
428 if (I != E)
429 TPA.Revert();
430 else
431 TPA.Commit();
432 }
433 return Actions.ActOnOpenMPDeclareReductionDirectiveEnd(getCurScope(), DRD,
434 IsCorrect);
435}
436
437void Parser::ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm) {
438 // Parse declarator '=' initializer.
439 // If a '==' or '+=' is found, suggest a fixit to '='.
440 if (isTokenEqualOrEqualTypo()) {
441 ConsumeToken();
442
443 if (Tok.is(tok::code_completion)) {
444 Actions.CodeCompleteInitializer(getCurScope(), OmpPrivParm);
445 Actions.FinalizeDeclaration(OmpPrivParm);
446 cutOffParsing();
447 return;
448 }
449
450 PreferredType.enterVariableInit(Tok.getLocation(), OmpPrivParm);
451 ExprResult Init = ParseInitializer();
452
453 if (Init.isInvalid()) {
454 SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, StopBeforeMatch);
455 Actions.ActOnInitializerError(OmpPrivParm);
456 } else {
457 Actions.AddInitializerToDecl(OmpPrivParm, Init.get(),
458 /*DirectInit=*/false);
459 }
460 } else if (Tok.is(tok::l_paren)) {
461 // Parse C++ direct initializer: '(' expression-list ')'
462 BalancedDelimiterTracker T(*this, tok::l_paren);
463 T.consumeOpen();
464
465 ExprVector Exprs;
466 CommaLocsTy CommaLocs;
467
468 SourceLocation LParLoc = T.getOpenLocation();
469 auto RunSignatureHelp = [this, OmpPrivParm, LParLoc, &Exprs]() {
470 QualType PreferredType = Actions.ProduceConstructorSignatureHelp(
471 getCurScope(), OmpPrivParm->getType()->getCanonicalTypeInternal(),
472 OmpPrivParm->getLocation(), Exprs, LParLoc);
473 CalledSignatureHelp = true;
474 return PreferredType;
475 };
476 if (ParseExpressionList(Exprs, CommaLocs, [&] {
477 PreferredType.enterFunctionArgument(Tok.getLocation(),
478 RunSignatureHelp);
479 })) {
480 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
481 RunSignatureHelp();
482 Actions.ActOnInitializerError(OmpPrivParm);
483 SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, StopBeforeMatch);
484 } else {
485 // Match the ')'.
486 SourceLocation RLoc = Tok.getLocation();
487 if (!T.consumeClose())
488 RLoc = T.getCloseLocation();
489
490 assert(!Exprs.empty() && Exprs.size() - 1 == CommaLocs.size() &&((!Exprs.empty() && Exprs.size() - 1 == CommaLocs.size
() && "Unexpected number of commas!") ? static_cast<
void> (0) : __assert_fail ("!Exprs.empty() && Exprs.size() - 1 == CommaLocs.size() && \"Unexpected number of commas!\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 491, __PRETTY_FUNCTION__))
491 "Unexpected number of commas!")((!Exprs.empty() && Exprs.size() - 1 == CommaLocs.size
() && "Unexpected number of commas!") ? static_cast<
void> (0) : __assert_fail ("!Exprs.empty() && Exprs.size() - 1 == CommaLocs.size() && \"Unexpected number of commas!\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 491, __PRETTY_FUNCTION__))
;
492
493 ExprResult Initializer =
494 Actions.ActOnParenListExpr(T.getOpenLocation(), RLoc, Exprs);
495 Actions.AddInitializerToDecl(OmpPrivParm, Initializer.get(),
496 /*DirectInit=*/true);
497 }
498 } else if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
499 // Parse C++0x braced-init-list.
500 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
501
502 ExprResult Init(ParseBraceInitializer());
503
504 if (Init.isInvalid()) {
505 Actions.ActOnInitializerError(OmpPrivParm);
506 } else {
507 Actions.AddInitializerToDecl(OmpPrivParm, Init.get(),
508 /*DirectInit=*/true);
509 }
510 } else {
511 Actions.ActOnUninitializedDecl(OmpPrivParm);
512 }
513}
514
515/// Parses 'omp declare mapper' directive.
516///
517/// declare-mapper-directive:
518/// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifier> ':']
519/// <type> <var> ')' [<clause>[[,] <clause>] ... ]
520/// annot_pragma_openmp_end
521/// <mapper-identifier> and <var> are base language identifiers.
522///
523Parser::DeclGroupPtrTy
524Parser::ParseOpenMPDeclareMapperDirective(AccessSpecifier AS) {
525 bool IsCorrect = true;
526 // Parse '('
527 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
528 if (T.expectAndConsume(diag::err_expected_lparen_after,
529 getOpenMPDirectiveName(OMPD_declare_mapper).data())) {
530 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
531 return DeclGroupPtrTy();
532 }
533
534 // Parse <mapper-identifier>
535 auto &DeclNames = Actions.getASTContext().DeclarationNames;
536 DeclarationName MapperId;
537 if (PP.LookAhead(0).is(tok::colon)) {
538 if (Tok.isNot(tok::identifier) && Tok.isNot(tok::kw_default)) {
539 Diag(Tok.getLocation(), diag::err_omp_mapper_illegal_identifier);
540 IsCorrect = false;
541 } else {
542 MapperId = DeclNames.getIdentifier(Tok.getIdentifierInfo());
543 }
544 ConsumeToken();
545 // Consume ':'.
546 ExpectAndConsume(tok::colon);
547 } else {
548 // If no mapper identifier is provided, its name is "default" by default
549 MapperId =
550 DeclNames.getIdentifier(&Actions.getASTContext().Idents.get("default"));
551 }
552
553 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
554 return DeclGroupPtrTy();
555
556 // Parse <type> <var>
557 DeclarationName VName;
558 QualType MapperType;
559 SourceRange Range;
560 TypeResult ParsedType = parseOpenMPDeclareMapperVarDecl(Range, VName, AS);
561 if (ParsedType.isUsable())
562 MapperType =
563 Actions.ActOnOpenMPDeclareMapperType(Range.getBegin(), ParsedType);
564 if (MapperType.isNull())
565 IsCorrect = false;
566 if (!IsCorrect) {
567 SkipUntil(tok::annot_pragma_openmp_end, Parser::StopBeforeMatch);
568 return DeclGroupPtrTy();
569 }
570
571 // Consume ')'.
572 IsCorrect &= !T.consumeClose();
573 if (!IsCorrect) {
574 SkipUntil(tok::annot_pragma_openmp_end, Parser::StopBeforeMatch);
575 return DeclGroupPtrTy();
576 }
577
578 // Enter scope.
579 DeclarationNameInfo DirName;
580 SourceLocation Loc = Tok.getLocation();
581 unsigned ScopeFlags = Scope::FnScope | Scope::DeclScope |
582 Scope::CompoundStmtScope | Scope::OpenMPDirectiveScope;
583 ParseScope OMPDirectiveScope(this, ScopeFlags);
584 Actions.StartOpenMPDSABlock(OMPD_declare_mapper, DirName, getCurScope(), Loc);
585
586 // Add the mapper variable declaration.
587 ExprResult MapperVarRef = Actions.ActOnOpenMPDeclareMapperDirectiveVarDecl(
588 getCurScope(), MapperType, Range.getBegin(), VName);
589
590 // Parse map clauses.
591 SmallVector<OMPClause *, 6> Clauses;
592 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
593 OpenMPClauseKind CKind = Tok.isAnnotation()
594 ? OMPC_unknown
595 : getOpenMPClauseKind(PP.getSpelling(Tok));
596 Actions.StartOpenMPClause(CKind);
597 OMPClause *Clause =
598 ParseOpenMPClause(OMPD_declare_mapper, CKind, Clauses.empty());
599 if (Clause)
600 Clauses.push_back(Clause);
601 else
602 IsCorrect = false;
603 // Skip ',' if any.
604 if (Tok.is(tok::comma))
605 ConsumeToken();
606 Actions.EndOpenMPClause();
607 }
608 if (Clauses.empty()) {
609 Diag(Tok, diag::err_omp_expected_clause)
610 << getOpenMPDirectiveName(OMPD_declare_mapper);
611 IsCorrect = false;
612 }
613
614 // Exit scope.
615 Actions.EndOpenMPDSABlock(nullptr);
616 OMPDirectiveScope.Exit();
617 DeclGroupPtrTy DG = Actions.ActOnOpenMPDeclareMapperDirective(
618 getCurScope(), Actions.getCurLexicalContext(), MapperId, MapperType,
619 Range.getBegin(), VName, AS, MapperVarRef.get(), Clauses);
620 if (!IsCorrect)
621 return DeclGroupPtrTy();
622
623 return DG;
624}
625
626TypeResult Parser::parseOpenMPDeclareMapperVarDecl(SourceRange &Range,
627 DeclarationName &Name,
628 AccessSpecifier AS) {
629 // Parse the common declaration-specifiers piece.
630 Parser::DeclSpecContext DSC = Parser::DeclSpecContext::DSC_type_specifier;
631 DeclSpec DS(AttrFactory);
632 ParseSpecifierQualifierList(DS, AS, DSC);
633
634 // Parse the declarator.
635 DeclaratorContext Context = DeclaratorContext::Prototype;
636 Declarator DeclaratorInfo(DS, Context);
637 ParseDeclarator(DeclaratorInfo);
638 Range = DeclaratorInfo.getSourceRange();
639 if (DeclaratorInfo.getIdentifier() == nullptr) {
640 Diag(Tok.getLocation(), diag::err_omp_mapper_expected_declarator);
641 return true;
642 }
643 Name = Actions.GetNameForDeclarator(DeclaratorInfo).getName();
644
645 return Actions.ActOnOpenMPDeclareMapperVarDecl(getCurScope(), DeclaratorInfo);
646}
647
648namespace {
649/// RAII that recreates function context for correct parsing of clauses of
650/// 'declare simd' construct.
651/// OpenMP, 2.8.2 declare simd Construct
652/// The expressions appearing in the clauses of this directive are evaluated in
653/// the scope of the arguments of the function declaration or definition.
654class FNContextRAII final {
655 Parser &P;
656 Sema::CXXThisScopeRAII *ThisScope;
657 Parser::MultiParseScope Scopes;
658 bool HasFunScope = false;
659 FNContextRAII() = delete;
660 FNContextRAII(const FNContextRAII &) = delete;
661 FNContextRAII &operator=(const FNContextRAII &) = delete;
662
663public:
664 FNContextRAII(Parser &P, Parser::DeclGroupPtrTy Ptr) : P(P), Scopes(P) {
665 Decl *D = *Ptr.get().begin();
666 NamedDecl *ND = dyn_cast<NamedDecl>(D);
667 RecordDecl *RD = dyn_cast_or_null<RecordDecl>(D->getDeclContext());
668 Sema &Actions = P.getActions();
669
670 // Allow 'this' within late-parsed attributes.
671 ThisScope = new Sema::CXXThisScopeRAII(Actions, RD, Qualifiers(),
672 ND && ND->isCXXInstanceMember());
673
674 // If the Decl is templatized, add template parameters to scope.
675 // FIXME: Track CurTemplateDepth?
676 P.ReenterTemplateScopes(Scopes, D);
677
678 // If the Decl is on a function, add function parameters to the scope.
679 if (D->isFunctionOrFunctionTemplate()) {
680 HasFunScope = true;
681 Scopes.Enter(Scope::FnScope | Scope::DeclScope |
682 Scope::CompoundStmtScope);
683 Actions.ActOnReenterFunctionContext(Actions.getCurScope(), D);
684 }
685 }
686 ~FNContextRAII() {
687 if (HasFunScope)
688 P.getActions().ActOnExitFunctionContext();
689 delete ThisScope;
690 }
691};
692} // namespace
693
694/// Parses clauses for 'declare simd' directive.
695/// clause:
696/// 'inbranch' | 'notinbranch'
697/// 'simdlen' '(' <expr> ')'
698/// { 'uniform' '(' <argument_list> ')' }
699/// { 'aligned '(' <argument_list> [ ':' <alignment> ] ')' }
700/// { 'linear '(' <argument_list> [ ':' <step> ] ')' }
701static bool parseDeclareSimdClauses(
702 Parser &P, OMPDeclareSimdDeclAttr::BranchStateTy &BS, ExprResult &SimdLen,
703 SmallVectorImpl<Expr *> &Uniforms, SmallVectorImpl<Expr *> &Aligneds,
704 SmallVectorImpl<Expr *> &Alignments, SmallVectorImpl<Expr *> &Linears,
705 SmallVectorImpl<unsigned> &LinModifiers, SmallVectorImpl<Expr *> &Steps) {
706 SourceRange BSRange;
707 const Token &Tok = P.getCurToken();
708 bool IsError = false;
709 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
710 if (Tok.isNot(tok::identifier))
711 break;
712 OMPDeclareSimdDeclAttr::BranchStateTy Out;
713 IdentifierInfo *II = Tok.getIdentifierInfo();
714 StringRef ClauseName = II->getName();
715 // Parse 'inranch|notinbranch' clauses.
716 if (OMPDeclareSimdDeclAttr::ConvertStrToBranchStateTy(ClauseName, Out)) {
717 if (BS != OMPDeclareSimdDeclAttr::BS_Undefined && BS != Out) {
718 P.Diag(Tok, diag::err_omp_declare_simd_inbranch_notinbranch)
719 << ClauseName
720 << OMPDeclareSimdDeclAttr::ConvertBranchStateTyToStr(BS) << BSRange;
721 IsError = true;
722 }
723 BS = Out;
724 BSRange = SourceRange(Tok.getLocation(), Tok.getEndLoc());
725 P.ConsumeToken();
726 } else if (ClauseName.equals("simdlen")) {
727 if (SimdLen.isUsable()) {
728 P.Diag(Tok, diag::err_omp_more_one_clause)
729 << getOpenMPDirectiveName(OMPD_declare_simd) << ClauseName << 0;
730 IsError = true;
731 }
732 P.ConsumeToken();
733 SourceLocation RLoc;
734 SimdLen = P.ParseOpenMPParensExpr(ClauseName, RLoc);
735 if (SimdLen.isInvalid())
736 IsError = true;
737 } else {
738 OpenMPClauseKind CKind = getOpenMPClauseKind(ClauseName);
739 if (CKind == OMPC_uniform || CKind == OMPC_aligned ||
740 CKind == OMPC_linear) {
741 Parser::OpenMPVarListDataTy Data;
742 SmallVectorImpl<Expr *> *Vars = &Uniforms;
743 if (CKind == OMPC_aligned) {
744 Vars = &Aligneds;
745 } else if (CKind == OMPC_linear) {
746 Data.ExtraModifier = OMPC_LINEAR_val;
747 Vars = &Linears;
748 }
749
750 P.ConsumeToken();
751 if (P.ParseOpenMPVarList(OMPD_declare_simd,
752 getOpenMPClauseKind(ClauseName), *Vars, Data))
753 IsError = true;
754 if (CKind == OMPC_aligned) {
755 Alignments.append(Aligneds.size() - Alignments.size(),
756 Data.DepModOrTailExpr);
757 } else if (CKind == OMPC_linear) {
758 assert(0 <= Data.ExtraModifier &&((0 <= Data.ExtraModifier && Data.ExtraModifier <=
OMPC_LINEAR_unknown && "Unexpected linear modifier."
) ? static_cast<void> (0) : __assert_fail ("0 <= Data.ExtraModifier && Data.ExtraModifier <= OMPC_LINEAR_unknown && \"Unexpected linear modifier.\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 760, __PRETTY_FUNCTION__))
759 Data.ExtraModifier <= OMPC_LINEAR_unknown &&((0 <= Data.ExtraModifier && Data.ExtraModifier <=
OMPC_LINEAR_unknown && "Unexpected linear modifier."
) ? static_cast<void> (0) : __assert_fail ("0 <= Data.ExtraModifier && Data.ExtraModifier <= OMPC_LINEAR_unknown && \"Unexpected linear modifier.\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 760, __PRETTY_FUNCTION__))
760 "Unexpected linear modifier.")((0 <= Data.ExtraModifier && Data.ExtraModifier <=
OMPC_LINEAR_unknown && "Unexpected linear modifier."
) ? static_cast<void> (0) : __assert_fail ("0 <= Data.ExtraModifier && Data.ExtraModifier <= OMPC_LINEAR_unknown && \"Unexpected linear modifier.\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 760, __PRETTY_FUNCTION__))
;
761 if (P.getActions().CheckOpenMPLinearModifier(
762 static_cast<OpenMPLinearClauseKind>(Data.ExtraModifier),
763 Data.ExtraModifierLoc))
764 Data.ExtraModifier = OMPC_LINEAR_val;
765 LinModifiers.append(Linears.size() - LinModifiers.size(),
766 Data.ExtraModifier);
767 Steps.append(Linears.size() - Steps.size(), Data.DepModOrTailExpr);
768 }
769 } else
770 // TODO: add parsing of other clauses.
771 break;
772 }
773 // Skip ',' if any.
774 if (Tok.is(tok::comma))
775 P.ConsumeToken();
776 }
777 return IsError;
778}
779
780/// Parse clauses for '#pragma omp declare simd'.
781Parser::DeclGroupPtrTy
782Parser::ParseOMPDeclareSimdClauses(Parser::DeclGroupPtrTy Ptr,
783 CachedTokens &Toks, SourceLocation Loc) {
784 PP.EnterToken(Tok, /*IsReinject*/ true);
785 PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true,
786 /*IsReinject*/ true);
787 // Consume the previously pushed token.
788 ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
789 ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
790
791 FNContextRAII FnContext(*this, Ptr);
792 OMPDeclareSimdDeclAttr::BranchStateTy BS =
793 OMPDeclareSimdDeclAttr::BS_Undefined;
794 ExprResult Simdlen;
795 SmallVector<Expr *, 4> Uniforms;
796 SmallVector<Expr *, 4> Aligneds;
797 SmallVector<Expr *, 4> Alignments;
798 SmallVector<Expr *, 4> Linears;
799 SmallVector<unsigned, 4> LinModifiers;
800 SmallVector<Expr *, 4> Steps;
801 bool IsError =
802 parseDeclareSimdClauses(*this, BS, Simdlen, Uniforms, Aligneds,
803 Alignments, Linears, LinModifiers, Steps);
804 skipUntilPragmaOpenMPEnd(OMPD_declare_simd);
805 // Skip the last annot_pragma_openmp_end.
806 SourceLocation EndLoc = ConsumeAnnotationToken();
807 if (IsError)
808 return Ptr;
809 return Actions.ActOnOpenMPDeclareSimdDirective(
810 Ptr, BS, Simdlen.get(), Uniforms, Aligneds, Alignments, Linears,
811 LinModifiers, Steps, SourceRange(Loc, EndLoc));
812}
813
814namespace {
815/// Constant used in the diagnostics to distinguish the levels in an OpenMP
816/// contexts: selector-set={selector(trait, ...), ...}, ....
817enum OMPContextLvl {
818 CONTEXT_SELECTOR_SET_LVL = 0,
819 CONTEXT_SELECTOR_LVL = 1,
820 CONTEXT_TRAIT_LVL = 2,
821};
822
823static StringRef stringLiteralParser(Parser &P) {
824 ExprResult Res = P.ParseStringLiteralExpression(true);
825 return Res.isUsable() ? Res.getAs<StringLiteral>()->getString() : "";
826}
827
828static StringRef getNameFromIdOrString(Parser &P, Token &Tok,
829 OMPContextLvl Lvl) {
830 if (Tok.is(tok::identifier)) {
831 llvm::SmallString<16> Buffer;
832 StringRef Name = P.getPreprocessor().getSpelling(Tok, Buffer);
833 (void)P.ConsumeToken();
834 return Name;
835 }
836
837 if (tok::isStringLiteral(Tok.getKind()))
838 return stringLiteralParser(P);
839
840 P.Diag(Tok.getLocation(),
841 diag::warn_omp_declare_variant_string_literal_or_identifier)
842 << Lvl;
843 return "";
844}
845
846static bool checkForDuplicates(Parser &P, StringRef Name,
847 SourceLocation NameLoc,
848 llvm::StringMap<SourceLocation> &Seen,
849 OMPContextLvl Lvl) {
850 auto Res = Seen.try_emplace(Name, NameLoc);
851 if (Res.second)
852 return false;
853
854 // Each trait-set-selector-name, trait-selector-name and trait-name can
855 // only be specified once.
856 P.Diag(NameLoc, diag::warn_omp_declare_variant_ctx_mutiple_use)
857 << Lvl << Name;
858 P.Diag(Res.first->getValue(), diag::note_omp_declare_variant_ctx_used_here)
859 << Lvl << Name;
860 return true;
861}
862} // namespace
863
864void Parser::parseOMPTraitPropertyKind(OMPTraitProperty &TIProperty,
865 llvm::omp::TraitSet Set,
866 llvm::omp::TraitSelector Selector,
867 llvm::StringMap<SourceLocation> &Seen) {
868 TIProperty.Kind = TraitProperty::invalid;
869
870 SourceLocation NameLoc = Tok.getLocation();
871 StringRef Name = getNameFromIdOrString(*this, Tok, CONTEXT_TRAIT_LVL);
872 if (Name.empty()) {
873 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_options)
874 << CONTEXT_TRAIT_LVL << listOpenMPContextTraitProperties(Set, Selector);
875 return;
876 }
877
878 TIProperty.RawString = Name;
879 TIProperty.Kind = getOpenMPContextTraitPropertyKind(Set, Selector, Name);
880 if (TIProperty.Kind != TraitProperty::invalid) {
881 if (checkForDuplicates(*this, Name, NameLoc, Seen, CONTEXT_TRAIT_LVL))
882 TIProperty.Kind = TraitProperty::invalid;
883 return;
884 }
885
886 // It follows diagnosis and helping notes.
887 // FIXME: We should move the diagnosis string generation into libFrontend.
888 Diag(NameLoc, diag::warn_omp_declare_variant_ctx_not_a_property)
889 << Name << getOpenMPContextTraitSelectorName(Selector)
890 << getOpenMPContextTraitSetName(Set);
891
892 TraitSet SetForName = getOpenMPContextTraitSetKind(Name);
893 if (SetForName != TraitSet::invalid) {
894 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
895 << Name << CONTEXT_SELECTOR_SET_LVL << CONTEXT_TRAIT_LVL;
896 Diag(NameLoc, diag::note_omp_declare_variant_ctx_try)
897 << Name << "<selector-name>"
898 << "(<property-name>)";
899 return;
900 }
901 TraitSelector SelectorForName = getOpenMPContextTraitSelectorKind(Name);
902 if (SelectorForName != TraitSelector::invalid) {
903 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
904 << Name << CONTEXT_SELECTOR_LVL << CONTEXT_TRAIT_LVL;
905 bool AllowsTraitScore = false;
906 bool RequiresProperty = false;
907 isValidTraitSelectorForTraitSet(
908 SelectorForName, getOpenMPContextTraitSetForSelector(SelectorForName),
909 AllowsTraitScore, RequiresProperty);
910 Diag(NameLoc, diag::note_omp_declare_variant_ctx_try)
911 << getOpenMPContextTraitSetName(
912 getOpenMPContextTraitSetForSelector(SelectorForName))
913 << Name << (RequiresProperty ? "(<property-name>)" : "");
914 return;
915 }
916 for (const auto &PotentialSet :
917 {TraitSet::construct, TraitSet::user, TraitSet::implementation,
918 TraitSet::device}) {
919 TraitProperty PropertyForName =
920 getOpenMPContextTraitPropertyKind(PotentialSet, Selector, Name);
921 if (PropertyForName == TraitProperty::invalid)
922 continue;
923 Diag(NameLoc, diag::note_omp_declare_variant_ctx_try)
924 << getOpenMPContextTraitSetName(
925 getOpenMPContextTraitSetForProperty(PropertyForName))
926 << getOpenMPContextTraitSelectorName(
927 getOpenMPContextTraitSelectorForProperty(PropertyForName))
928 << ("(" + Name + ")").str();
929 return;
930 }
931 Diag(NameLoc, diag::note_omp_declare_variant_ctx_options)
932 << CONTEXT_TRAIT_LVL << listOpenMPContextTraitProperties(Set, Selector);
933}
934
935static bool checkExtensionProperty(Parser &P, SourceLocation Loc,
936 OMPTraitProperty &TIProperty,
937 OMPTraitSelector &TISelector,
938 llvm::StringMap<SourceLocation> &Seen) {
939 assert(TISelector.Kind ==((TISelector.Kind == llvm::omp::TraitSelector::implementation_extension
&& "Only for extension properties, e.g., " "`implementation={extension(PROPERTY)}`"
) ? static_cast<void> (0) : __assert_fail ("TISelector.Kind == llvm::omp::TraitSelector::implementation_extension && \"Only for extension properties, e.g., \" \"`implementation={extension(PROPERTY)}`\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 942, __PRETTY_FUNCTION__))
940 llvm::omp::TraitSelector::implementation_extension &&((TISelector.Kind == llvm::omp::TraitSelector::implementation_extension
&& "Only for extension properties, e.g., " "`implementation={extension(PROPERTY)}`"
) ? static_cast<void> (0) : __assert_fail ("TISelector.Kind == llvm::omp::TraitSelector::implementation_extension && \"Only for extension properties, e.g., \" \"`implementation={extension(PROPERTY)}`\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 942, __PRETTY_FUNCTION__))
941 "Only for extension properties, e.g., "((TISelector.Kind == llvm::omp::TraitSelector::implementation_extension
&& "Only for extension properties, e.g., " "`implementation={extension(PROPERTY)}`"
) ? static_cast<void> (0) : __assert_fail ("TISelector.Kind == llvm::omp::TraitSelector::implementation_extension && \"Only for extension properties, e.g., \" \"`implementation={extension(PROPERTY)}`\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 942, __PRETTY_FUNCTION__))
942 "`implementation={extension(PROPERTY)}`")((TISelector.Kind == llvm::omp::TraitSelector::implementation_extension
&& "Only for extension properties, e.g., " "`implementation={extension(PROPERTY)}`"
) ? static_cast<void> (0) : __assert_fail ("TISelector.Kind == llvm::omp::TraitSelector::implementation_extension && \"Only for extension properties, e.g., \" \"`implementation={extension(PROPERTY)}`\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 942, __PRETTY_FUNCTION__))
;
943 if (TIProperty.Kind == TraitProperty::invalid)
944 return false;
945
946 if (TIProperty.Kind ==
947 TraitProperty::implementation_extension_disable_implicit_base)
948 return true;
949
950 if (TIProperty.Kind ==
951 TraitProperty::implementation_extension_allow_templates)
952 return true;
953
954 auto IsMatchExtension = [](OMPTraitProperty &TP) {
955 return (TP.Kind ==
956 llvm::omp::TraitProperty::implementation_extension_match_all ||
957 TP.Kind ==
958 llvm::omp::TraitProperty::implementation_extension_match_any ||
959 TP.Kind ==
960 llvm::omp::TraitProperty::implementation_extension_match_none);
961 };
962
963 if (IsMatchExtension(TIProperty)) {
964 for (OMPTraitProperty &SeenProp : TISelector.Properties)
965 if (IsMatchExtension(SeenProp)) {
966 P.Diag(Loc, diag::err_omp_variant_ctx_second_match_extension);
967 StringRef SeenName = llvm::omp::getOpenMPContextTraitPropertyName(
968 SeenProp.Kind, SeenProp.RawString);
969 SourceLocation SeenLoc = Seen[SeenName];
970 P.Diag(SeenLoc, diag::note_omp_declare_variant_ctx_used_here)
971 << CONTEXT_TRAIT_LVL << SeenName;
972 return false;
973 }
974 return true;
975 }
976
977 llvm_unreachable("Unknown extension property!")::llvm::llvm_unreachable_internal("Unknown extension property!"
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 977)
;
978}
979
980void Parser::parseOMPContextProperty(OMPTraitSelector &TISelector,
981 llvm::omp::TraitSet Set,
982 llvm::StringMap<SourceLocation> &Seen) {
983 assert(TISelector.Kind != TraitSelector::user_condition &&((TISelector.Kind != TraitSelector::user_condition &&
"User conditions are special properties not handled here!") ?
static_cast<void> (0) : __assert_fail ("TISelector.Kind != TraitSelector::user_condition && \"User conditions are special properties not handled here!\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 984, __PRETTY_FUNCTION__))
984 "User conditions are special properties not handled here!")((TISelector.Kind != TraitSelector::user_condition &&
"User conditions are special properties not handled here!") ?
static_cast<void> (0) : __assert_fail ("TISelector.Kind != TraitSelector::user_condition && \"User conditions are special properties not handled here!\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 984, __PRETTY_FUNCTION__))
;
985
986 SourceLocation PropertyLoc = Tok.getLocation();
987 OMPTraitProperty TIProperty;
988 parseOMPTraitPropertyKind(TIProperty, Set, TISelector.Kind, Seen);
989
990 if (TISelector.Kind == llvm::omp::TraitSelector::implementation_extension)
991 if (!checkExtensionProperty(*this, Tok.getLocation(), TIProperty,
992 TISelector, Seen))
993 TIProperty.Kind = TraitProperty::invalid;
994
995 // If we have an invalid property here we already issued a warning.
996 if (TIProperty.Kind == TraitProperty::invalid) {
997 if (PropertyLoc != Tok.getLocation())
998 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_continue_here)
999 << CONTEXT_TRAIT_LVL;
1000 return;
1001 }
1002
1003 if (isValidTraitPropertyForTraitSetAndSelector(TIProperty.Kind,
1004 TISelector.Kind, Set)) {
1005
1006 // If we make it here the property, selector, set, score, condition, ... are
1007 // all valid (or have been corrected). Thus we can record the property.
1008 TISelector.Properties.push_back(TIProperty);
1009 return;
1010 }
1011
1012 Diag(PropertyLoc, diag::warn_omp_ctx_incompatible_property_for_selector)
1013 << getOpenMPContextTraitPropertyName(TIProperty.Kind,
1014 TIProperty.RawString)
1015 << getOpenMPContextTraitSelectorName(TISelector.Kind)
1016 << getOpenMPContextTraitSetName(Set);
1017 Diag(PropertyLoc, diag::note_omp_ctx_compatible_set_and_selector_for_property)
1018 << getOpenMPContextTraitPropertyName(TIProperty.Kind,
1019 TIProperty.RawString)
1020 << getOpenMPContextTraitSelectorName(
1021 getOpenMPContextTraitSelectorForProperty(TIProperty.Kind))
1022 << getOpenMPContextTraitSetName(
1023 getOpenMPContextTraitSetForProperty(TIProperty.Kind));
1024 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_continue_here)
1025 << CONTEXT_TRAIT_LVL;
1026}
1027
1028void Parser::parseOMPTraitSelectorKind(OMPTraitSelector &TISelector,
1029 llvm::omp::TraitSet Set,
1030 llvm::StringMap<SourceLocation> &Seen) {
1031 TISelector.Kind = TraitSelector::invalid;
1032
1033 SourceLocation NameLoc = Tok.getLocation();
1034 StringRef Name = getNameFromIdOrString(*this, Tok, CONTEXT_SELECTOR_LVL);
1035 if (Name.empty()) {
1036 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_options)
1037 << CONTEXT_SELECTOR_LVL << listOpenMPContextTraitSelectors(Set);
1038 return;
1039 }
1040
1041 TISelector.Kind = getOpenMPContextTraitSelectorKind(Name);
1042 if (TISelector.Kind != TraitSelector::invalid) {
1043 if (checkForDuplicates(*this, Name, NameLoc, Seen, CONTEXT_SELECTOR_LVL))
1044 TISelector.Kind = TraitSelector::invalid;
1045 return;
1046 }
1047
1048 // It follows diagnosis and helping notes.
1049 Diag(NameLoc, diag::warn_omp_declare_variant_ctx_not_a_selector)
1050 << Name << getOpenMPContextTraitSetName(Set);
1051
1052 TraitSet SetForName = getOpenMPContextTraitSetKind(Name);
1053 if (SetForName != TraitSet::invalid) {
1054 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
1055 << Name << CONTEXT_SELECTOR_SET_LVL << CONTEXT_SELECTOR_LVL;
1056 Diag(NameLoc, diag::note_omp_declare_variant_ctx_try)
1057 << Name << "<selector-name>"
1058 << "<property-name>";
1059 return;
1060 }
1061 for (const auto &PotentialSet :
1062 {TraitSet::construct, TraitSet::user, TraitSet::implementation,
1063 TraitSet::device}) {
1064 TraitProperty PropertyForName = getOpenMPContextTraitPropertyKind(
1065 PotentialSet, TraitSelector::invalid, Name);
1066 if (PropertyForName == TraitProperty::invalid)
1067 continue;
1068 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
1069 << Name << CONTEXT_TRAIT_LVL << CONTEXT_SELECTOR_LVL;
1070 Diag(NameLoc, diag::note_omp_declare_variant_ctx_try)
1071 << getOpenMPContextTraitSetName(
1072 getOpenMPContextTraitSetForProperty(PropertyForName))
1073 << getOpenMPContextTraitSelectorName(
1074 getOpenMPContextTraitSelectorForProperty(PropertyForName))
1075 << ("(" + Name + ")").str();
1076 return;
1077 }
1078 Diag(NameLoc, diag::note_omp_declare_variant_ctx_options)
1079 << CONTEXT_SELECTOR_LVL << listOpenMPContextTraitSelectors(Set);
1080}
1081
1082/// Parse optional 'score' '(' <expr> ')' ':'.
1083static ExprResult parseContextScore(Parser &P) {
1084 ExprResult ScoreExpr;
1085 llvm::SmallString<16> Buffer;
1086 StringRef SelectorName =
1087 P.getPreprocessor().getSpelling(P.getCurToken(), Buffer);
1088 if (!SelectorName.equals("score"))
1089 return ScoreExpr;
1090 (void)P.ConsumeToken();
1091 SourceLocation RLoc;
1092 ScoreExpr = P.ParseOpenMPParensExpr(SelectorName, RLoc);
1093 // Parse ':'
1094 if (P.getCurToken().is(tok::colon))
1095 (void)P.ConsumeAnyToken();
1096 else
1097 P.Diag(P.getCurToken(), diag::warn_omp_declare_variant_expected)
1098 << "':'"
1099 << "score expression";
1100 return ScoreExpr;
1101}
1102
1103/// Parses an OpenMP context selector.
1104///
1105/// <trait-selector-name> ['('[<trait-score>] <trait-property> [, <t-p>]* ')']
1106void Parser::parseOMPContextSelector(
1107 OMPTraitSelector &TISelector, llvm::omp::TraitSet Set,
1108 llvm::StringMap<SourceLocation> &SeenSelectors) {
1109 unsigned short OuterPC = ParenCount;
1110
1111 // If anything went wrong we issue an error or warning and then skip the rest
1112 // of the selector. However, commas are ambiguous so we look for the nesting
1113 // of parentheses here as well.
1114 auto FinishSelector = [OuterPC, this]() -> void {
1115 bool Done = false;
1116 while (!Done) {
1117 while (!SkipUntil({tok::r_brace, tok::r_paren, tok::comma,
1118 tok::annot_pragma_openmp_end},
1119 StopBeforeMatch))
1120 ;
1121 if (Tok.is(tok::r_paren) && OuterPC > ParenCount)
1122 (void)ConsumeParen();
1123 if (OuterPC <= ParenCount) {
1124 Done = true;
1125 break;
1126 }
1127 if (!Tok.is(tok::comma) && !Tok.is(tok::r_paren)) {
1128 Done = true;
1129 break;
1130 }
1131 (void)ConsumeAnyToken();
1132 }
1133 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_continue_here)
1134 << CONTEXT_SELECTOR_LVL;
1135 };
1136
1137 SourceLocation SelectorLoc = Tok.getLocation();
1138 parseOMPTraitSelectorKind(TISelector, Set, SeenSelectors);
1139 if (TISelector.Kind == TraitSelector::invalid)
1140 return FinishSelector();
1141
1142 bool AllowsTraitScore = false;
1143 bool RequiresProperty = false;
1144 if (!isValidTraitSelectorForTraitSet(TISelector.Kind, Set, AllowsTraitScore,
1145 RequiresProperty)) {
1146 Diag(SelectorLoc, diag::warn_omp_ctx_incompatible_selector_for_set)
1147 << getOpenMPContextTraitSelectorName(TISelector.Kind)
1148 << getOpenMPContextTraitSetName(Set);
1149 Diag(SelectorLoc, diag::note_omp_ctx_compatible_set_for_selector)
1150 << getOpenMPContextTraitSelectorName(TISelector.Kind)
1151 << getOpenMPContextTraitSetName(
1152 getOpenMPContextTraitSetForSelector(TISelector.Kind))
1153 << RequiresProperty;
1154 return FinishSelector();
1155 }
1156
1157 if (!RequiresProperty) {
1158 TISelector.Properties.push_back(
1159 {getOpenMPContextTraitPropertyForSelector(TISelector.Kind),
1160 getOpenMPContextTraitSelectorName(TISelector.Kind)});
1161 return;
1162 }
1163
1164 if (!Tok.is(tok::l_paren)) {
1165 Diag(SelectorLoc, diag::warn_omp_ctx_selector_without_properties)
1166 << getOpenMPContextTraitSelectorName(TISelector.Kind)
1167 << getOpenMPContextTraitSetName(Set);
1168 return FinishSelector();
1169 }
1170
1171 if (TISelector.Kind == TraitSelector::user_condition) {
1172 SourceLocation RLoc;
1173 ExprResult Condition = ParseOpenMPParensExpr("user condition", RLoc);
1174 if (!Condition.isUsable())
1175 return FinishSelector();
1176 TISelector.ScoreOrCondition = Condition.get();
1177 TISelector.Properties.push_back(
1178 {TraitProperty::user_condition_unknown, "<condition>"});
1179 return;
1180 }
1181
1182 BalancedDelimiterTracker BDT(*this, tok::l_paren,
1183 tok::annot_pragma_openmp_end);
1184 // Parse '('.
1185 (void)BDT.consumeOpen();
1186
1187 SourceLocation ScoreLoc = Tok.getLocation();
1188 ExprResult Score = parseContextScore(*this);
1189
1190 if (!AllowsTraitScore && !Score.isUnset()) {
1191 if (Score.isUsable()) {
1192 Diag(ScoreLoc, diag::warn_omp_ctx_incompatible_score_for_property)
1193 << getOpenMPContextTraitSelectorName(TISelector.Kind)
1194 << getOpenMPContextTraitSetName(Set) << Score.get();
1195 } else {
1196 Diag(ScoreLoc, diag::warn_omp_ctx_incompatible_score_for_property)
1197 << getOpenMPContextTraitSelectorName(TISelector.Kind)
1198 << getOpenMPContextTraitSetName(Set) << "<invalid>";
1199 }
1200 Score = ExprResult();
1201 }
1202
1203 if (Score.isUsable())
1204 TISelector.ScoreOrCondition = Score.get();
1205
1206 llvm::StringMap<SourceLocation> SeenProperties;
1207 do {
1208 parseOMPContextProperty(TISelector, Set, SeenProperties);
1209 } while (TryConsumeToken(tok::comma));
1210
1211 // Parse ')'.
1212 BDT.consumeClose();
1213}
1214
1215void Parser::parseOMPTraitSetKind(OMPTraitSet &TISet,
1216 llvm::StringMap<SourceLocation> &Seen) {
1217 TISet.Kind = TraitSet::invalid;
1218
1219 SourceLocation NameLoc = Tok.getLocation();
1220 StringRef Name = getNameFromIdOrString(*this, Tok, CONTEXT_SELECTOR_SET_LVL);
1221 if (Name.empty()) {
1222 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_options)
1223 << CONTEXT_SELECTOR_SET_LVL << listOpenMPContextTraitSets();
1224 return;
1225 }
1226
1227 TISet.Kind = getOpenMPContextTraitSetKind(Name);
1228 if (TISet.Kind != TraitSet::invalid) {
1229 if (checkForDuplicates(*this, Name, NameLoc, Seen,
1230 CONTEXT_SELECTOR_SET_LVL))
1231 TISet.Kind = TraitSet::invalid;
1232 return;
1233 }
1234
1235 // It follows diagnosis and helping notes.
1236 Diag(NameLoc, diag::warn_omp_declare_variant_ctx_not_a_set) << Name;
1237
1238 TraitSelector SelectorForName = getOpenMPContextTraitSelectorKind(Name);
1239 if (SelectorForName != TraitSelector::invalid) {
1240 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
1241 << Name << CONTEXT_SELECTOR_LVL << CONTEXT_SELECTOR_SET_LVL;
1242 bool AllowsTraitScore = false;
1243 bool RequiresProperty = false;
1244 isValidTraitSelectorForTraitSet(
1245 SelectorForName, getOpenMPContextTraitSetForSelector(SelectorForName),
1246 AllowsTraitScore, RequiresProperty);
1247 Diag(NameLoc, diag::note_omp_declare_variant_ctx_try)
1248 << getOpenMPContextTraitSetName(
1249 getOpenMPContextTraitSetForSelector(SelectorForName))
1250 << Name << (RequiresProperty ? "(<property-name>)" : "");
1251 return;
1252 }
1253 for (const auto &PotentialSet :
1254 {TraitSet::construct, TraitSet::user, TraitSet::implementation,
1255 TraitSet::device}) {
1256 TraitProperty PropertyForName = getOpenMPContextTraitPropertyKind(
1257 PotentialSet, TraitSelector::invalid, Name);
1258 if (PropertyForName == TraitProperty::invalid)
1259 continue;
1260 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
1261 << Name << CONTEXT_TRAIT_LVL << CONTEXT_SELECTOR_SET_LVL;
1262 Diag(NameLoc, diag::note_omp_declare_variant_ctx_try)
1263 << getOpenMPContextTraitSetName(
1264 getOpenMPContextTraitSetForProperty(PropertyForName))
1265 << getOpenMPContextTraitSelectorName(
1266 getOpenMPContextTraitSelectorForProperty(PropertyForName))
1267 << ("(" + Name + ")").str();
1268 return;
1269 }
1270 Diag(NameLoc, diag::note_omp_declare_variant_ctx_options)
1271 << CONTEXT_SELECTOR_SET_LVL << listOpenMPContextTraitSets();
1272}
1273
1274/// Parses an OpenMP context selector set.
1275///
1276/// <trait-set-selector-name> '=' '{' <trait-selector> [, <trait-selector>]* '}'
1277void Parser::parseOMPContextSelectorSet(
1278 OMPTraitSet &TISet, llvm::StringMap<SourceLocation> &SeenSets) {
1279 auto OuterBC = BraceCount;
1280
1281 // If anything went wrong we issue an error or warning and then skip the rest
1282 // of the set. However, commas are ambiguous so we look for the nesting
1283 // of braces here as well.
1284 auto FinishSelectorSet = [this, OuterBC]() -> void {
1285 bool Done = false;
1286 while (!Done) {
1287 while (!SkipUntil({tok::comma, tok::r_brace, tok::r_paren,
1288 tok::annot_pragma_openmp_end},
1289 StopBeforeMatch))
1290 ;
1291 if (Tok.is(tok::r_brace) && OuterBC > BraceCount)
1292 (void)ConsumeBrace();
1293 if (OuterBC <= BraceCount) {
1294 Done = true;
1295 break;
1296 }
1297 if (!Tok.is(tok::comma) && !Tok.is(tok::r_brace)) {
1298 Done = true;
1299 break;
1300 }
1301 (void)ConsumeAnyToken();
1302 }
1303 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_continue_here)
1304 << CONTEXT_SELECTOR_SET_LVL;
1305 };
1306
1307 parseOMPTraitSetKind(TISet, SeenSets);
1308 if (TISet.Kind == TraitSet::invalid)
1309 return FinishSelectorSet();
1310
1311 // Parse '='.
1312 if (!TryConsumeToken(tok::equal))
1313 Diag(Tok.getLocation(), diag::warn_omp_declare_variant_expected)
1314 << "="
1315 << ("context set name \"" + getOpenMPContextTraitSetName(TISet.Kind) +
1316 "\"")
1317 .str();
1318
1319 // Parse '{'.
1320 if (Tok.is(tok::l_brace)) {
1321 (void)ConsumeBrace();
1322 } else {
1323 Diag(Tok.getLocation(), diag::warn_omp_declare_variant_expected)
1324 << "{"
1325 << ("'=' that follows the context set name \"" +
1326 getOpenMPContextTraitSetName(TISet.Kind) + "\"")
1327 .str();
1328 }
1329
1330 llvm::StringMap<SourceLocation> SeenSelectors;
1331 do {
1332 OMPTraitSelector TISelector;
1333 parseOMPContextSelector(TISelector, TISet.Kind, SeenSelectors);
1334 if (TISelector.Kind != TraitSelector::invalid &&
1335 !TISelector.Properties.empty())
1336 TISet.Selectors.push_back(TISelector);
1337 } while (TryConsumeToken(tok::comma));
1338
1339 // Parse '}'.
1340 if (Tok.is(tok::r_brace)) {
1341 (void)ConsumeBrace();
1342 } else {
1343 Diag(Tok.getLocation(), diag::warn_omp_declare_variant_expected)
1344 << "}"
1345 << ("context selectors for the context set \"" +
1346 getOpenMPContextTraitSetName(TISet.Kind) + "\"")
1347 .str();
1348 }
1349}
1350
1351/// Parse OpenMP context selectors:
1352///
1353/// <trait-set-selector> [, <trait-set-selector>]*
1354bool Parser::parseOMPContextSelectors(SourceLocation Loc, OMPTraitInfo &TI) {
1355 llvm::StringMap<SourceLocation> SeenSets;
1356 do {
1357 OMPTraitSet TISet;
1358 parseOMPContextSelectorSet(TISet, SeenSets);
1359 if (TISet.Kind != TraitSet::invalid && !TISet.Selectors.empty())
1360 TI.Sets.push_back(TISet);
1361 } while (TryConsumeToken(tok::comma));
1362
1363 return false;
1364}
1365
1366/// Parse clauses for '#pragma omp declare variant ( variant-func-id ) clause'.
1367void Parser::ParseOMPDeclareVariantClauses(Parser::DeclGroupPtrTy Ptr,
1368 CachedTokens &Toks,
1369 SourceLocation Loc) {
1370 PP.EnterToken(Tok, /*IsReinject*/ true);
1371 PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true,
1372 /*IsReinject*/ true);
1373 // Consume the previously pushed token.
1374 ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
1375 ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
1376
1377 FNContextRAII FnContext(*this, Ptr);
1378 // Parse function declaration id.
1379 SourceLocation RLoc;
1380 // Parse with IsAddressOfOperand set to true to parse methods as DeclRefExprs
1381 // instead of MemberExprs.
1382 ExprResult AssociatedFunction;
1383 {
1384 // Do not mark function as is used to prevent its emission if this is the
1385 // only place where it is used.
1386 EnterExpressionEvaluationContext Unevaluated(
1387 Actions, Sema::ExpressionEvaluationContext::Unevaluated);
1388 AssociatedFunction = ParseOpenMPParensExpr(
1389 getOpenMPDirectiveName(OMPD_declare_variant), RLoc,
1390 /*IsAddressOfOperand=*/true);
1391 }
1392 if (!AssociatedFunction.isUsable()) {
1393 if (!Tok.is(tok::annot_pragma_openmp_end))
1394 while (!SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch))
1395 ;
1396 // Skip the last annot_pragma_openmp_end.
1397 (void)ConsumeAnnotationToken();
1398 return;
1399 }
1400
1401 OMPTraitInfo *ParentTI = Actions.getOMPTraitInfoForSurroundingScope();
1402 ASTContext &ASTCtx = Actions.getASTContext();
1403 OMPTraitInfo &TI = ASTCtx.getNewOMPTraitInfo();
1404 if (parseOMPDeclareVariantMatchClause(Loc, TI, ParentTI))
1405 return;
1406
1407 Optional<std::pair<FunctionDecl *, Expr *>> DeclVarData =
1408 Actions.checkOpenMPDeclareVariantFunction(
1409 Ptr, AssociatedFunction.get(), TI,
1410 SourceRange(Loc, Tok.getLocation()));
1411
1412 // Skip last tokens.
1413 while (Tok.isNot(tok::annot_pragma_openmp_end))
1414 ConsumeAnyToken();
1415 if (DeclVarData && !TI.Sets.empty())
1416 Actions.ActOnOpenMPDeclareVariantDirective(
1417 DeclVarData->first, DeclVarData->second, TI,
1418 SourceRange(Loc, Tok.getLocation()));
1419
1420 // Skip the last annot_pragma_openmp_end.
1421 (void)ConsumeAnnotationToken();
1422}
1423
1424bool Parser::parseOMPDeclareVariantMatchClause(SourceLocation Loc,
1425 OMPTraitInfo &TI,
1426 OMPTraitInfo *ParentTI) {
1427 // Parse 'match'.
1428 OpenMPClauseKind CKind = Tok.isAnnotation()
1429 ? OMPC_unknown
1430 : getOpenMPClauseKind(PP.getSpelling(Tok));
1431 if (CKind != OMPC_match) {
1432 Diag(Tok.getLocation(), diag::err_omp_declare_variant_wrong_clause)
1433 << getOpenMPClauseName(OMPC_match);
1434 while (!SkipUntil(tok::annot_pragma_openmp_end, Parser::StopBeforeMatch))
1435 ;
1436 // Skip the last annot_pragma_openmp_end.
1437 (void)ConsumeAnnotationToken();
1438 return true;
1439 }
1440 (void)ConsumeToken();
1441 // Parse '('.
1442 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
1443 if (T.expectAndConsume(diag::err_expected_lparen_after,
1444 getOpenMPClauseName(OMPC_match).data())) {
1445 while (!SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch))
1446 ;
1447 // Skip the last annot_pragma_openmp_end.
1448 (void)ConsumeAnnotationToken();
1449 return true;
1450 }
1451
1452 // Parse inner context selectors.
1453 parseOMPContextSelectors(Loc, TI);
1454
1455 // Parse ')'
1456 (void)T.consumeClose();
1457
1458 if (!ParentTI)
1459 return false;
1460
1461 // Merge the parent/outer trait info into the one we just parsed and diagnose
1462 // problems.
1463 // TODO: Keep some source location in the TI to provide better diagnostics.
1464 // TODO: Perform some kind of equivalence check on the condition and score
1465 // expressions.
1466 for (const OMPTraitSet &ParentSet : ParentTI->Sets) {
1467 bool MergedSet = false;
1468 for (OMPTraitSet &Set : TI.Sets) {
1469 if (Set.Kind != ParentSet.Kind)
1470 continue;
1471 MergedSet = true;
1472 for (const OMPTraitSelector &ParentSelector : ParentSet.Selectors) {
1473 bool MergedSelector = false;
1474 for (OMPTraitSelector &Selector : Set.Selectors) {
1475 if (Selector.Kind != ParentSelector.Kind)
1476 continue;
1477 MergedSelector = true;
1478 for (const OMPTraitProperty &ParentProperty :
1479 ParentSelector.Properties) {
1480 bool MergedProperty = false;
1481 for (OMPTraitProperty &Property : Selector.Properties) {
1482 // Ignore "equivalent" properties.
1483 if (Property.Kind != ParentProperty.Kind)
1484 continue;
1485
1486 // If the kind is the same but the raw string not, we don't want
1487 // to skip out on the property.
1488 MergedProperty |= Property.RawString == ParentProperty.RawString;
1489
1490 if (Property.RawString == ParentProperty.RawString &&
1491 Selector.ScoreOrCondition == ParentSelector.ScoreOrCondition)
1492 continue;
1493
1494 if (Selector.Kind == llvm::omp::TraitSelector::user_condition) {
1495 Diag(Loc, diag::err_omp_declare_variant_nested_user_condition);
1496 } else if (Selector.ScoreOrCondition !=
1497 ParentSelector.ScoreOrCondition) {
1498 Diag(Loc, diag::err_omp_declare_variant_duplicate_nested_trait)
1499 << getOpenMPContextTraitPropertyName(
1500 ParentProperty.Kind, ParentProperty.RawString)
1501 << getOpenMPContextTraitSelectorName(ParentSelector.Kind)
1502 << getOpenMPContextTraitSetName(ParentSet.Kind);
1503 }
1504 }
1505 if (!MergedProperty)
1506 Selector.Properties.push_back(ParentProperty);
1507 }
1508 }
1509 if (!MergedSelector)
1510 Set.Selectors.push_back(ParentSelector);
1511 }
1512 }
1513 if (!MergedSet)
1514 TI.Sets.push_back(ParentSet);
1515 }
1516
1517 return false;
1518}
1519
1520/// `omp assumes` or `omp begin/end assumes` <clause> [[,]<clause>]...
1521/// where
1522///
1523/// clause:
1524/// 'ext_IMPL_DEFINED'
1525/// 'absent' '(' directive-name [, directive-name]* ')'
1526/// 'contains' '(' directive-name [, directive-name]* ')'
1527/// 'holds' '(' scalar-expression ')'
1528/// 'no_openmp'
1529/// 'no_openmp_routines'
1530/// 'no_parallelism'
1531///
1532void Parser::ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
1533 SourceLocation Loc) {
1534 SmallVector<StringRef, 4> Assumptions;
1535 bool SkippedClauses = false;
1536
1537 auto SkipBraces = [&](llvm::StringRef Spelling, bool IssueNote) {
1538 BalancedDelimiterTracker T(*this, tok::l_paren,
1539 tok::annot_pragma_openmp_end);
1540 if (T.expectAndConsume(diag::err_expected_lparen_after, Spelling.data()))
1541 return;
1542 T.skipToEnd();
1543 if (IssueNote && T.getCloseLocation().isValid())
1544 Diag(T.getCloseLocation(),
1545 diag::note_omp_assumption_clause_continue_here);
1546 };
1547
1548 /// Helper to determine which AssumptionClauseMapping (ACM) in the
1549 /// AssumptionClauseMappings table matches \p RawString. The return value is
1550 /// the index of the matching ACM into the table or -1 if there was no match.
1551 auto MatchACMClause = [&](StringRef RawString) {
1552 llvm::StringSwitch<int> SS(RawString);
1553 unsigned ACMIdx = 0;
1554 for (const AssumptionClauseMappingInfo &ACMI : AssumptionClauseMappings) {
1555 if (ACMI.StartsWith)
1556 SS.StartsWith(ACMI.Identifier, ACMIdx++);
1557 else
1558 SS.Case(ACMI.Identifier, ACMIdx++);
1559 }
1560 return SS.Default(-1);
1561 };
1562
1563 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
1564 IdentifierInfo *II = nullptr;
1565 SourceLocation StartLoc = Tok.getLocation();
1566 int Idx = -1;
1567 if (Tok.isAnyIdentifier()) {
1568 II = Tok.getIdentifierInfo();
1569 Idx = MatchACMClause(II->getName());
1570 }
1571 ConsumeAnyToken();
1572
1573 bool NextIsLPar = Tok.is(tok::l_paren);
1574 // Handle unknown clauses by skipping them.
1575 if (Idx == -1) {
1576 Diag(StartLoc, diag::warn_omp_unknown_assumption_clause_missing_id)
1577 << llvm::omp::getOpenMPDirectiveName(DKind)
1578 << llvm::omp::getAllAssumeClauseOptions() << NextIsLPar;
1579 if (NextIsLPar)
1580 SkipBraces(II ? II->getName() : "", /* IssueNote */ true);
1581 SkippedClauses = true;
1582 continue;
1583 }
1584 const AssumptionClauseMappingInfo &ACMI = AssumptionClauseMappings[Idx];
1585 if (ACMI.HasDirectiveList || ACMI.HasExpression) {
1586 // TODO: We ignore absent, contains, and holds assumptions for now. We
1587 // also do not verify the content in the parenthesis at all.
1588 SkippedClauses = true;
1589 SkipBraces(II->getName(), /* IssueNote */ false);
1590 continue;
1591 }
1592
1593 if (NextIsLPar) {
1594 Diag(Tok.getLocation(),
1595 diag::warn_omp_unknown_assumption_clause_without_args)
1596 << II;
1597 SkipBraces(II->getName(), /* IssueNote */ true);
1598 }
1599
1600 assert(II && "Expected an identifier clause!")((II && "Expected an identifier clause!") ? static_cast
<void> (0) : __assert_fail ("II && \"Expected an identifier clause!\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 1600, __PRETTY_FUNCTION__))
;
1601 StringRef Assumption = II->getName();
1602 if (ACMI.StartsWith)
1603 Assumption = Assumption.substr(ACMI.Identifier.size());
1604 Assumptions.push_back(Assumption);
1605 }
1606
1607 Actions.ActOnOpenMPAssumesDirective(Loc, DKind, Assumptions, SkippedClauses);
1608}
1609
1610void Parser::ParseOpenMPEndAssumesDirective(SourceLocation Loc) {
1611 if (Actions.isInOpenMPAssumeScope())
1612 Actions.ActOnOpenMPEndAssumesDirective();
1613 else
1614 Diag(Loc, diag::err_expected_begin_assumes);
1615}
1616
1617/// Parsing of simple OpenMP clauses like 'default' or 'proc_bind'.
1618///
1619/// default-clause:
1620/// 'default' '(' 'none' | 'shared' | 'firstprivate' ')
1621///
1622/// proc_bind-clause:
1623/// 'proc_bind' '(' 'master' | 'close' | 'spread' ')
1624///
1625/// device_type-clause:
1626/// 'device_type' '(' 'host' | 'nohost' | 'any' )'
1627namespace {
1628struct SimpleClauseData {
1629 unsigned Type;
1630 SourceLocation Loc;
1631 SourceLocation LOpen;
1632 SourceLocation TypeLoc;
1633 SourceLocation RLoc;
1634 SimpleClauseData(unsigned Type, SourceLocation Loc, SourceLocation LOpen,
1635 SourceLocation TypeLoc, SourceLocation RLoc)
1636 : Type(Type), Loc(Loc), LOpen(LOpen), TypeLoc(TypeLoc), RLoc(RLoc) {}
1637};
1638} // anonymous namespace
1639
1640static Optional<SimpleClauseData>
1641parseOpenMPSimpleClause(Parser &P, OpenMPClauseKind Kind) {
1642 const Token &Tok = P.getCurToken();
1643 SourceLocation Loc = Tok.getLocation();
1644 SourceLocation LOpen = P.ConsumeToken();
1645 // Parse '('.
1646 BalancedDelimiterTracker T(P, tok::l_paren, tok::annot_pragma_openmp_end);
1647 if (T.expectAndConsume(diag::err_expected_lparen_after,
1648 getOpenMPClauseName(Kind).data()))
1649 return llvm::None;
1650
1651 unsigned Type = getOpenMPSimpleClauseType(
1652 Kind, Tok.isAnnotation() ? "" : P.getPreprocessor().getSpelling(Tok),
1653 P.getLangOpts().OpenMP);
1654 SourceLocation TypeLoc = Tok.getLocation();
1655 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1656 Tok.isNot(tok::annot_pragma_openmp_end))
1657 P.ConsumeAnyToken();
1658
1659 // Parse ')'.
1660 SourceLocation RLoc = Tok.getLocation();
1661 if (!T.consumeClose())
1662 RLoc = T.getCloseLocation();
1663
1664 return SimpleClauseData(Type, Loc, LOpen, TypeLoc, RLoc);
1665}
1666
1667Parser::DeclGroupPtrTy Parser::ParseOMPDeclareTargetClauses() {
1668 // OpenMP 4.5 syntax with list of entities.
1669 Sema::NamedDeclSetType SameDirectiveDecls;
1670 SmallVector<std::tuple<OMPDeclareTargetDeclAttr::MapTypeTy, SourceLocation,
1671 NamedDecl *>,
1672 4>
1673 DeclareTargetDecls;
1674 OMPDeclareTargetDeclAttr::DevTypeTy DT = OMPDeclareTargetDeclAttr::DT_Any;
1675 SourceLocation DeviceTypeLoc;
1676 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
1677 OMPDeclareTargetDeclAttr::MapTypeTy MT = OMPDeclareTargetDeclAttr::MT_To;
1678 if (Tok.is(tok::identifier)) {
1679 IdentifierInfo *II = Tok.getIdentifierInfo();
1680 StringRef ClauseName = II->getName();
1681 bool IsDeviceTypeClause =
1682 getLangOpts().OpenMP >= 50 &&
1683 getOpenMPClauseKind(ClauseName) == OMPC_device_type;
1684 // Parse 'to|link|device_type' clauses.
1685 if (!OMPDeclareTargetDeclAttr::ConvertStrToMapTypeTy(ClauseName, MT) &&
1686 !IsDeviceTypeClause) {
1687 Diag(Tok, diag::err_omp_declare_target_unexpected_clause)
1688 << ClauseName << (getLangOpts().OpenMP >= 50 ? 1 : 0);
1689 break;
1690 }
1691 // Parse 'device_type' clause and go to next clause if any.
1692 if (IsDeviceTypeClause) {
1693 Optional<SimpleClauseData> DevTypeData =
1694 parseOpenMPSimpleClause(*this, OMPC_device_type);
1695 if (DevTypeData.hasValue()) {
1696 if (DeviceTypeLoc.isValid()) {
1697 // We already saw another device_type clause, diagnose it.
1698 Diag(DevTypeData.getValue().Loc,
1699 diag::warn_omp_more_one_device_type_clause);
1700 }
1701 switch (static_cast<OpenMPDeviceType>(DevTypeData.getValue().Type)) {
1702 case OMPC_DEVICE_TYPE_any:
1703 DT = OMPDeclareTargetDeclAttr::DT_Any;
1704 break;
1705 case OMPC_DEVICE_TYPE_host:
1706 DT = OMPDeclareTargetDeclAttr::DT_Host;
1707 break;
1708 case OMPC_DEVICE_TYPE_nohost:
1709 DT = OMPDeclareTargetDeclAttr::DT_NoHost;
1710 break;
1711 case OMPC_DEVICE_TYPE_unknown:
1712 llvm_unreachable("Unexpected device_type")::llvm::llvm_unreachable_internal("Unexpected device_type", "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 1712)
;
1713 }
1714 DeviceTypeLoc = DevTypeData.getValue().Loc;
1715 }
1716 continue;
1717 }
1718 ConsumeToken();
1719 }
1720 auto &&Callback = [this, MT, &DeclareTargetDecls, &SameDirectiveDecls](
1721 CXXScopeSpec &SS, DeclarationNameInfo NameInfo) {
1722 NamedDecl *ND = Actions.lookupOpenMPDeclareTargetName(
1723 getCurScope(), SS, NameInfo, SameDirectiveDecls);
1724 if (ND)
1725 DeclareTargetDecls.emplace_back(MT, NameInfo.getLoc(), ND);
1726 };
1727 if (ParseOpenMPSimpleVarList(OMPD_declare_target, Callback,
1728 /*AllowScopeSpecifier=*/true))
1729 break;
1730
1731 // Consume optional ','.
1732 if (Tok.is(tok::comma))
1733 ConsumeToken();
1734 }
1735 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
1736 ConsumeAnyToken();
1737 for (auto &MTLocDecl : DeclareTargetDecls) {
1738 OMPDeclareTargetDeclAttr::MapTypeTy MT;
1739 SourceLocation Loc;
1740 NamedDecl *ND;
1741 std::tie(MT, Loc, ND) = MTLocDecl;
1742 // device_type clause is applied only to functions.
1743 Actions.ActOnOpenMPDeclareTargetName(
1744 ND, Loc, MT, isa<VarDecl>(ND) ? OMPDeclareTargetDeclAttr::DT_Any : DT);
1745 }
1746 SmallVector<Decl *, 4> Decls(SameDirectiveDecls.begin(),
1747 SameDirectiveDecls.end());
1748 if (Decls.empty())
1749 return DeclGroupPtrTy();
1750 return Actions.BuildDeclaratorGroup(Decls);
1751}
1752
1753void Parser::skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind) {
1754 // The last seen token is annot_pragma_openmp_end - need to check for
1755 // extra tokens.
1756 if (Tok.is(tok::annot_pragma_openmp_end))
1757 return;
1758
1759 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
1760 << getOpenMPDirectiveName(DKind);
1761 while (Tok.isNot(tok::annot_pragma_openmp_end))
1762 ConsumeAnyToken();
1763}
1764
1765void Parser::parseOMPEndDirective(OpenMPDirectiveKind BeginKind,
1766 OpenMPDirectiveKind ExpectedKind,
1767 OpenMPDirectiveKind FoundKind,
1768 SourceLocation BeginLoc,
1769 SourceLocation FoundLoc,
1770 bool SkipUntilOpenMPEnd) {
1771 int DiagSelection = ExpectedKind == OMPD_end_declare_target ? 0 : 1;
1772
1773 if (FoundKind == ExpectedKind) {
1774 ConsumeAnyToken();
1775 skipUntilPragmaOpenMPEnd(ExpectedKind);
1776 return;
1777 }
1778
1779 Diag(FoundLoc, diag::err_expected_end_declare_target_or_variant)
1780 << DiagSelection;
1781 Diag(BeginLoc, diag::note_matching)
1782 << ("'#pragma omp " + getOpenMPDirectiveName(BeginKind) + "'").str();
1783 if (SkipUntilOpenMPEnd)
1784 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
1785}
1786
1787void Parser::ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind DKind,
1788 SourceLocation DKLoc) {
1789 parseOMPEndDirective(OMPD_declare_target, OMPD_end_declare_target, DKind,
1790 DKLoc, Tok.getLocation(),
1791 /* SkipUntilOpenMPEnd */ false);
1792 // Skip the last annot_pragma_openmp_end.
1793 if (Tok.is(tok::annot_pragma_openmp_end))
1794 ConsumeAnnotationToken();
1795}
1796
1797/// Parsing of declarative OpenMP directives.
1798///
1799/// threadprivate-directive:
1800/// annot_pragma_openmp 'threadprivate' simple-variable-list
1801/// annot_pragma_openmp_end
1802///
1803/// allocate-directive:
1804/// annot_pragma_openmp 'allocate' simple-variable-list [<clause>]
1805/// annot_pragma_openmp_end
1806///
1807/// declare-reduction-directive:
1808/// annot_pragma_openmp 'declare' 'reduction' [...]
1809/// annot_pragma_openmp_end
1810///
1811/// declare-mapper-directive:
1812/// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifer> ':']
1813/// <type> <var> ')' [<clause>[[,] <clause>] ... ]
1814/// annot_pragma_openmp_end
1815///
1816/// declare-simd-directive:
1817/// annot_pragma_openmp 'declare simd' {<clause> [,]}
1818/// annot_pragma_openmp_end
1819/// <function declaration/definition>
1820///
1821/// requires directive:
1822/// annot_pragma_openmp 'requires' <clause> [[[,] <clause>] ... ]
1823/// annot_pragma_openmp_end
1824///
1825/// assumes directive:
1826/// annot_pragma_openmp 'assumes' <clause> [[[,] <clause>] ... ]
1827/// annot_pragma_openmp_end
1828/// or
1829/// annot_pragma_openmp 'begin assumes' <clause> [[[,] <clause>] ... ]
1830/// annot_pragma_openmp 'end assumes'
1831/// annot_pragma_openmp_end
1832///
1833Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
1834 AccessSpecifier &AS, ParsedAttributesWithRange &Attrs, bool Delayed,
1835 DeclSpec::TST TagType, Decl *Tag) {
1836 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!")((Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"
) ? static_cast<void> (0) : __assert_fail ("Tok.is(tok::annot_pragma_openmp) && \"Not an OpenMP directive!\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 1836, __PRETTY_FUNCTION__))
;
1837 ParsingOpenMPDirectiveRAII DirScope(*this);
1838 ParenBraceBracketBalancer BalancerRAIIObj(*this);
1839
1840 SourceLocation Loc;
1841 OpenMPDirectiveKind DKind;
1842 if (Delayed) {
1843 TentativeParsingAction TPA(*this);
1844 Loc = ConsumeAnnotationToken();
1845 DKind = parseOpenMPDirectiveKind(*this);
1846 if (DKind == OMPD_declare_reduction || DKind == OMPD_declare_mapper) {
1847 // Need to delay parsing until completion of the parent class.
1848 TPA.Revert();
1849 CachedTokens Toks;
1850 unsigned Cnt = 1;
1851 Toks.push_back(Tok);
1852 while (Cnt && Tok.isNot(tok::eof)) {
1853 (void)ConsumeAnyToken();
1854 if (Tok.is(tok::annot_pragma_openmp))
1855 ++Cnt;
1856 else if (Tok.is(tok::annot_pragma_openmp_end))
1857 --Cnt;
1858 Toks.push_back(Tok);
1859 }
1860 // Skip last annot_pragma_openmp_end.
1861 if (Cnt == 0)
1862 (void)ConsumeAnyToken();
1863 auto *LP = new LateParsedPragma(this, AS);
1864 LP->takeToks(Toks);
1865 getCurrentClass().LateParsedDeclarations.push_back(LP);
1866 return nullptr;
1867 }
1868 TPA.Commit();
1869 } else {
1870 Loc = ConsumeAnnotationToken();
1871 DKind = parseOpenMPDirectiveKind(*this);
1872 }
1873
1874 switch (DKind) {
1875 case OMPD_threadprivate: {
1876 ConsumeToken();
1877 DeclDirectiveListParserHelper Helper(this, DKind);
1878 if (!ParseOpenMPSimpleVarList(DKind, Helper,
1879 /*AllowScopeSpecifier=*/true)) {
1880 skipUntilPragmaOpenMPEnd(DKind);
1881 // Skip the last annot_pragma_openmp_end.
1882 ConsumeAnnotationToken();
1883 return Actions.ActOnOpenMPThreadprivateDirective(Loc,
1884 Helper.getIdentifiers());
1885 }
1886 break;
1887 }
1888 case OMPD_allocate: {
1889 ConsumeToken();
1890 DeclDirectiveListParserHelper Helper(this, DKind);
1891 if (!ParseOpenMPSimpleVarList(DKind, Helper,
1892 /*AllowScopeSpecifier=*/true)) {
1893 SmallVector<OMPClause *, 1> Clauses;
1894 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
1895 SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>,
1896 llvm::omp::Clause_enumSize + 1>
1897 FirstClauses(llvm::omp::Clause_enumSize + 1);
1898 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
1899 OpenMPClauseKind CKind =
1900 Tok.isAnnotation() ? OMPC_unknown
1901 : getOpenMPClauseKind(PP.getSpelling(Tok));
1902 Actions.StartOpenMPClause(CKind);
1903 OMPClause *Clause = ParseOpenMPClause(
1904 OMPD_allocate, CKind, !FirstClauses[unsigned(CKind)].getInt());
1905 SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end,
1906 StopBeforeMatch);
1907 FirstClauses[unsigned(CKind)].setInt(true);
1908 if (Clause != nullptr)
1909 Clauses.push_back(Clause);
1910 if (Tok.is(tok::annot_pragma_openmp_end)) {
1911 Actions.EndOpenMPClause();
1912 break;
1913 }
1914 // Skip ',' if any.
1915 if (Tok.is(tok::comma))
1916 ConsumeToken();
1917 Actions.EndOpenMPClause();
1918 }
1919 skipUntilPragmaOpenMPEnd(DKind);
1920 }
1921 // Skip the last annot_pragma_openmp_end.
1922 ConsumeAnnotationToken();
1923 return Actions.ActOnOpenMPAllocateDirective(Loc, Helper.getIdentifiers(),
1924 Clauses);
1925 }
1926 break;
1927 }
1928 case OMPD_requires: {
1929 SourceLocation StartLoc = ConsumeToken();
1930 SmallVector<OMPClause *, 5> Clauses;
1931 SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>,
1932 llvm::omp::Clause_enumSize + 1>
1933 FirstClauses(llvm::omp::Clause_enumSize + 1);
1934 if (Tok.is(tok::annot_pragma_openmp_end)) {
1935 Diag(Tok, diag::err_omp_expected_clause)
1936 << getOpenMPDirectiveName(OMPD_requires);
1937 break;
1938 }
1939 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
1940 OpenMPClauseKind CKind = Tok.isAnnotation()
1941 ? OMPC_unknown
1942 : getOpenMPClauseKind(PP.getSpelling(Tok));
1943 Actions.StartOpenMPClause(CKind);
1944 OMPClause *Clause = ParseOpenMPClause(
1945 OMPD_requires, CKind, !FirstClauses[unsigned(CKind)].getInt());
1946 SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end,
1947 StopBeforeMatch);
1948 FirstClauses[unsigned(CKind)].setInt(true);
1949 if (Clause != nullptr)
1950 Clauses.push_back(Clause);
1951 if (Tok.is(tok::annot_pragma_openmp_end)) {
1952 Actions.EndOpenMPClause();
1953 break;
1954 }
1955 // Skip ',' if any.
1956 if (Tok.is(tok::comma))
1957 ConsumeToken();
1958 Actions.EndOpenMPClause();
1959 }
1960 // Consume final annot_pragma_openmp_end
1961 if (Clauses.empty()) {
1962 Diag(Tok, diag::err_omp_expected_clause)
1963 << getOpenMPDirectiveName(OMPD_requires);
1964 ConsumeAnnotationToken();
1965 return nullptr;
1966 }
1967 ConsumeAnnotationToken();
1968 return Actions.ActOnOpenMPRequiresDirective(StartLoc, Clauses);
1969 }
1970 case OMPD_assumes:
1971 case OMPD_begin_assumes:
1972 ParseOpenMPAssumesDirective(DKind, ConsumeToken());
1973 break;
1974 case OMPD_end_assumes:
1975 ParseOpenMPEndAssumesDirective(ConsumeToken());
1976 break;
1977 case OMPD_declare_reduction:
1978 ConsumeToken();
1979 if (DeclGroupPtrTy Res = ParseOpenMPDeclareReductionDirective(AS)) {
1980 skipUntilPragmaOpenMPEnd(OMPD_declare_reduction);
1981 // Skip the last annot_pragma_openmp_end.
1982 ConsumeAnnotationToken();
1983 return Res;
1984 }
1985 break;
1986 case OMPD_declare_mapper: {
1987 ConsumeToken();
1988 if (DeclGroupPtrTy Res = ParseOpenMPDeclareMapperDirective(AS)) {
1989 // Skip the last annot_pragma_openmp_end.
1990 ConsumeAnnotationToken();
1991 return Res;
1992 }
1993 break;
1994 }
1995 case OMPD_begin_declare_variant: {
1996 // The syntax is:
1997 // { #pragma omp begin declare variant clause }
1998 // <function-declaration-or-definition-sequence>
1999 // { #pragma omp end declare variant }
2000 //
2001 ConsumeToken();
2002 OMPTraitInfo *ParentTI = Actions.getOMPTraitInfoForSurroundingScope();
2003 ASTContext &ASTCtx = Actions.getASTContext();
2004 OMPTraitInfo &TI = ASTCtx.getNewOMPTraitInfo();
2005 if (parseOMPDeclareVariantMatchClause(Loc, TI, ParentTI))
2006 break;
2007
2008 // Skip last tokens.
2009 skipUntilPragmaOpenMPEnd(OMPD_begin_declare_variant);
2010
2011 ParsingOpenMPDirectiveRAII NormalScope(*this, /*Value=*/false);
2012
2013 VariantMatchInfo VMI;
2014 TI.getAsVariantMatchInfo(ASTCtx, VMI);
2015
2016 std::function<void(StringRef)> DiagUnknownTrait = [this, Loc](
2017 StringRef ISATrait) {
2018 // TODO Track the selector locations in a way that is accessible here to
2019 // improve the diagnostic location.
2020 Diag(Loc, diag::warn_unknown_begin_declare_variant_isa_trait) << ISATrait;
2021 };
2022 TargetOMPContext OMPCtx(ASTCtx, std::move(DiagUnknownTrait),
2023 /* CurrentFunctionDecl */ nullptr);
2024
2025 if (isVariantApplicableInContext(VMI, OMPCtx, /* DeviceSetOnly */ true)) {
2026 Actions.ActOnOpenMPBeginDeclareVariant(Loc, TI);
2027 break;
2028 }
2029
2030 // Elide all the code till the matching end declare variant was found.
2031 unsigned Nesting = 1;
2032 SourceLocation DKLoc;
2033 OpenMPDirectiveKind DK = OMPD_unknown;
2034 do {
2035 DKLoc = Tok.getLocation();
2036 DK = parseOpenMPDirectiveKind(*this);
2037 if (DK == OMPD_end_declare_variant)
2038 --Nesting;
2039 else if (DK == OMPD_begin_declare_variant)
2040 ++Nesting;
2041 if (!Nesting || isEofOrEom())
2042 break;
2043 ConsumeAnyToken();
2044 } while (true);
2045
2046 parseOMPEndDirective(OMPD_begin_declare_variant, OMPD_end_declare_variant,
2047 DK, Loc, DKLoc, /* SkipUntilOpenMPEnd */ true);
2048 if (isEofOrEom())
2049 return nullptr;
2050 break;
2051 }
2052 case OMPD_end_declare_variant: {
2053 if (Actions.isInOpenMPDeclareVariantScope())
2054 Actions.ActOnOpenMPEndDeclareVariant();
2055 else
2056 Diag(Loc, diag::err_expected_begin_declare_variant);
2057 ConsumeToken();
2058 break;
2059 }
2060 case OMPD_declare_variant:
2061 case OMPD_declare_simd: {
2062 // The syntax is:
2063 // { #pragma omp declare {simd|variant} }
2064 // <function-declaration-or-definition>
2065 //
2066 CachedTokens Toks;
2067 Toks.push_back(Tok);
2068 ConsumeToken();
2069 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
2070 Toks.push_back(Tok);
2071 ConsumeAnyToken();
2072 }
2073 Toks.push_back(Tok);
2074 ConsumeAnyToken();
2075
2076 DeclGroupPtrTy Ptr;
2077 if (Tok.is(tok::annot_pragma_openmp)) {
2078 Ptr = ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs, Delayed,
2079 TagType, Tag);
2080 } else if (Tok.isNot(tok::r_brace) && !isEofOrEom()) {
2081 // Here we expect to see some function declaration.
2082 if (AS == AS_none) {
2083 assert(TagType == DeclSpec::TST_unspecified)((TagType == DeclSpec::TST_unspecified) ? static_cast<void
> (0) : __assert_fail ("TagType == DeclSpec::TST_unspecified"
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 2083, __PRETTY_FUNCTION__))
;
2084 MaybeParseCXX11Attributes(Attrs);
2085 ParsingDeclSpec PDS(*this);
2086 Ptr = ParseExternalDeclaration(Attrs, &PDS);
2087 } else {
2088 Ptr =
2089 ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag);
2090 }
2091 }
2092 if (!Ptr) {
2093 Diag(Loc, diag::err_omp_decl_in_declare_simd_variant)
2094 << (DKind == OMPD_declare_simd ? 0 : 1);
2095 return DeclGroupPtrTy();
2096 }
2097 if (DKind == OMPD_declare_simd)
2098 return ParseOMPDeclareSimdClauses(Ptr, Toks, Loc);
2099 assert(DKind == OMPD_declare_variant &&((DKind == OMPD_declare_variant && "Expected declare variant directive only"
) ? static_cast<void> (0) : __assert_fail ("DKind == OMPD_declare_variant && \"Expected declare variant directive only\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 2100, __PRETTY_FUNCTION__))
2100 "Expected declare variant directive only")((DKind == OMPD_declare_variant && "Expected declare variant directive only"
) ? static_cast<void> (0) : __assert_fail ("DKind == OMPD_declare_variant && \"Expected declare variant directive only\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 2100, __PRETTY_FUNCTION__))
;
2101 ParseOMPDeclareVariantClauses(Ptr, Toks, Loc);
2102 return Ptr;
2103 }
2104 case OMPD_declare_target: {
2105 SourceLocation DTLoc = ConsumeAnyToken();
2106 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
2107 return ParseOMPDeclareTargetClauses();
2108 }
2109
2110 // Skip the last annot_pragma_openmp_end.
2111 ConsumeAnyToken();
2112
2113 if (!Actions.ActOnStartOpenMPDeclareTargetDirective(DTLoc))
2114 return DeclGroupPtrTy();
2115
2116 ParsingOpenMPDirectiveRAII NormalScope(*this, /*Value=*/false);
2117 llvm::SmallVector<Decl *, 4> Decls;
2118 DKind = parseOpenMPDirectiveKind(*this);
2119 while (DKind != OMPD_end_declare_target && Tok.isNot(tok::eof) &&
2120 Tok.isNot(tok::r_brace)) {
2121 DeclGroupPtrTy Ptr;
2122 // Here we expect to see some function declaration.
2123 if (AS == AS_none) {
2124 assert(TagType == DeclSpec::TST_unspecified)((TagType == DeclSpec::TST_unspecified) ? static_cast<void
> (0) : __assert_fail ("TagType == DeclSpec::TST_unspecified"
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 2124, __PRETTY_FUNCTION__))
;
2125 MaybeParseCXX11Attributes(Attrs);
2126 ParsingDeclSpec PDS(*this);
2127 Ptr = ParseExternalDeclaration(Attrs, &PDS);
2128 } else {
2129 Ptr =
2130 ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag);
2131 }
2132 if (Ptr) {
2133 DeclGroupRef Ref = Ptr.get();
2134 Decls.append(Ref.begin(), Ref.end());
2135 }
2136 if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
2137 TentativeParsingAction TPA(*this);
2138 ConsumeAnnotationToken();
2139 DKind = parseOpenMPDirectiveKind(*this);
2140 if (DKind != OMPD_end_declare_target)
2141 TPA.Revert();
2142 else
2143 TPA.Commit();
2144 }
2145 }
2146
2147 ParseOMPEndDeclareTargetDirective(DKind, DTLoc);
2148 Actions.ActOnFinishOpenMPDeclareTargetDirective();
2149 return Actions.BuildDeclaratorGroup(Decls);
2150 }
2151 case OMPD_unknown:
2152 Diag(Tok, diag::err_omp_unknown_directive);
2153 break;
2154 case OMPD_parallel:
2155 case OMPD_simd:
2156 case OMPD_tile:
2157 case OMPD_task:
2158 case OMPD_taskyield:
2159 case OMPD_barrier:
2160 case OMPD_taskwait:
2161 case OMPD_taskgroup:
2162 case OMPD_flush:
2163 case OMPD_depobj:
2164 case OMPD_scan:
2165 case OMPD_for:
2166 case OMPD_for_simd:
2167 case OMPD_sections:
2168 case OMPD_section:
2169 case OMPD_single:
2170 case OMPD_master:
2171 case OMPD_ordered:
2172 case OMPD_critical:
2173 case OMPD_parallel_for:
2174 case OMPD_parallel_for_simd:
2175 case OMPD_parallel_sections:
2176 case OMPD_parallel_master:
2177 case OMPD_atomic:
2178 case OMPD_target:
2179 case OMPD_teams:
2180 case OMPD_cancellation_point:
2181 case OMPD_cancel:
2182 case OMPD_target_data:
2183 case OMPD_target_enter_data:
2184 case OMPD_target_exit_data:
2185 case OMPD_target_parallel:
2186 case OMPD_target_parallel_for:
2187 case OMPD_taskloop:
2188 case OMPD_taskloop_simd:
2189 case OMPD_master_taskloop:
2190 case OMPD_master_taskloop_simd:
2191 case OMPD_parallel_master_taskloop:
2192 case OMPD_parallel_master_taskloop_simd:
2193 case OMPD_distribute:
2194 case OMPD_end_declare_target:
2195 case OMPD_target_update:
2196 case OMPD_distribute_parallel_for:
2197 case OMPD_distribute_parallel_for_simd:
2198 case OMPD_distribute_simd:
2199 case OMPD_target_parallel_for_simd:
2200 case OMPD_target_simd:
2201 case OMPD_teams_distribute:
2202 case OMPD_teams_distribute_simd:
2203 case OMPD_teams_distribute_parallel_for_simd:
2204 case OMPD_teams_distribute_parallel_for:
2205 case OMPD_target_teams:
2206 case OMPD_target_teams_distribute:
2207 case OMPD_target_teams_distribute_parallel_for:
2208 case OMPD_target_teams_distribute_parallel_for_simd:
2209 case OMPD_target_teams_distribute_simd:
2210 Diag(Tok, diag::err_omp_unexpected_directive)
2211 << 1 << getOpenMPDirectiveName(DKind);
2212 break;
2213 default:
2214 break;
2215 }
2216 while (Tok.isNot(tok::annot_pragma_openmp_end))
2217 ConsumeAnyToken();
2218 ConsumeAnyToken();
2219 return nullptr;
2220}
2221
2222/// Parsing of declarative or executable OpenMP directives.
2223///
2224/// threadprivate-directive:
2225/// annot_pragma_openmp 'threadprivate' simple-variable-list
2226/// annot_pragma_openmp_end
2227///
2228/// allocate-directive:
2229/// annot_pragma_openmp 'allocate' simple-variable-list
2230/// annot_pragma_openmp_end
2231///
2232/// declare-reduction-directive:
2233/// annot_pragma_openmp 'declare' 'reduction' '(' <reduction_id> ':'
2234/// <type> {',' <type>} ':' <expression> ')' ['initializer' '('
2235/// ('omp_priv' '=' <expression>|<function_call>) ')']
2236/// annot_pragma_openmp_end
2237///
2238/// declare-mapper-directive:
2239/// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifer> ':']
2240/// <type> <var> ')' [<clause>[[,] <clause>] ... ]
2241/// annot_pragma_openmp_end
2242///
2243/// executable-directive:
2244/// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' |
2245/// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] |
2246/// 'parallel for' | 'parallel sections' | 'parallel master' | 'task' |
2247/// 'taskyield' | 'barrier' | 'taskwait' | 'flush' | 'ordered' |
2248/// 'atomic' | 'for simd' | 'parallel for simd' | 'target' | 'target
2249/// data' | 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' |
2250/// 'master taskloop' | 'master taskloop simd' | 'parallel master
2251/// taskloop' | 'parallel master taskloop simd' | 'distribute' | 'target
2252/// enter data' | 'target exit data' | 'target parallel' | 'target
2253/// parallel for' | 'target update' | 'distribute parallel for' |
2254/// 'distribute paralle for simd' | 'distribute simd' | 'target parallel
2255/// for simd' | 'target simd' | 'teams distribute' | 'teams distribute
2256/// simd' | 'teams distribute parallel for simd' | 'teams distribute
2257/// parallel for' | 'target teams' | 'target teams distribute' | 'target
2258/// teams distribute parallel for' | 'target teams distribute parallel
2259/// for simd' | 'target teams distribute simd' {clause}
2260/// annot_pragma_openmp_end
2261///
2262StmtResult
2263Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) {
2264 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!")((Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"
) ? static_cast<void> (0) : __assert_fail ("Tok.is(tok::annot_pragma_openmp) && \"Not an OpenMP directive!\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 2264, __PRETTY_FUNCTION__))
;
2265 ParsingOpenMPDirectiveRAII DirScope(*this);
2266 ParenBraceBracketBalancer BalancerRAIIObj(*this);
2267 SmallVector<OMPClause *, 5> Clauses;
2268 SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>,
2269 llvm::omp::Clause_enumSize + 1>
2270 FirstClauses(llvm::omp::Clause_enumSize + 1);
2271 unsigned ScopeFlags = Scope::FnScope | Scope::DeclScope |
2272 Scope::CompoundStmtScope | Scope::OpenMPDirectiveScope;
2273 SourceLocation Loc = ConsumeAnnotationToken(), EndLoc;
2274 OpenMPDirectiveKind DKind = parseOpenMPDirectiveKind(*this);
2275 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
2276 // Name of critical directive.
2277 DeclarationNameInfo DirName;
2278 StmtResult Directive = StmtError();
2279 bool HasAssociatedStatement = true;
2280
2281 switch (DKind) {
2282 case OMPD_threadprivate: {
2283 // FIXME: Should this be permitted in C++?
2284 if ((StmtCtx & ParsedStmtContext::AllowDeclarationsInC) ==
2285 ParsedStmtContext()) {
2286 Diag(Tok, diag::err_omp_immediate_directive)
2287 << getOpenMPDirectiveName(DKind) << 0;
2288 }
2289 ConsumeToken();
2290 DeclDirectiveListParserHelper Helper(this, DKind);
2291 if (!ParseOpenMPSimpleVarList(DKind, Helper,
2292 /*AllowScopeSpecifier=*/false)) {
2293 skipUntilPragmaOpenMPEnd(DKind);
2294 DeclGroupPtrTy Res = Actions.ActOnOpenMPThreadprivateDirective(
2295 Loc, Helper.getIdentifiers());
2296 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
2297 }
2298 SkipUntil(tok::annot_pragma_openmp_end);
2299 break;
2300 }
2301 case OMPD_allocate: {
2302 // FIXME: Should this be permitted in C++?
2303 if ((StmtCtx & ParsedStmtContext::AllowDeclarationsInC) ==
2304 ParsedStmtContext()) {
2305 Diag(Tok, diag::err_omp_immediate_directive)
2306 << getOpenMPDirectiveName(DKind) << 0;
2307 }
2308 ConsumeToken();
2309 DeclDirectiveListParserHelper Helper(this, DKind);
2310 if (!ParseOpenMPSimpleVarList(DKind, Helper,
2311 /*AllowScopeSpecifier=*/false)) {
2312 SmallVector<OMPClause *, 1> Clauses;
2313 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
2314 SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>,
2315 llvm::omp::Clause_enumSize + 1>
2316 FirstClauses(llvm::omp::Clause_enumSize + 1);
2317 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
2318 OpenMPClauseKind CKind =
2319 Tok.isAnnotation() ? OMPC_unknown
2320 : getOpenMPClauseKind(PP.getSpelling(Tok));
2321 Actions.StartOpenMPClause(CKind);
2322 OMPClause *Clause = ParseOpenMPClause(
2323 OMPD_allocate, CKind, !FirstClauses[unsigned(CKind)].getInt());
2324 SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end,
2325 StopBeforeMatch);
2326 FirstClauses[unsigned(CKind)].setInt(true);
2327 if (Clause != nullptr)
2328 Clauses.push_back(Clause);
2329 if (Tok.is(tok::annot_pragma_openmp_end)) {
2330 Actions.EndOpenMPClause();
2331 break;
2332 }
2333 // Skip ',' if any.
2334 if (Tok.is(tok::comma))
2335 ConsumeToken();
2336 Actions.EndOpenMPClause();
2337 }
2338 skipUntilPragmaOpenMPEnd(DKind);
2339 }
2340 DeclGroupPtrTy Res = Actions.ActOnOpenMPAllocateDirective(
2341 Loc, Helper.getIdentifiers(), Clauses);
2342 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
2343 }
2344 SkipUntil(tok::annot_pragma_openmp_end);
2345 break;
2346 }
2347 case OMPD_declare_reduction:
2348 ConsumeToken();
2349 if (DeclGroupPtrTy Res =
2350 ParseOpenMPDeclareReductionDirective(/*AS=*/AS_none)) {
2351 skipUntilPragmaOpenMPEnd(OMPD_declare_reduction);
2352 ConsumeAnyToken();
2353 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
2354 } else {
2355 SkipUntil(tok::annot_pragma_openmp_end);
2356 }
2357 break;
2358 case OMPD_declare_mapper: {
2359 ConsumeToken();
2360 if (DeclGroupPtrTy Res =
2361 ParseOpenMPDeclareMapperDirective(/*AS=*/AS_none)) {
2362 // Skip the last annot_pragma_openmp_end.
2363 ConsumeAnnotationToken();
2364 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
2365 } else {
2366 SkipUntil(tok::annot_pragma_openmp_end);
2367 }
2368 break;
2369 }
2370 case OMPD_flush:
2371 case OMPD_depobj:
2372 case OMPD_scan:
2373 case OMPD_taskyield:
2374 case OMPD_barrier:
2375 case OMPD_taskwait:
2376 case OMPD_cancellation_point:
2377 case OMPD_cancel:
2378 case OMPD_target_enter_data:
2379 case OMPD_target_exit_data:
2380 case OMPD_target_update:
2381 if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) ==
2382 ParsedStmtContext()) {
2383 Diag(Tok, diag::err_omp_immediate_directive)
2384 << getOpenMPDirectiveName(DKind) << 0;
2385 }
2386 HasAssociatedStatement = false;
2387 // Fall through for further analysis.
2388 LLVM_FALLTHROUGH[[gnu::fallthrough]];
2389 case OMPD_parallel:
2390 case OMPD_simd:
2391 case OMPD_tile:
2392 case OMPD_for:
2393 case OMPD_for_simd:
2394 case OMPD_sections:
2395 case OMPD_single:
2396 case OMPD_section:
2397 case OMPD_master:
2398 case OMPD_critical:
2399 case OMPD_parallel_for:
2400 case OMPD_parallel_for_simd:
2401 case OMPD_parallel_sections:
2402 case OMPD_parallel_master:
2403 case OMPD_task:
2404 case OMPD_ordered:
2405 case OMPD_atomic:
2406 case OMPD_target:
2407 case OMPD_teams:
2408 case OMPD_taskgroup:
2409 case OMPD_target_data:
2410 case OMPD_target_parallel:
2411 case OMPD_target_parallel_for:
2412 case OMPD_taskloop:
2413 case OMPD_taskloop_simd:
2414 case OMPD_master_taskloop:
2415 case OMPD_master_taskloop_simd:
2416 case OMPD_parallel_master_taskloop:
2417 case OMPD_parallel_master_taskloop_simd:
2418 case OMPD_distribute:
2419 case OMPD_distribute_parallel_for:
2420 case OMPD_distribute_parallel_for_simd:
2421 case OMPD_distribute_simd:
2422 case OMPD_target_parallel_for_simd:
2423 case OMPD_target_simd:
2424 case OMPD_teams_distribute:
2425 case OMPD_teams_distribute_simd:
2426 case OMPD_teams_distribute_parallel_for_simd:
2427 case OMPD_teams_distribute_parallel_for:
2428 case OMPD_target_teams:
2429 case OMPD_target_teams_distribute:
2430 case OMPD_target_teams_distribute_parallel_for:
2431 case OMPD_target_teams_distribute_parallel_for_simd:
2432 case OMPD_target_teams_distribute_simd: {
2433 // Special processing for flush and depobj clauses.
2434 Token ImplicitTok;
2435 bool ImplicitClauseAllowed = false;
2436 if (DKind == OMPD_flush || DKind == OMPD_depobj) {
2437 ImplicitTok = Tok;
2438 ImplicitClauseAllowed = true;
2439 }
2440 ConsumeToken();
2441 // Parse directive name of the 'critical' directive if any.
2442 if (DKind == OMPD_critical) {
2443 BalancedDelimiterTracker T(*this, tok::l_paren,
2444 tok::annot_pragma_openmp_end);
2445 if (!T.consumeOpen()) {
2446 if (Tok.isAnyIdentifier()) {
2447 DirName =
2448 DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation());
2449 ConsumeAnyToken();
2450 } else {
2451 Diag(Tok, diag::err_omp_expected_identifier_for_critical);
2452 }
2453 T.consumeClose();
2454 }
2455 } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) {
2456 CancelRegion = parseOpenMPDirectiveKind(*this);
2457 if (Tok.isNot(tok::annot_pragma_openmp_end))
2458 ConsumeToken();
2459 }
2460
2461 if (isOpenMPLoopDirective(DKind))
2462 ScopeFlags |= Scope::OpenMPLoopDirectiveScope;
2463 if (isOpenMPSimdDirective(DKind))
2464 ScopeFlags |= Scope::OpenMPSimdDirectiveScope;
2465 ParseScope OMPDirectiveScope(this, ScopeFlags);
2466 Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc);
2467
2468 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
2469 bool HasImplicitClause = false;
2470 if (ImplicitClauseAllowed && Tok.is(tok::l_paren)) {
2471 HasImplicitClause = true;
2472 // Push copy of the current token back to stream to properly parse
2473 // pseudo-clause OMPFlushClause or OMPDepobjClause.
2474 PP.EnterToken(Tok, /*IsReinject*/ true);
2475 PP.EnterToken(ImplicitTok, /*IsReinject*/ true);
2476 ConsumeAnyToken();
2477 }
2478 OpenMPClauseKind CKind = Tok.isAnnotation()
2479 ? OMPC_unknown
2480 : getOpenMPClauseKind(PP.getSpelling(Tok));
2481 if (HasImplicitClause) {
2482 assert(CKind == OMPC_unknown && "Must be unknown implicit clause.")((CKind == OMPC_unknown && "Must be unknown implicit clause."
) ? static_cast<void> (0) : __assert_fail ("CKind == OMPC_unknown && \"Must be unknown implicit clause.\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 2482, __PRETTY_FUNCTION__))
;
2483 if (DKind == OMPD_flush) {
2484 CKind = OMPC_flush;
2485 } else {
2486 assert(DKind == OMPD_depobj &&((DKind == OMPD_depobj && "Expected flush or depobj directives."
) ? static_cast<void> (0) : __assert_fail ("DKind == OMPD_depobj && \"Expected flush or depobj directives.\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 2487, __PRETTY_FUNCTION__))
2487 "Expected flush or depobj directives.")((DKind == OMPD_depobj && "Expected flush or depobj directives."
) ? static_cast<void> (0) : __assert_fail ("DKind == OMPD_depobj && \"Expected flush or depobj directives.\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 2487, __PRETTY_FUNCTION__))
;
2488 CKind = OMPC_depobj;
2489 }
2490 }
2491 // No more implicit clauses allowed.
2492 ImplicitClauseAllowed = false;
2493 Actions.StartOpenMPClause(CKind);
2494 HasImplicitClause = false;
Value stored to 'HasImplicitClause' is never read
2495 OMPClause *Clause = ParseOpenMPClause(
2496 DKind, CKind, !FirstClauses[unsigned(CKind)].getInt());
2497 FirstClauses[unsigned(CKind)].setInt(true);
2498 if (Clause) {
2499 FirstClauses[unsigned(CKind)].setPointer(Clause);
2500 Clauses.push_back(Clause);
2501 }
2502
2503 // Skip ',' if any.
2504 if (Tok.is(tok::comma))
2505 ConsumeToken();
2506 Actions.EndOpenMPClause();
2507 }
2508 // End location of the directive.
2509 EndLoc = Tok.getLocation();
2510 // Consume final annot_pragma_openmp_end.
2511 ConsumeAnnotationToken();
2512
2513 // OpenMP [2.13.8, ordered Construct, Syntax]
2514 // If the depend clause is specified, the ordered construct is a stand-alone
2515 // directive.
2516 if (DKind == OMPD_ordered && FirstClauses[unsigned(OMPC_depend)].getInt()) {
2517 if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) ==
2518 ParsedStmtContext()) {
2519 Diag(Loc, diag::err_omp_immediate_directive)
2520 << getOpenMPDirectiveName(DKind) << 1
2521 << getOpenMPClauseName(OMPC_depend);
2522 }
2523 HasAssociatedStatement = false;
2524 }
2525
2526 if (DKind == OMPD_tile && !FirstClauses[unsigned(OMPC_sizes)].getInt()) {
2527 Diag(Loc, diag::err_omp_required_clause)
2528 << getOpenMPDirectiveName(OMPD_tile) << "sizes";
2529 }
2530
2531 StmtResult AssociatedStmt;
2532 if (HasAssociatedStatement) {
2533 // The body is a block scope like in Lambdas and Blocks.
2534 Actions.ActOnOpenMPRegionStart(DKind, getCurScope());
2535 // FIXME: We create a bogus CompoundStmt scope to hold the contents of
2536 // the captured region. Code elsewhere assumes that any FunctionScopeInfo
2537 // should have at least one compound statement scope within it.
2538 ParsingOpenMPDirectiveRAII NormalScope(*this, /*Value=*/false);
2539 {
2540 Sema::CompoundScopeRAII Scope(Actions);
2541 AssociatedStmt = ParseStatement();
2542
2543 if (AssociatedStmt.isUsable() && isOpenMPLoopDirective(DKind) &&
2544 getLangOpts().OpenMPIRBuilder)
2545 AssociatedStmt =
2546 Actions.ActOnOpenMPCanonicalLoop(AssociatedStmt.get());
2547 }
2548 AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
2549 } else if (DKind == OMPD_target_update || DKind == OMPD_target_enter_data ||
2550 DKind == OMPD_target_exit_data) {
2551 Actions.ActOnOpenMPRegionStart(DKind, getCurScope());
2552 AssociatedStmt = (Sema::CompoundScopeRAII(Actions),
2553 Actions.ActOnCompoundStmt(Loc, Loc, llvm::None,
2554 /*isStmtExpr=*/false));
2555 AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
2556 }
2557 Directive = Actions.ActOnOpenMPExecutableDirective(
2558 DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc,
2559 EndLoc);
2560
2561 // Exit scope.
2562 Actions.EndOpenMPDSABlock(Directive.get());
2563 OMPDirectiveScope.Exit();
2564 break;
2565 }
2566 case OMPD_declare_simd:
2567 case OMPD_declare_target:
2568 case OMPD_end_declare_target:
2569 case OMPD_requires:
2570 case OMPD_begin_declare_variant:
2571 case OMPD_end_declare_variant:
2572 case OMPD_declare_variant:
2573 Diag(Tok, diag::err_omp_unexpected_directive)
2574 << 1 << getOpenMPDirectiveName(DKind);
2575 SkipUntil(tok::annot_pragma_openmp_end);
2576 break;
2577 case OMPD_unknown:
2578 default:
2579 Diag(Tok, diag::err_omp_unknown_directive);
2580 SkipUntil(tok::annot_pragma_openmp_end);
2581 break;
2582 }
2583 return Directive;
2584}
2585
2586// Parses simple list:
2587// simple-variable-list:
2588// '(' id-expression {, id-expression} ')'
2589//
2590bool Parser::ParseOpenMPSimpleVarList(
2591 OpenMPDirectiveKind Kind,
2592 const llvm::function_ref<void(CXXScopeSpec &, DeclarationNameInfo)>
2593 &Callback,
2594 bool AllowScopeSpecifier) {
2595 // Parse '('.
2596 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
2597 if (T.expectAndConsume(diag::err_expected_lparen_after,
2598 getOpenMPDirectiveName(Kind).data()))
2599 return true;
2600 bool IsCorrect = true;
2601 bool NoIdentIsFound = true;
2602
2603 // Read tokens while ')' or annot_pragma_openmp_end is not found.
2604 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
2605 CXXScopeSpec SS;
2606 UnqualifiedId Name;
2607 // Read var name.
2608 Token PrevTok = Tok;
2609 NoIdentIsFound = false;
2610
2611 if (AllowScopeSpecifier && getLangOpts().CPlusPlus &&
2612 ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr,
2613 /*ObjectHadErrors=*/false, false)) {
2614 IsCorrect = false;
2615 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
2616 StopBeforeMatch);
2617 } else if (ParseUnqualifiedId(SS, /*ObjectType=*/nullptr,
2618 /*ObjectHadErrors=*/false, false, false,
2619 false, false, nullptr, Name)) {
2620 IsCorrect = false;
2621 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
2622 StopBeforeMatch);
2623 } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) &&
2624 Tok.isNot(tok::annot_pragma_openmp_end)) {
2625 IsCorrect = false;
2626 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
2627 StopBeforeMatch);
2628 Diag(PrevTok.getLocation(), diag::err_expected)
2629 << tok::identifier
2630 << SourceRange(PrevTok.getLocation(), PrevTokLocation);
2631 } else {
2632 Callback(SS, Actions.GetNameFromUnqualifiedId(Name));
2633 }
2634 // Consume ','.
2635 if (Tok.is(tok::comma)) {
2636 ConsumeToken();
2637 }
2638 }
2639
2640 if (NoIdentIsFound) {
2641 Diag(Tok, diag::err_expected) << tok::identifier;
2642 IsCorrect = false;
2643 }
2644
2645 // Parse ')'.
2646 IsCorrect = !T.consumeClose() && IsCorrect;
2647
2648 return !IsCorrect;
2649}
2650
2651OMPClause *Parser::ParseOpenMPSizesClause() {
2652 SourceLocation ClauseNameLoc = ConsumeToken();
2653 SmallVector<Expr *, 4> ValExprs;
2654
2655 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
2656 if (T.consumeOpen()) {
2657 Diag(Tok, diag::err_expected) << tok::l_paren;
2658 return nullptr;
2659 }
2660
2661 while (true) {
2662 ExprResult Val = ParseConstantExpression();
2663 if (!Val.isUsable()) {
2664 T.skipToEnd();
2665 return nullptr;
2666 }
2667
2668 ValExprs.push_back(Val.get());
2669
2670 if (Tok.is(tok::r_paren) || Tok.is(tok::annot_pragma_openmp_end))
2671 break;
2672
2673 ExpectAndConsume(tok::comma);
2674 }
2675
2676 T.consumeClose();
2677
2678 return Actions.ActOnOpenMPSizesClause(
2679 ValExprs, ClauseNameLoc, T.getOpenLocation(), T.getCloseLocation());
2680}
2681
2682OMPClause *Parser::ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind) {
2683 SourceLocation Loc = Tok.getLocation();
2684 ConsumeAnyToken();
2685
2686 // Parse '('.
2687 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
2688 if (T.expectAndConsume(diag::err_expected_lparen_after, "uses_allocator"))
2689 return nullptr;
2690 SmallVector<Sema::UsesAllocatorsData, 4> Data;
2691 do {
2692 ExprResult Allocator = ParseCXXIdExpression();
2693 if (Allocator.isInvalid()) {
2694 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
2695 StopBeforeMatch);
2696 break;
2697 }
2698 Sema::UsesAllocatorsData &D = Data.emplace_back();
2699 D.Allocator = Allocator.get();
2700 if (Tok.is(tok::l_paren)) {
2701 BalancedDelimiterTracker T(*this, tok::l_paren,
2702 tok::annot_pragma_openmp_end);
2703 T.consumeOpen();
2704 ExprResult AllocatorTraits = ParseCXXIdExpression();
2705 T.consumeClose();
2706 if (AllocatorTraits.isInvalid()) {
2707 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
2708 StopBeforeMatch);
2709 break;
2710 }
2711 D.AllocatorTraits = AllocatorTraits.get();
2712 D.LParenLoc = T.getOpenLocation();
2713 D.RParenLoc = T.getCloseLocation();
2714 }
2715 if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren))
2716 Diag(Tok, diag::err_omp_expected_punc) << "uses_allocators" << 0;
2717 // Parse ','
2718 if (Tok.is(tok::comma))
2719 ConsumeAnyToken();
2720 } while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end));
2721 T.consumeClose();
2722 return Actions.ActOnOpenMPUsesAllocatorClause(Loc, T.getOpenLocation(),
2723 T.getCloseLocation(), Data);
2724}
2725
2726/// Parsing of OpenMP clauses.
2727///
2728/// clause:
2729/// if-clause | final-clause | num_threads-clause | safelen-clause |
2730/// default-clause | private-clause | firstprivate-clause | shared-clause
2731/// | linear-clause | aligned-clause | collapse-clause |
2732/// lastprivate-clause | reduction-clause | proc_bind-clause |
2733/// schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
2734/// mergeable-clause | flush-clause | read-clause | write-clause |
2735/// update-clause | capture-clause | seq_cst-clause | device-clause |
2736/// simdlen-clause | threads-clause | simd-clause | num_teams-clause |
2737/// thread_limit-clause | priority-clause | grainsize-clause |
2738/// nogroup-clause | num_tasks-clause | hint-clause | to-clause |
2739/// from-clause | is_device_ptr-clause | task_reduction-clause |
2740/// in_reduction-clause | allocator-clause | allocate-clause |
2741/// acq_rel-clause | acquire-clause | release-clause | relaxed-clause |
2742/// depobj-clause | destroy-clause | detach-clause | inclusive-clause |
2743/// exclusive-clause | uses_allocators-clause | use_device_addr-clause
2744///
2745OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
2746 OpenMPClauseKind CKind, bool FirstClause) {
2747 OMPClauseKind = CKind;
2748 OMPClause *Clause = nullptr;
2749 bool ErrorFound = false;
2750 bool WrongDirective = false;
2751 // Check if clause is allowed for the given directive.
2752 if (CKind != OMPC_unknown &&
2753 !isAllowedClauseForDirective(DKind, CKind, getLangOpts().OpenMP)) {
2754 Diag(Tok, diag::err_omp_unexpected_clause)
2755 << getOpenMPClauseName(CKind) << getOpenMPDirectiveName(DKind);
2756 ErrorFound = true;
2757 WrongDirective = true;
2758 }
2759
2760 switch (CKind) {
2761 case OMPC_final:
2762 case OMPC_num_threads:
2763 case OMPC_safelen:
2764 case OMPC_simdlen:
2765 case OMPC_collapse:
2766 case OMPC_ordered:
2767 case OMPC_num_teams:
2768 case OMPC_thread_limit:
2769 case OMPC_priority:
2770 case OMPC_grainsize:
2771 case OMPC_num_tasks:
2772 case OMPC_hint:
2773 case OMPC_allocator:
2774 case OMPC_depobj:
2775 case OMPC_detach:
2776 // OpenMP [2.5, Restrictions]
2777 // At most one num_threads clause can appear on the directive.
2778 // OpenMP [2.8.1, simd construct, Restrictions]
2779 // Only one safelen clause can appear on a simd directive.
2780 // Only one simdlen clause can appear on a simd directive.
2781 // Only one collapse clause can appear on a simd directive.
2782 // OpenMP [2.11.1, task Construct, Restrictions]
2783 // At most one if clause can appear on the directive.
2784 // At most one final clause can appear on the directive.
2785 // OpenMP [teams Construct, Restrictions]
2786 // At most one num_teams clause can appear on the directive.
2787 // At most one thread_limit clause can appear on the directive.
2788 // OpenMP [2.9.1, task Construct, Restrictions]
2789 // At most one priority clause can appear on the directive.
2790 // OpenMP [2.9.2, taskloop Construct, Restrictions]
2791 // At most one grainsize clause can appear on the directive.
2792 // OpenMP [2.9.2, taskloop Construct, Restrictions]
2793 // At most one num_tasks clause can appear on the directive.
2794 // OpenMP [2.11.3, allocate Directive, Restrictions]
2795 // At most one allocator clause can appear on the directive.
2796 // OpenMP 5.0, 2.10.1 task Construct, Restrictions.
2797 // At most one detach clause can appear on the directive.
2798 if (!FirstClause) {
2799 Diag(Tok, diag::err_omp_more_one_clause)
2800 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
2801 ErrorFound = true;
2802 }
2803
2804 if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren))
2805 Clause = ParseOpenMPClause(CKind, WrongDirective);
2806 else
2807 Clause = ParseOpenMPSingleExprClause(CKind, WrongDirective);
2808 break;
2809 case OMPC_default:
2810 case OMPC_proc_bind:
2811 case OMPC_atomic_default_mem_order:
2812 case OMPC_order:
2813 // OpenMP [2.14.3.1, Restrictions]
2814 // Only a single default clause may be specified on a parallel, task or
2815 // teams directive.
2816 // OpenMP [2.5, parallel Construct, Restrictions]
2817 // At most one proc_bind clause can appear on the directive.
2818 // OpenMP [5.0, Requires directive, Restrictions]
2819 // At most one atomic_default_mem_order clause can appear
2820 // on the directive
2821 if (!FirstClause && CKind != OMPC_order) {
2822 Diag(Tok, diag::err_omp_more_one_clause)
2823 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
2824 ErrorFound = true;
2825 }
2826
2827 Clause = ParseOpenMPSimpleClause(CKind, WrongDirective);
2828 break;
2829 case OMPC_device:
2830 case OMPC_schedule:
2831 case OMPC_dist_schedule:
2832 case OMPC_defaultmap:
2833 // OpenMP [2.7.1, Restrictions, p. 3]
2834 // Only one schedule clause can appear on a loop directive.
2835 // OpenMP 4.5 [2.10.4, Restrictions, p. 106]
2836 // At most one defaultmap clause can appear on the directive.
2837 // OpenMP 5.0 [2.12.5, target construct, Restrictions]
2838 // At most one device clause can appear on the directive.
2839 if ((getLangOpts().OpenMP < 50 || CKind != OMPC_defaultmap) &&
2840 !FirstClause) {
2841 Diag(Tok, diag::err_omp_more_one_clause)
2842 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
2843 ErrorFound = true;
2844 }
2845 LLVM_FALLTHROUGH[[gnu::fallthrough]];
2846 case OMPC_if:
2847 Clause = ParseOpenMPSingleExprWithArgClause(DKind, CKind, WrongDirective);
2848 break;
2849 case OMPC_nowait:
2850 case OMPC_untied:
2851 case OMPC_mergeable:
2852 case OMPC_read:
2853 case OMPC_write:
2854 case OMPC_capture:
2855 case OMPC_seq_cst:
2856 case OMPC_acq_rel:
2857 case OMPC_acquire:
2858 case OMPC_release:
2859 case OMPC_relaxed:
2860 case OMPC_threads:
2861 case OMPC_simd:
2862 case OMPC_nogroup:
2863 case OMPC_unified_address:
2864 case OMPC_unified_shared_memory:
2865 case OMPC_reverse_offload:
2866 case OMPC_dynamic_allocators:
2867 case OMPC_destroy:
2868 // OpenMP [2.7.1, Restrictions, p. 9]
2869 // Only one ordered clause can appear on a loop directive.
2870 // OpenMP [2.7.1, Restrictions, C/C++, p. 4]
2871 // Only one nowait clause can appear on a for directive.
2872 // OpenMP [5.0, Requires directive, Restrictions]
2873 // Each of the requires clauses can appear at most once on the directive.
2874 if (!FirstClause) {
2875 Diag(Tok, diag::err_omp_more_one_clause)
2876 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
2877 ErrorFound = true;
2878 }
2879
2880 Clause = ParseOpenMPClause(CKind, WrongDirective);
2881 break;
2882 case OMPC_update:
2883 if (!FirstClause) {
2884 Diag(Tok, diag::err_omp_more_one_clause)
2885 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
2886 ErrorFound = true;
2887 }
2888
2889 Clause = (DKind == OMPD_depobj)
2890 ? ParseOpenMPSimpleClause(CKind, WrongDirective)
2891 : ParseOpenMPClause(CKind, WrongDirective);
2892 break;
2893 case OMPC_private:
2894 case OMPC_firstprivate:
2895 case OMPC_lastprivate:
2896 case OMPC_shared:
2897 case OMPC_reduction:
2898 case OMPC_task_reduction:
2899 case OMPC_in_reduction:
2900 case OMPC_linear:
2901 case OMPC_aligned:
2902 case OMPC_copyin:
2903 case OMPC_copyprivate:
2904 case OMPC_flush:
2905 case OMPC_depend:
2906 case OMPC_map:
2907 case OMPC_to:
2908 case OMPC_from:
2909 case OMPC_use_device_ptr:
2910 case OMPC_use_device_addr:
2911 case OMPC_is_device_ptr:
2912 case OMPC_allocate:
2913 case OMPC_nontemporal:
2914 case OMPC_inclusive:
2915 case OMPC_exclusive:
2916 case OMPC_affinity:
2917 Clause = ParseOpenMPVarListClause(DKind, CKind, WrongDirective);
2918 break;
2919 case OMPC_sizes:
2920 if (!FirstClause) {
2921 Diag(Tok, diag::err_omp_more_one_clause)
2922 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
2923 ErrorFound = true;
2924 }
2925
2926 Clause = ParseOpenMPSizesClause();
2927 break;
2928 case OMPC_uses_allocators:
2929 Clause = ParseOpenMPUsesAllocatorClause(DKind);
2930 break;
2931 case OMPC_device_type:
2932 case OMPC_unknown:
2933 skipUntilPragmaOpenMPEnd(DKind);
2934 break;
2935 case OMPC_threadprivate:
2936 case OMPC_uniform:
2937 case OMPC_match:
2938 if (!WrongDirective)
2939 Diag(Tok, diag::err_omp_unexpected_clause)
2940 << getOpenMPClauseName(CKind) << getOpenMPDirectiveName(DKind);
2941 SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
2942 break;
2943 default:
2944 break;
2945 }
2946 return ErrorFound ? nullptr : Clause;
2947}
2948
2949/// Parses simple expression in parens for single-expression clauses of OpenMP
2950/// constructs.
2951/// \param RLoc Returned location of right paren.
2952ExprResult Parser::ParseOpenMPParensExpr(StringRef ClauseName,
2953 SourceLocation &RLoc,
2954 bool IsAddressOfOperand) {
2955 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
2956 if (T.expectAndConsume(diag::err_expected_lparen_after, ClauseName.data()))
2957 return ExprError();
2958
2959 SourceLocation ELoc = Tok.getLocation();
2960 ExprResult LHS(
2961 ParseCastExpression(AnyCastExpr, IsAddressOfOperand, NotTypeCast));
2962 ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
2963 Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc, /*DiscardedValue*/ false);
2964
2965 // Parse ')'.
2966 RLoc = Tok.getLocation();
2967 if (!T.consumeClose())
2968 RLoc = T.getCloseLocation();
2969
2970 return Val;
2971}
2972
2973/// Parsing of OpenMP clauses with single expressions like 'final',
2974/// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams',
2975/// 'thread_limit', 'simdlen', 'priority', 'grainsize', 'num_tasks', 'hint' or
2976/// 'detach'.
2977///
2978/// final-clause:
2979/// 'final' '(' expression ')'
2980///
2981/// num_threads-clause:
2982/// 'num_threads' '(' expression ')'
2983///
2984/// safelen-clause:
2985/// 'safelen' '(' expression ')'
2986///
2987/// simdlen-clause:
2988/// 'simdlen' '(' expression ')'
2989///
2990/// collapse-clause:
2991/// 'collapse' '(' expression ')'
2992///
2993/// priority-clause:
2994/// 'priority' '(' expression ')'
2995///
2996/// grainsize-clause:
2997/// 'grainsize' '(' expression ')'
2998///
2999/// num_tasks-clause:
3000/// 'num_tasks' '(' expression ')'
3001///
3002/// hint-clause:
3003/// 'hint' '(' expression ')'
3004///
3005/// allocator-clause:
3006/// 'allocator' '(' expression ')'
3007///
3008/// detach-clause:
3009/// 'detach' '(' event-handler-expression ')'
3010///
3011OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind,
3012 bool ParseOnly) {
3013 SourceLocation Loc = ConsumeToken();
3014 SourceLocation LLoc = Tok.getLocation();
3015 SourceLocation RLoc;
3016
3017 ExprResult Val = ParseOpenMPParensExpr(getOpenMPClauseName(Kind), RLoc);
3018
3019 if (Val.isInvalid())
3020 return nullptr;
3021
3022 if (ParseOnly)
3023 return nullptr;
3024 return Actions.ActOnOpenMPSingleExprClause(Kind, Val.get(), Loc, LLoc, RLoc);
3025}
3026
3027/// Parsing of simple OpenMP clauses like 'default' or 'proc_bind'.
3028///
3029/// default-clause:
3030/// 'default' '(' 'none' | 'shared' | 'firstprivate' ')'
3031///
3032/// proc_bind-clause:
3033/// 'proc_bind' '(' 'master' | 'close' | 'spread' ')'
3034///
3035/// update-clause:
3036/// 'update' '(' 'in' | 'out' | 'inout' | 'mutexinoutset' ')'
3037///
3038OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind,
3039 bool ParseOnly) {
3040 llvm::Optional<SimpleClauseData> Val = parseOpenMPSimpleClause(*this, Kind);
3041 if (!Val || ParseOnly)
3042 return nullptr;
3043 if (getLangOpts().OpenMP < 51 && Kind == OMPC_default &&
3044 static_cast<DefaultKind>(Val.getValue().Type) ==
3045 OMP_DEFAULT_firstprivate) {
3046 Diag(Val.getValue().LOpen, diag::err_omp_invalid_dsa)
3047 << getOpenMPClauseName(OMPC_firstprivate)
3048 << getOpenMPClauseName(OMPC_default) << "5.1";
3049 return nullptr;
3050 }
3051 return Actions.ActOnOpenMPSimpleClause(
3052 Kind, Val.getValue().Type, Val.getValue().TypeLoc, Val.getValue().LOpen,
3053 Val.getValue().Loc, Val.getValue().RLoc);
3054}
3055
3056/// Parsing of OpenMP clauses like 'ordered'.
3057///
3058/// ordered-clause:
3059/// 'ordered'
3060///
3061/// nowait-clause:
3062/// 'nowait'
3063///
3064/// untied-clause:
3065/// 'untied'
3066///
3067/// mergeable-clause:
3068/// 'mergeable'
3069///
3070/// read-clause:
3071/// 'read'
3072///
3073/// threads-clause:
3074/// 'threads'
3075///
3076/// simd-clause:
3077/// 'simd'
3078///
3079/// nogroup-clause:
3080/// 'nogroup'
3081///
3082OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind, bool ParseOnly) {
3083 SourceLocation Loc = Tok.getLocation();
3084 ConsumeAnyToken();
3085
3086 if (ParseOnly)
3087 return nullptr;
3088 return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
3089}
3090
3091/// Parsing of OpenMP clauses with single expressions and some additional
3092/// argument like 'schedule' or 'dist_schedule'.
3093///
3094/// schedule-clause:
3095/// 'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression ]
3096/// ')'
3097///
3098/// if-clause:
3099/// 'if' '(' [ directive-name-modifier ':' ] expression ')'
3100///
3101/// defaultmap:
3102/// 'defaultmap' '(' modifier [ ':' kind ] ')'
3103///
3104/// device-clause:
3105/// 'device' '(' [ device-modifier ':' ] expression ')'
3106///
3107OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
3108 OpenMPClauseKind Kind,
3109 bool ParseOnly) {
3110 SourceLocation Loc = ConsumeToken();
3111 SourceLocation DelimLoc;
3112 // Parse '('.
3113 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
3114 if (T.expectAndConsume(diag::err_expected_lparen_after,
3115 getOpenMPClauseName(Kind).data()))
3116 return nullptr;
3117
3118 ExprResult Val;
3119 SmallVector<unsigned, 4> Arg;
3120 SmallVector<SourceLocation, 4> KLoc;
3121 if (Kind == OMPC_schedule) {
3122 enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements };
3123 Arg.resize(NumberOfElements);
3124 KLoc.resize(NumberOfElements);
3125 Arg[Modifier1] = OMPC_SCHEDULE_MODIFIER_unknown;
3126 Arg[Modifier2] = OMPC_SCHEDULE_MODIFIER_unknown;
3127 Arg[ScheduleKind] = OMPC_SCHEDULE_unknown;
3128 unsigned KindModifier = getOpenMPSimpleClauseType(
3129 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok),
3130 getLangOpts().OpenMP);
3131 if (KindModifier > OMPC_SCHEDULE_unknown) {
3132 // Parse 'modifier'
3133 Arg[Modifier1] = KindModifier;
3134 KLoc[Modifier1] = Tok.getLocation();
3135 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
3136 Tok.isNot(tok::annot_pragma_openmp_end))
3137 ConsumeAnyToken();
3138 if (Tok.is(tok::comma)) {
3139 // Parse ',' 'modifier'
3140 ConsumeAnyToken();
3141 KindModifier = getOpenMPSimpleClauseType(
3142 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok),
3143 getLangOpts().OpenMP);
3144 Arg[Modifier2] = KindModifier > OMPC_SCHEDULE_unknown
3145 ? KindModifier
3146 : (unsigned)OMPC_SCHEDULE_unknown;
3147 KLoc[Modifier2] = Tok.getLocation();
3148 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
3149 Tok.isNot(tok::annot_pragma_openmp_end))
3150 ConsumeAnyToken();
3151 }
3152 // Parse ':'
3153 if (Tok.is(tok::colon))
3154 ConsumeAnyToken();
3155 else
3156 Diag(Tok, diag::warn_pragma_expected_colon) << "schedule modifier";
3157 KindModifier = getOpenMPSimpleClauseType(
3158 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok),
3159 getLangOpts().OpenMP);
3160 }
3161 Arg[ScheduleKind] = KindModifier;
3162 KLoc[ScheduleKind] = Tok.getLocation();
3163 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
3164 Tok.isNot(tok::annot_pragma_openmp_end))
3165 ConsumeAnyToken();
3166 if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static ||
3167 Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic ||
3168 Arg[ScheduleKind] == OMPC_SCHEDULE_guided) &&
3169 Tok.is(tok::comma))
3170 DelimLoc = ConsumeAnyToken();
3171 } else if (Kind == OMPC_dist_schedule) {
3172 Arg.push_back(getOpenMPSimpleClauseType(
3173 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok),
3174 getLangOpts().OpenMP));
3175 KLoc.push_back(Tok.getLocation());
3176 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
3177 Tok.isNot(tok::annot_pragma_openmp_end))
3178 ConsumeAnyToken();
3179 if (Arg.back() == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma))
3180 DelimLoc = ConsumeAnyToken();
3181 } else if (Kind == OMPC_defaultmap) {
3182 // Get a defaultmap modifier
3183 unsigned Modifier = getOpenMPSimpleClauseType(
3184 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok),
3185 getLangOpts().OpenMP);
3186 // Set defaultmap modifier to unknown if it is either scalar, aggregate, or
3187 // pointer
3188 if (Modifier < OMPC_DEFAULTMAP_MODIFIER_unknown)
3189 Modifier = OMPC_DEFAULTMAP_MODIFIER_unknown;
3190 Arg.push_back(Modifier);
3191 KLoc.push_back(Tok.getLocation());
3192 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
3193 Tok.isNot(tok::annot_pragma_openmp_end))
3194 ConsumeAnyToken();
3195 // Parse ':'
3196 if (Tok.is(tok::colon) || getLangOpts().OpenMP < 50) {
3197 if (Tok.is(tok::colon))
3198 ConsumeAnyToken();
3199 else if (Arg.back() != OMPC_DEFAULTMAP_MODIFIER_unknown)
3200 Diag(Tok, diag::warn_pragma_expected_colon) << "defaultmap modifier";
3201 // Get a defaultmap kind
3202 Arg.push_back(getOpenMPSimpleClauseType(
3203 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok),
3204 getLangOpts().OpenMP));
3205 KLoc.push_back(Tok.getLocation());
3206 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
3207 Tok.isNot(tok::annot_pragma_openmp_end))
3208 ConsumeAnyToken();
3209 } else {
3210 Arg.push_back(OMPC_DEFAULTMAP_unknown);
3211 KLoc.push_back(SourceLocation());
3212 }
3213 } else if (Kind == OMPC_device) {
3214 // Only target executable directives support extended device construct.
3215 if (isOpenMPTargetExecutionDirective(DKind) && getLangOpts().OpenMP >= 50 &&
3216 NextToken().is(tok::colon)) {
3217 // Parse optional <device modifier> ':'
3218 Arg.push_back(getOpenMPSimpleClauseType(
3219 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok),
3220 getLangOpts().OpenMP));
3221 KLoc.push_back(Tok.getLocation());
3222 ConsumeAnyToken();
3223 // Parse ':'
3224 ConsumeAnyToken();
3225 } else {
3226 Arg.push_back(OMPC_DEVICE_unknown);
3227 KLoc.emplace_back();
3228 }
3229 } else {
3230 assert(Kind == OMPC_if)((Kind == OMPC_if) ? static_cast<void> (0) : __assert_fail
("Kind == OMPC_if", "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 3230, __PRETTY_FUNCTION__))
;
3231 KLoc.push_back(Tok.getLocation());
3232 TentativeParsingAction TPA(*this);
3233 auto DK = parseOpenMPDirectiveKind(*this);
3234 Arg.push_back(DK);
3235 if (DK != OMPD_unknown) {
3236 ConsumeToken();
3237 if (Tok.is(tok::colon) && getLangOpts().OpenMP > 40) {
3238 TPA.Commit();
3239 DelimLoc = ConsumeToken();
3240 } else {
3241 TPA.Revert();
3242 Arg.back() = unsigned(OMPD_unknown);
3243 }
3244 } else {
3245 TPA.Revert();
3246 }
3247 }
3248
3249 bool NeedAnExpression = (Kind == OMPC_schedule && DelimLoc.isValid()) ||
3250 (Kind == OMPC_dist_schedule && DelimLoc.isValid()) ||
3251 Kind == OMPC_if || Kind == OMPC_device;
3252 if (NeedAnExpression) {
3253 SourceLocation ELoc = Tok.getLocation();
3254 ExprResult LHS(ParseCastExpression(AnyCastExpr, false, NotTypeCast));
3255 Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional);
3256 Val =
3257 Actions.ActOnFinishFullExpr(Val.get(), ELoc, /*DiscardedValue*/ false);
3258 }
3259
3260 // Parse ')'.
3261 SourceLocation RLoc = Tok.getLocation();
3262 if (!T.consumeClose())
3263 RLoc = T.getCloseLocation();
3264
3265 if (NeedAnExpression && Val.isInvalid())
3266 return nullptr;
3267
3268 if (ParseOnly)
3269 return nullptr;
3270 return Actions.ActOnOpenMPSingleExprWithArgClause(
3271 Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc, RLoc);
3272}
3273
3274static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec,
3275 UnqualifiedId &ReductionId) {
3276 if (ReductionIdScopeSpec.isEmpty()) {
3277 auto OOK = OO_None;
3278 switch (P.getCurToken().getKind()) {
3279 case tok::plus:
3280 OOK = OO_Plus;
3281 break;
3282 case tok::minus:
3283 OOK = OO_Minus;
3284 break;
3285 case tok::star:
3286 OOK = OO_Star;
3287 break;
3288 case tok::amp:
3289 OOK = OO_Amp;
3290 break;
3291 case tok::pipe:
3292 OOK = OO_Pipe;
3293 break;
3294 case tok::caret:
3295 OOK = OO_Caret;
3296 break;
3297 case tok::ampamp:
3298 OOK = OO_AmpAmp;
3299 break;
3300 case tok::pipepipe:
3301 OOK = OO_PipePipe;
3302 break;
3303 default:
3304 break;
3305 }
3306 if (OOK != OO_None) {
3307 SourceLocation OpLoc = P.ConsumeToken();
3308 SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()};
3309 ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations);
3310 return false;
3311 }
3312 }
3313 return P.ParseUnqualifiedId(
3314 ReductionIdScopeSpec, /*ObjectType=*/nullptr,
3315 /*ObjectHadErrors=*/false, /*EnteringContext*/ false,
3316 /*AllowDestructorName*/ false,
3317 /*AllowConstructorName*/ false,
3318 /*AllowDeductionGuide*/ false, nullptr, ReductionId);
3319}
3320
3321/// Checks if the token is a valid map-type-modifier.
3322/// FIXME: It will return an OpenMPMapClauseKind if that's what it parses.
3323static OpenMPMapModifierKind isMapModifier(Parser &P) {
3324 Token Tok = P.getCurToken();
3325 if (!Tok.is(tok::identifier))
3326 return OMPC_MAP_MODIFIER_unknown;
3327
3328 Preprocessor &PP = P.getPreprocessor();
3329 OpenMPMapModifierKind TypeModifier =
3330 static_cast<OpenMPMapModifierKind>(getOpenMPSimpleClauseType(
3331 OMPC_map, PP.getSpelling(Tok), P.getLangOpts().OpenMP));
3332 return TypeModifier;
3333}
3334
3335/// Parse the mapper modifier in map, to, and from clauses.
3336bool Parser::parseMapperModifier(OpenMPVarListDataTy &Data) {
3337 // Parse '('.
3338 BalancedDelimiterTracker T(*this, tok::l_paren, tok::colon);
3339 if (T.expectAndConsume(diag::err_expected_lparen_after, "mapper")) {
3340 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
3341 StopBeforeMatch);
3342 return true;
3343 }
3344 // Parse mapper-identifier
3345 if (getLangOpts().CPlusPlus)
3346 ParseOptionalCXXScopeSpecifier(Data.ReductionOrMapperIdScopeSpec,
3347 /*ObjectType=*/nullptr,
3348 /*ObjectHadErrors=*/false,
3349 /*EnteringContext=*/false);
3350 if (Tok.isNot(tok::identifier) && Tok.isNot(tok::kw_default)) {
3351 Diag(Tok.getLocation(), diag::err_omp_mapper_illegal_identifier);
3352 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
3353 StopBeforeMatch);
3354 return true;
3355 }
3356 auto &DeclNames = Actions.getASTContext().DeclarationNames;
3357 Data.ReductionOrMapperId = DeclarationNameInfo(
3358 DeclNames.getIdentifier(Tok.getIdentifierInfo()), Tok.getLocation());
3359 ConsumeToken();
3360 // Parse ')'.
3361 return T.consumeClose();
3362}
3363
3364/// Parse map-type-modifiers in map clause.
3365/// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list)
3366/// where, map-type-modifier ::= always | close | mapper(mapper-identifier) |
3367/// present
3368bool Parser::parseMapTypeModifiers(OpenMPVarListDataTy &Data) {
3369 while (getCurToken().isNot(tok::colon)) {
3370 OpenMPMapModifierKind TypeModifier = isMapModifier(*this);
3371 if (TypeModifier == OMPC_MAP_MODIFIER_always ||
3372 TypeModifier == OMPC_MAP_MODIFIER_close ||
3373 TypeModifier == OMPC_MAP_MODIFIER_present) {
3374 Data.MapTypeModifiers.push_back(TypeModifier);
3375 Data.MapTypeModifiersLoc.push_back(Tok.getLocation());
3376 ConsumeToken();
3377 } else if (TypeModifier == OMPC_MAP_MODIFIER_mapper) {
3378 Data.MapTypeModifiers.push_back(TypeModifier);
3379 Data.MapTypeModifiersLoc.push_back(Tok.getLocation());
3380 ConsumeToken();
3381 if (parseMapperModifier(Data))
3382 return true;
3383 } else {
3384 // For the case of unknown map-type-modifier or a map-type.
3385 // Map-type is followed by a colon; the function returns when it
3386 // encounters a token followed by a colon.
3387 if (Tok.is(tok::comma)) {
3388 Diag(Tok, diag::err_omp_map_type_modifier_missing);
3389 ConsumeToken();
3390 continue;
3391 }
3392 // Potential map-type token as it is followed by a colon.
3393 if (PP.LookAhead(0).is(tok::colon))
3394 return false;
3395 Diag(Tok, diag::err_omp_unknown_map_type_modifier)
3396 << (getLangOpts().OpenMP >= 51 ? 1 : 0);
3397 ConsumeToken();
3398 }
3399 if (getCurToken().is(tok::comma))
3400 ConsumeToken();
3401 }
3402 return false;
3403}
3404
3405/// Checks if the token is a valid map-type.
3406/// FIXME: It will return an OpenMPMapModifierKind if that's what it parses.
3407static OpenMPMapClauseKind isMapType(Parser &P) {
3408 Token Tok = P.getCurToken();
3409 // The map-type token can be either an identifier or the C++ delete keyword.
3410 if (!Tok.isOneOf(tok::identifier, tok::kw_delete))
3411 return OMPC_MAP_unknown;
3412 Preprocessor &PP = P.getPreprocessor();
3413 OpenMPMapClauseKind MapType =
3414 static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType(
3415 OMPC_map, PP.getSpelling(Tok), P.getLangOpts().OpenMP));
3416 return MapType;
3417}
3418
3419/// Parse map-type in map clause.
3420/// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list)
3421/// where, map-type ::= to | from | tofrom | alloc | release | delete
3422static void parseMapType(Parser &P, Parser::OpenMPVarListDataTy &Data) {
3423 Token Tok = P.getCurToken();
3424 if (Tok.is(tok::colon)) {
3425 P.Diag(Tok, diag::err_omp_map_type_missing);
3426 return;
3427 }
3428 Data.ExtraModifier = isMapType(P);
3429 if (Data.ExtraModifier == OMPC_MAP_unknown)
3430 P.Diag(Tok, diag::err_omp_unknown_map_type);
3431 P.ConsumeToken();
3432}
3433
3434/// Parses simple expression in parens for single-expression clauses of OpenMP
3435/// constructs.
3436ExprResult Parser::ParseOpenMPIteratorsExpr() {
3437 assert(Tok.is(tok::identifier) && PP.getSpelling(Tok) == "iterator" &&((Tok.is(tok::identifier) && PP.getSpelling(Tok) == "iterator"
&& "Expected 'iterator' token.") ? static_cast<void
> (0) : __assert_fail ("Tok.is(tok::identifier) && PP.getSpelling(Tok) == \"iterator\" && \"Expected 'iterator' token.\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 3438, __PRETTY_FUNCTION__))
3438 "Expected 'iterator' token.")((Tok.is(tok::identifier) && PP.getSpelling(Tok) == "iterator"
&& "Expected 'iterator' token.") ? static_cast<void
> (0) : __assert_fail ("Tok.is(tok::identifier) && PP.getSpelling(Tok) == \"iterator\" && \"Expected 'iterator' token.\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 3438, __PRETTY_FUNCTION__))
;
3439 SourceLocation IteratorKwLoc = ConsumeToken();
3440
3441 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
3442 if (T.expectAndConsume(diag::err_expected_lparen_after, "iterator"))
3443 return ExprError();
3444
3445 SourceLocation LLoc = T.getOpenLocation();
3446 SmallVector<Sema::OMPIteratorData, 4> Data;
3447 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
3448 // Check if the type parsing is required.
3449 ParsedType IteratorType;
3450 if (Tok.isNot(tok::identifier) || NextToken().isNot(tok::equal)) {
3451 // identifier '=' is not found - parse type.
3452 TypeResult TR = ParseTypeName();
3453 if (TR.isInvalid()) {
3454 T.skipToEnd();
3455 return ExprError();
3456 }
3457 IteratorType = TR.get();
3458 }
3459
3460 // Parse identifier.
3461 IdentifierInfo *II = nullptr;
3462 SourceLocation IdLoc;
3463 if (Tok.is(tok::identifier)) {
3464 II = Tok.getIdentifierInfo();
3465 IdLoc = ConsumeToken();
3466 } else {
3467 Diag(Tok, diag::err_expected_unqualified_id) << 0;
3468 }
3469
3470 // Parse '='.
3471 SourceLocation AssignLoc;
3472 if (Tok.is(tok::equal))
3473 AssignLoc = ConsumeToken();
3474 else
3475 Diag(Tok, diag::err_omp_expected_equal_in_iterator);
3476
3477 // Parse range-specification - <begin> ':' <end> [ ':' <step> ]
3478 ColonProtectionRAIIObject ColonRAII(*this);
3479 // Parse <begin>
3480 SourceLocation Loc = Tok.getLocation();
3481 ExprResult LHS = ParseCastExpression(AnyCastExpr);
3482 ExprResult Begin = Actions.CorrectDelayedTyposInExpr(
3483 ParseRHSOfBinaryExpression(LHS, prec::Conditional));
3484 Begin = Actions.ActOnFinishFullExpr(Begin.get(), Loc,
3485 /*DiscardedValue=*/false);
3486 // Parse ':'.
3487 SourceLocation ColonLoc;
3488 if (Tok.is(tok::colon))
3489 ColonLoc = ConsumeToken();
3490
3491 // Parse <end>
3492 Loc = Tok.getLocation();
3493 LHS = ParseCastExpression(AnyCastExpr);
3494 ExprResult End = Actions.CorrectDelayedTyposInExpr(
3495 ParseRHSOfBinaryExpression(LHS, prec::Conditional));
3496 End = Actions.ActOnFinishFullExpr(End.get(), Loc,
3497 /*DiscardedValue=*/false);
3498
3499 SourceLocation SecColonLoc;
3500 ExprResult Step;
3501 // Parse optional step.
3502 if (Tok.is(tok::colon)) {
3503 // Parse ':'
3504 SecColonLoc = ConsumeToken();
3505 // Parse <step>
3506 Loc = Tok.getLocation();
3507 LHS = ParseCastExpression(AnyCastExpr);
3508 Step = Actions.CorrectDelayedTyposInExpr(
3509 ParseRHSOfBinaryExpression(LHS, prec::Conditional));
3510 Step = Actions.ActOnFinishFullExpr(Step.get(), Loc,
3511 /*DiscardedValue=*/false);
3512 }
3513
3514 // Parse ',' or ')'
3515 if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren))
3516 Diag(Tok, diag::err_omp_expected_punc_after_iterator);
3517 if (Tok.is(tok::comma))
3518 ConsumeToken();
3519
3520 Sema::OMPIteratorData &D = Data.emplace_back();
3521 D.DeclIdent = II;
3522 D.DeclIdentLoc = IdLoc;
3523 D.Type = IteratorType;
3524 D.AssignLoc = AssignLoc;
3525 D.ColonLoc = ColonLoc;
3526 D.SecColonLoc = SecColonLoc;
3527 D.Range.Begin = Begin.get();
3528 D.Range.End = End.get();
3529 D.Range.Step = Step.get();
3530 }
3531
3532 // Parse ')'.
3533 SourceLocation RLoc = Tok.getLocation();
3534 if (!T.consumeClose())
3535 RLoc = T.getCloseLocation();
3536
3537 return Actions.ActOnOMPIteratorExpr(getCurScope(), IteratorKwLoc, LLoc, RLoc,
3538 Data);
3539}
3540
3541/// Parses clauses with list.
3542bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
3543 OpenMPClauseKind Kind,
3544 SmallVectorImpl<Expr *> &Vars,
3545 OpenMPVarListDataTy &Data) {
3546 UnqualifiedId UnqualifiedReductionId;
3547 bool InvalidReductionId = false;
3548 bool IsInvalidMapperModifier = false;
3549
3550 // Parse '('.
3551 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
3552 if (T.expectAndConsume(diag::err_expected_lparen_after,
3553 getOpenMPClauseName(Kind).data()))
3554 return true;
3555
3556 bool HasIterator = false;
3557 bool NeedRParenForLinear = false;
3558 BalancedDelimiterTracker LinearT(*this, tok::l_paren,
3559 tok::annot_pragma_openmp_end);
3560 // Handle reduction-identifier for reduction clause.
3561 if (Kind == OMPC_reduction || Kind == OMPC_task_reduction ||
3562 Kind == OMPC_in_reduction) {
3563 Data.ExtraModifier = OMPC_REDUCTION_unknown;
3564 if (Kind == OMPC_reduction && getLangOpts().OpenMP >= 50 &&
3565 (Tok.is(tok::identifier) || Tok.is(tok::kw_default)) &&
3566 NextToken().is(tok::comma)) {
3567 // Parse optional reduction modifier.
3568 Data.ExtraModifier = getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok),
3569 getLangOpts().OpenMP);
3570 Data.ExtraModifierLoc = Tok.getLocation();
3571 ConsumeToken();
3572 assert(Tok.is(tok::comma) && "Expected comma.")((Tok.is(tok::comma) && "Expected comma.") ? static_cast
<void> (0) : __assert_fail ("Tok.is(tok::comma) && \"Expected comma.\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 3572, __PRETTY_FUNCTION__))
;
3573 (void)ConsumeToken();
3574 }
3575 ColonProtectionRAIIObject ColonRAII(*this);
3576 if (getLangOpts().CPlusPlus)
3577 ParseOptionalCXXScopeSpecifier(Data.ReductionOrMapperIdScopeSpec,
3578 /*ObjectType=*/nullptr,
3579 /*ObjectHadErrors=*/false,
3580 /*EnteringContext=*/false);
3581 InvalidReductionId = ParseReductionId(
3582 *this, Data.ReductionOrMapperIdScopeSpec, UnqualifiedReductionId);
3583 if (InvalidReductionId) {
3584 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
3585 StopBeforeMatch);
3586 }
3587 if (Tok.is(tok::colon))
3588 Data.ColonLoc = ConsumeToken();
3589 else
3590 Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier";
3591 if (!InvalidReductionId)
3592 Data.ReductionOrMapperId =
3593 Actions.GetNameFromUnqualifiedId(UnqualifiedReductionId);
3594 } else if (Kind == OMPC_depend) {
3595 if (getLangOpts().OpenMP >= 50) {
3596 if (Tok.is(tok::identifier) && PP.getSpelling(Tok) == "iterator") {
3597 // Handle optional dependence modifier.
3598 // iterator(iterators-definition)
3599 // where iterators-definition is iterator-specifier [,
3600 // iterators-definition ]
3601 // where iterator-specifier is [ iterator-type ] identifier =
3602 // range-specification
3603 HasIterator = true;
3604 EnterScope(Scope::OpenMPDirectiveScope | Scope::DeclScope);
3605 ExprResult IteratorRes = ParseOpenMPIteratorsExpr();
3606 Data.DepModOrTailExpr = IteratorRes.get();
3607 // Parse ','
3608 ExpectAndConsume(tok::comma);
3609 }
3610 }
3611 // Handle dependency type for depend clause.
3612 ColonProtectionRAIIObject ColonRAII(*this);
3613 Data.ExtraModifier = getOpenMPSimpleClauseType(
3614 Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : "",
3615 getLangOpts().OpenMP);
3616 Data.ExtraModifierLoc = Tok.getLocation();
3617 if (Data.ExtraModifier == OMPC_DEPEND_unknown) {
3618 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
3619 StopBeforeMatch);
3620 } else {
3621 ConsumeToken();
3622 // Special processing for depend(source) clause.
3623 if (DKind == OMPD_ordered && Data.ExtraModifier == OMPC_DEPEND_source) {
3624 // Parse ')'.
3625 T.consumeClose();
3626 return false;
3627 }
3628 }
3629 if (Tok.is(tok::colon)) {
3630 Data.ColonLoc = ConsumeToken();
3631 } else {
3632 Diag(Tok, DKind == OMPD_ordered ? diag::warn_pragma_expected_colon_r_paren
3633 : diag::warn_pragma_expected_colon)
3634 << "dependency type";
3635 }
3636 } else if (Kind == OMPC_linear) {
3637 // Try to parse modifier if any.
3638 Data.ExtraModifier = OMPC_LINEAR_val;
3639 if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) {
3640 Data.ExtraModifier = getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok),
3641 getLangOpts().OpenMP);
3642 Data.ExtraModifierLoc = ConsumeToken();
3643 LinearT.consumeOpen();
3644 NeedRParenForLinear = true;
3645 }
3646 } else if (Kind == OMPC_lastprivate) {
3647 // Try to parse modifier if any.
3648 Data.ExtraModifier = OMPC_LASTPRIVATE_unknown;
3649 // Conditional modifier allowed only in OpenMP 5.0 and not supported in
3650 // distribute and taskloop based directives.
3651 if ((getLangOpts().OpenMP >= 50 && !isOpenMPDistributeDirective(DKind) &&
3652 !isOpenMPTaskLoopDirective(DKind)) &&
3653 Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::colon)) {
3654 Data.ExtraModifier = getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok),
3655 getLangOpts().OpenMP);
3656 Data.ExtraModifierLoc = Tok.getLocation();
3657 ConsumeToken();
3658 assert(Tok.is(tok::colon) && "Expected colon.")((Tok.is(tok::colon) && "Expected colon.") ? static_cast
<void> (0) : __assert_fail ("Tok.is(tok::colon) && \"Expected colon.\""
, "/build/llvm-toolchain-snapshot-13~++20210308111132+66e3a4abe99c/clang/lib/Parse/ParseOpenMP.cpp"
, 3658, __PRETTY_FUNCTION__))
;
3659 Data.ColonLoc = ConsumeToken();
3660 }
3661 } else if (Kind == OMPC_map) {
3662 // Handle map type for map clause.
3663 ColonProtectionRAIIObject ColonRAII(*this);
3664
3665 // The first identifier may be a list item, a map-type or a
3666 // map-type-modifier. The map-type can also be delete which has the same
3667 // spelling of the C++ delete keyword.
3668 Data.ExtraModifier = OMPC_MAP_unknown;
3669 Data.ExtraModifierLoc = Tok.getLocation();
3670
3671 // Check for presence of a colon in the map clause.
3672 TentativeParsingAction TPA(*this);
3673 bool ColonPresent = false;
3674 if (SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
3675 StopBeforeMatch)) {
3676 if (Tok.is(tok::colon))
3677 ColonPresent = true;
3678 }
3679 TPA.Revert();
3680 // Only parse map-type-modifier[s] and map-type if a colon is present in
3681 // the map clause.
3682 if (ColonPresent) {
3683 IsInvalidMapperModifier = parseMapTypeModifiers(Data);
3684 if (!IsInvalidMapperModifier)
3685 parseMapType(*this, Data);
3686 else
3687 SkipUntil(tok::colon, tok::annot_pragma_openmp_end, StopBeforeMatch);
3688 }
3689 if (Data.ExtraModifier == OMPC_MAP_unknown) {
3690 Data.ExtraModifier = OMPC_MAP_tofrom;
3691 Data.IsMapTypeImplicit = true;
3692 }
3693
3694 if (Tok.is(tok::colon))
3695 Data.ColonLoc = ConsumeToken();
3696 } else if (Kind == OMPC_to || Kind == OMPC_from) {
3697 while (Tok.is(tok::identifier)) {
3698 auto Modifier =
3699 static_cast<OpenMPMotionModifierKind>(getOpenMPSimpleClauseType(
3700 Kind, PP.getSpelling(Tok), getLangOpts().OpenMP));
3701 if (Modifier == OMPC_MOTION_MODIFIER_unknown)
3702 break;
3703 Data.MotionModifiers.push_back(Modifier);
3704 Data.MotionModifiersLoc.push_back(Tok.getLocation());
3705 ConsumeToken();
3706 if (Modifier == OMPC_MOTION_MODIFIER_mapper) {
3707 IsInvalidMapperModifier = parseMapperModifier(Data);
3708 if (IsInvalidMapperModifier)
3709 break;
3710 }
3711 // OpenMP < 5.1 doesn't permit a ',' or additional modifiers.
3712 if (getLangOpts().OpenMP < 51)
3713 break;
3714 // OpenMP 5.1 accepts an optional ',' even if the next character is ':'.
3715 // TODO: Is that intentional?
3716 if (Tok.is(tok::comma))
3717 ConsumeToken();
3718 }
3719 if (!Data.MotionModifiers.empty() && Tok.isNot(tok::colon)) {
3720 if (!IsInvalidMapperModifier) {
3721 if (getLangOpts().OpenMP < 51)
3722 Diag(Tok, diag::warn_pragma_expected_colon) << ")";
3723 else
3724 Diag(Tok, diag::warn_pragma_expected_colon) << "motion modifier";
3725 }
3726 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
3727 StopBeforeMatch);
3728 }
3729 // OpenMP 5.1 permits a ':' even without a preceding modifier. TODO: Is
3730 // that intentional?
3731 if ((!Data.MotionModifiers.empty() || getLangOpts().OpenMP >= 51) &&
3732 Tok.is(tok::colon))
3733 Data.ColonLoc = ConsumeToken();
3734 } else if (Kind == OMPC_allocate ||
3735 (Kind == OMPC_affinity && Tok.is(tok::identifier) &&
3736 PP.getSpelling(Tok) == "iterator")) {
3737 // Handle optional allocator expression followed by colon delimiter.
3738 ColonProtectionRAIIObject ColonRAII(*this);
3739 TentativeParsingAction TPA(*this);
3740 // OpenMP 5.0, 2.10.1, task Construct.
3741 // where aff-modifier is one of the following:
3742 // iterator(iterators-definition)
3743 ExprResult Tail;
3744 if (Kind == OMPC_allocate) {
3745 Tail = ParseAssignmentExpression();
3746 } else {
3747 HasIterator = true;
3748 EnterScope(Scope::OpenMPDirectiveScope | Scope::DeclScope);
3749 Tail = ParseOpenMPIteratorsExpr();
3750 }
3751 Tail = Actions.CorrectDelayedTyposInExpr(Tail);
3752 Tail = Actions.ActOnFinishFullExpr(Tail.get(), T.getOpenLocation(),
3753 /*DiscardedValue=*/false);
3754 if (Tail.isUsable()) {
3755 if (Tok.is(tok::colon)) {
3756 Data.DepModOrTailExpr = Tail.get();
3757 Data.ColonLoc = ConsumeToken();
3758 TPA.Commit();
3759 } else {
3760 // Colon not found, parse only list of variables.
3761 TPA.Revert();
3762 }
3763 } else {
3764 // Parsing was unsuccessfull, revert and skip to the end of clause or
3765 // directive.
3766 TPA.Revert();
3767 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
3768 StopBeforeMatch);
3769 }
3770 }
3771
3772 bool IsComma =
3773 (Kind != OMPC_reduction && Kind != OMPC_task_reduction &&
3774 Kind != OMPC_in_reduction && Kind != OMPC_depend && Kind != OMPC_map) ||
3775 (Kind == OMPC_reduction && !InvalidReductionId) ||
3776 (Kind == OMPC_map && Data.ExtraModifier != OMPC_MAP_unknown) ||
3777 (Kind == OMPC_depend && Data.ExtraModifier != OMPC_DEPEND_unknown);
3778 const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
3779 while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
3780 Tok.isNot(tok::annot_pragma_openmp_end))) {
3781 ParseScope OMPListScope(this, Scope::OpenMPDirectiveScope);
3782 ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail);
3783 // Parse variable
3784 ExprResult VarExpr =
3785 Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
3786 if (VarExpr.isUsable()) {
3787 Vars.push_back(VarExpr.get());
3788 } else {
3789 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
3790 StopBeforeMatch);
3791 }
3792 // Skip ',' if any
3793 IsComma = Tok.is(tok::comma);
3794 if (IsComma)
3795 ConsumeToken();
3796 else if (Tok.isNot(tok::r_paren) &&
3797 Tok.isNot(tok::annot_pragma_openmp_end) &&
3798 (!MayHaveTail || Tok.isNot(tok::colon)))
3799 Diag(Tok, diag::err_omp_expected_punc)
3800 << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush)
3801 : getOpenMPClauseName(Kind))
3802 << (Kind == OMPC_flush);
3803 }
3804
3805 // Parse ')' for linear clause with modifier.
3806 if (NeedRParenForLinear)
3807 LinearT.consumeClose();
3808
3809 // Parse ':' linear-step (or ':' alignment).
3810 const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon);
3811 if (MustHaveTail) {
3812 Data.ColonLoc = Tok.getLocation();
3813 SourceLocation ELoc = ConsumeToken();
3814 ExprResult Tail = ParseAssignmentExpression();
3815 Tail =
3816 Actions.ActOnFinishFullExpr(Tail.get(), ELoc, /*DiscardedValue*/ false);
3817 if (Tail.isUsable())
3818 Data.DepModOrTailExpr = Tail.get();
3819 else
3820 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
3821 StopBeforeMatch);
3822 }
3823
3824 // Parse ')'.
3825 Data.RLoc = Tok.getLocation();
3826 if (!T.consumeClose())
3827 Data.RLoc = T.getCloseLocation();
3828 // Exit from scope when the iterator is used in depend clause.
3829 if (HasIterator)
3830 ExitScope();
3831 return (Kind != OMPC_depend && Kind != OMPC_map && Vars.empty()) ||
3832 (MustHaveTail && !Data.DepModOrTailExpr) || InvalidReductionId ||
3833 IsInvalidMapperModifier;
3834}
3835
3836/// Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
3837/// 'shared', 'copyin', 'copyprivate', 'flush', 'reduction', 'task_reduction',
3838/// 'in_reduction', 'nontemporal', 'exclusive' or 'inclusive'.
3839///
3840/// private-clause:
3841/// 'private' '(' list ')'
3842/// firstprivate-clause:
3843/// 'firstprivate' '(' list ')'
3844/// lastprivate-clause:
3845/// 'lastprivate' '(' list ')'
3846/// shared-clause:
3847/// 'shared' '(' list ')'
3848/// linear-clause:
3849/// 'linear' '(' linear-list [ ':' linear-step ] ')'
3850/// aligned-clause:
3851/// 'aligned' '(' list [ ':' alignment ] ')'
3852/// reduction-clause:
3853/// 'reduction' '(' [ modifier ',' ] reduction-identifier ':' list ')'
3854/// task_reduction-clause:
3855/// 'task_reduction' '(' reduction-identifier ':' list ')'
3856/// in_reduction-clause:
3857/// 'in_reduction' '(' reduction-identifier ':' list ')'
3858/// copyprivate-clause:
3859/// 'copyprivate' '(' list ')'
3860/// flush-clause:
3861/// 'flush' '(' list ')'
3862/// depend-clause:
3863/// 'depend' '(' in | out | inout : list | source ')'
3864/// map-clause:
3865/// 'map' '(' [ [ always [,] ] [ close [,] ]
3866/// [ mapper '(' mapper-identifier ')' [,] ]
3867/// to | from | tofrom | alloc | release | delete ':' ] list ')';
3868/// to-clause:
3869/// 'to' '(' [ mapper '(' mapper-identifier ')' ':' ] list ')'
3870/// from-clause:
3871/// 'from' '(' [ mapper '(' mapper-identifier ')' ':' ] list ')'
3872/// use_device_ptr-clause:
3873/// 'use_device_ptr' '(' list ')'
3874/// use_device_addr-clause:
3875/// 'use_device_addr' '(' list ')'
3876/// is_device_ptr-clause:
3877/// 'is_device_ptr' '(' list ')'
3878/// allocate-clause:
3879/// 'allocate' '(' [ allocator ':' ] list ')'
3880/// nontemporal-clause:
3881/// 'nontemporal' '(' list ')'
3882/// inclusive-clause:
3883/// 'inclusive' '(' list ')'
3884/// exclusive-clause:
3885/// 'exclusive' '(' list ')'
3886///
3887/// For 'linear' clause linear-list may have the following forms:
3888/// list
3889/// modifier(list)
3890/// where modifier is 'val' (C) or 'ref', 'val' or 'uval'(C++).
3891OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
3892 OpenMPClauseKind Kind,
3893 bool ParseOnly) {
3894 SourceLocation Loc = Tok.getLocation();
3895 SourceLocation LOpen = ConsumeToken();
3896 SmallVector<Expr *, 4> Vars;
3897 OpenMPVarListDataTy Data;
3898
3899 if (ParseOpenMPVarList(DKind, Kind, Vars, Data))
3900 return nullptr;
3901
3902 if (ParseOnly)
3903 return nullptr;
3904 OMPVarListLocTy Locs(Loc, LOpen, Data.RLoc);
3905 return Actions.ActOnOpenMPVarListClause(
3906 Kind, Vars, Data.DepModOrTailExpr, Locs, Data.ColonLoc,
3907 Data.ReductionOrMapperIdScopeSpec, Data.ReductionOrMapperId,
3908 Data.ExtraModifier, Data.MapTypeModifiers, Data.MapTypeModifiersLoc,
3909 Data.IsMapTypeImplicit, Data.ExtraModifierLoc, Data.MotionModifiers,
3910 Data.MotionModifiersLoc);
3911}