Bug Summary

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