19#include "llvm/ADT/StringExtras.h"
20#include "llvm/Support/Casting.h"
29 case OpenACCDirectiveKind::Invalid:
33 case OpenACCDirectiveKind::ParallelLoop:
34 case OpenACCDirectiveKind::SerialLoop:
35 case OpenACCDirectiveKind::KernelsLoop:
36 case OpenACCDirectiveKind::Parallel:
37 case OpenACCDirectiveKind::Serial:
38 case OpenACCDirectiveKind::Kernels:
39 case OpenACCDirectiveKind::Loop:
40 case OpenACCDirectiveKind::Data:
41 case OpenACCDirectiveKind::EnterData:
42 case OpenACCDirectiveKind::ExitData:
43 case OpenACCDirectiveKind::HostData:
44 case OpenACCDirectiveKind::Wait:
46 return S.
Diag(StartLoc, diag::err_acc_construct_appertainment) << K;
57 case OpenACCClauseKind::Default:
58 switch (DirectiveKind) {
59 case OpenACCDirectiveKind::Parallel:
60 case OpenACCDirectiveKind::Serial:
61 case OpenACCDirectiveKind::Kernels:
62 case OpenACCDirectiveKind::ParallelLoop:
63 case OpenACCDirectiveKind::SerialLoop:
64 case OpenACCDirectiveKind::KernelsLoop:
65 case OpenACCDirectiveKind::Data:
70 case OpenACCClauseKind::If:
71 switch (DirectiveKind) {
72 case OpenACCDirectiveKind::Parallel:
73 case OpenACCDirectiveKind::Serial:
74 case OpenACCDirectiveKind::Kernels:
75 case OpenACCDirectiveKind::Data:
76 case OpenACCDirectiveKind::EnterData:
77 case OpenACCDirectiveKind::ExitData:
78 case OpenACCDirectiveKind::HostData:
79 case OpenACCDirectiveKind::Init:
80 case OpenACCDirectiveKind::Shutdown:
81 case OpenACCDirectiveKind::Set:
82 case OpenACCDirectiveKind::Update:
83 case OpenACCDirectiveKind::Wait:
84 case OpenACCDirectiveKind::ParallelLoop:
85 case OpenACCDirectiveKind::SerialLoop:
86 case OpenACCDirectiveKind::KernelsLoop:
91 case OpenACCClauseKind::Self:
92 switch (DirectiveKind) {
93 case OpenACCDirectiveKind::Parallel:
94 case OpenACCDirectiveKind::Serial:
95 case OpenACCDirectiveKind::Kernels:
96 case OpenACCDirectiveKind::Update:
97 case OpenACCDirectiveKind::ParallelLoop:
98 case OpenACCDirectiveKind::SerialLoop:
99 case OpenACCDirectiveKind::KernelsLoop:
104 case OpenACCClauseKind::NumGangs:
105 case OpenACCClauseKind::NumWorkers:
106 case OpenACCClauseKind::VectorLength:
107 switch (DirectiveKind) {
108 case OpenACCDirectiveKind::Parallel:
109 case OpenACCDirectiveKind::Kernels:
110 case OpenACCDirectiveKind::ParallelLoop:
111 case OpenACCDirectiveKind::KernelsLoop:
116 case OpenACCClauseKind::FirstPrivate:
117 switch (DirectiveKind) {
118 case OpenACCDirectiveKind::Parallel:
119 case OpenACCDirectiveKind::Serial:
120 case OpenACCDirectiveKind::ParallelLoop:
121 case OpenACCDirectiveKind::SerialLoop:
126 case OpenACCClauseKind::Private:
127 switch (DirectiveKind) {
128 case OpenACCDirectiveKind::Parallel:
129 case OpenACCDirectiveKind::Serial:
130 case OpenACCDirectiveKind::Loop:
131 case OpenACCDirectiveKind::ParallelLoop:
132 case OpenACCDirectiveKind::SerialLoop:
133 case OpenACCDirectiveKind::KernelsLoop:
138 case OpenACCClauseKind::NoCreate:
139 switch (DirectiveKind) {
140 case OpenACCDirectiveKind::Parallel:
141 case OpenACCDirectiveKind::Serial:
142 case OpenACCDirectiveKind::Kernels:
143 case OpenACCDirectiveKind::Data:
144 case OpenACCDirectiveKind::ParallelLoop:
145 case OpenACCDirectiveKind::SerialLoop:
146 case OpenACCDirectiveKind::KernelsLoop:
151 case OpenACCClauseKind::Present:
152 switch (DirectiveKind) {
153 case OpenACCDirectiveKind::Parallel:
154 case OpenACCDirectiveKind::Serial:
155 case OpenACCDirectiveKind::Kernels:
156 case OpenACCDirectiveKind::Data:
157 case OpenACCDirectiveKind::Declare:
158 case OpenACCDirectiveKind::ParallelLoop:
159 case OpenACCDirectiveKind::SerialLoop:
160 case OpenACCDirectiveKind::KernelsLoop:
166 case OpenACCClauseKind::Copy:
167 case OpenACCClauseKind::PCopy:
168 case OpenACCClauseKind::PresentOrCopy:
169 switch (DirectiveKind) {
170 case OpenACCDirectiveKind::Parallel:
171 case OpenACCDirectiveKind::Serial:
172 case OpenACCDirectiveKind::Kernels:
173 case OpenACCDirectiveKind::Data:
174 case OpenACCDirectiveKind::Declare:
175 case OpenACCDirectiveKind::ParallelLoop:
176 case OpenACCDirectiveKind::SerialLoop:
177 case OpenACCDirectiveKind::KernelsLoop:
182 case OpenACCClauseKind::CopyIn:
183 case OpenACCClauseKind::PCopyIn:
184 case OpenACCClauseKind::PresentOrCopyIn:
185 switch (DirectiveKind) {
186 case OpenACCDirectiveKind::Parallel:
187 case OpenACCDirectiveKind::Serial:
188 case OpenACCDirectiveKind::Kernels:
189 case OpenACCDirectiveKind::Data:
190 case OpenACCDirectiveKind::EnterData:
191 case OpenACCDirectiveKind::Declare:
192 case OpenACCDirectiveKind::ParallelLoop:
193 case OpenACCDirectiveKind::SerialLoop:
194 case OpenACCDirectiveKind::KernelsLoop:
199 case OpenACCClauseKind::CopyOut:
200 case OpenACCClauseKind::PCopyOut:
201 case OpenACCClauseKind::PresentOrCopyOut:
202 switch (DirectiveKind) {
203 case OpenACCDirectiveKind::Parallel:
204 case OpenACCDirectiveKind::Serial:
205 case OpenACCDirectiveKind::Kernels:
206 case OpenACCDirectiveKind::Data:
207 case OpenACCDirectiveKind::ExitData:
208 case OpenACCDirectiveKind::Declare:
209 case OpenACCDirectiveKind::ParallelLoop:
210 case OpenACCDirectiveKind::SerialLoop:
211 case OpenACCDirectiveKind::KernelsLoop:
216 case OpenACCClauseKind::Create:
217 case OpenACCClauseKind::PCreate:
218 case OpenACCClauseKind::PresentOrCreate:
219 switch (DirectiveKind) {
220 case OpenACCDirectiveKind::Parallel:
221 case OpenACCDirectiveKind::Serial:
222 case OpenACCDirectiveKind::Kernels:
223 case OpenACCDirectiveKind::Data:
224 case OpenACCDirectiveKind::EnterData:
225 case OpenACCDirectiveKind::ParallelLoop:
226 case OpenACCDirectiveKind::SerialLoop:
227 case OpenACCDirectiveKind::KernelsLoop:
233 case OpenACCClauseKind::Attach:
234 switch (DirectiveKind) {
235 case OpenACCDirectiveKind::Parallel:
236 case OpenACCDirectiveKind::Serial:
237 case OpenACCDirectiveKind::Kernels:
238 case OpenACCDirectiveKind::Data:
239 case OpenACCDirectiveKind::EnterData:
240 case OpenACCDirectiveKind::ParallelLoop:
241 case OpenACCDirectiveKind::SerialLoop:
242 case OpenACCDirectiveKind::KernelsLoop:
247 case OpenACCClauseKind::DevicePtr:
248 switch (DirectiveKind) {
249 case OpenACCDirectiveKind::Parallel:
250 case OpenACCDirectiveKind::Serial:
251 case OpenACCDirectiveKind::Kernels:
252 case OpenACCDirectiveKind::Data:
253 case OpenACCDirectiveKind::Declare:
254 case OpenACCDirectiveKind::ParallelLoop:
255 case OpenACCDirectiveKind::SerialLoop:
256 case OpenACCDirectiveKind::KernelsLoop:
261 case OpenACCClauseKind::Async:
262 switch (DirectiveKind) {
263 case OpenACCDirectiveKind::Parallel:
264 case OpenACCDirectiveKind::Serial:
265 case OpenACCDirectiveKind::Kernels:
266 case OpenACCDirectiveKind::Data:
267 case OpenACCDirectiveKind::EnterData:
268 case OpenACCDirectiveKind::ExitData:
269 case OpenACCDirectiveKind::Set:
270 case OpenACCDirectiveKind::Update:
271 case OpenACCDirectiveKind::Wait:
272 case OpenACCDirectiveKind::ParallelLoop:
273 case OpenACCDirectiveKind::SerialLoop:
274 case OpenACCDirectiveKind::KernelsLoop:
279 case OpenACCClauseKind::Wait:
280 switch (DirectiveKind) {
281 case OpenACCDirectiveKind::Parallel:
282 case OpenACCDirectiveKind::Serial:
283 case OpenACCDirectiveKind::Kernels:
284 case OpenACCDirectiveKind::Data:
285 case OpenACCDirectiveKind::EnterData:
286 case OpenACCDirectiveKind::ExitData:
287 case OpenACCDirectiveKind::Update:
288 case OpenACCDirectiveKind::ParallelLoop:
289 case OpenACCDirectiveKind::SerialLoop:
290 case OpenACCDirectiveKind::KernelsLoop:
296 case OpenACCClauseKind::Seq:
297 switch (DirectiveKind) {
298 case OpenACCDirectiveKind::Loop:
299 case OpenACCDirectiveKind::Routine:
300 case OpenACCDirectiveKind::ParallelLoop:
301 case OpenACCDirectiveKind::SerialLoop:
302 case OpenACCDirectiveKind::KernelsLoop:
308 case OpenACCClauseKind::Independent:
309 case OpenACCClauseKind::Auto:
310 switch (DirectiveKind) {
311 case OpenACCDirectiveKind::Loop:
312 case OpenACCDirectiveKind::ParallelLoop:
313 case OpenACCDirectiveKind::SerialLoop:
314 case OpenACCDirectiveKind::KernelsLoop:
320 case OpenACCClauseKind::Reduction:
321 switch (DirectiveKind) {
322 case OpenACCDirectiveKind::Parallel:
323 case OpenACCDirectiveKind::Serial:
324 case OpenACCDirectiveKind::Loop:
325 case OpenACCDirectiveKind::ParallelLoop:
326 case OpenACCDirectiveKind::SerialLoop:
327 case OpenACCDirectiveKind::KernelsLoop:
333 case OpenACCClauseKind::DeviceType:
334 case OpenACCClauseKind::DType:
335 switch (DirectiveKind) {
336 case OpenACCDirectiveKind::Parallel:
337 case OpenACCDirectiveKind::Serial:
338 case OpenACCDirectiveKind::Kernels:
339 case OpenACCDirectiveKind::Data:
340 case OpenACCDirectiveKind::Init:
341 case OpenACCDirectiveKind::Shutdown:
342 case OpenACCDirectiveKind::Set:
343 case OpenACCDirectiveKind::Update:
344 case OpenACCDirectiveKind::Loop:
345 case OpenACCDirectiveKind::Routine:
346 case OpenACCDirectiveKind::ParallelLoop:
347 case OpenACCDirectiveKind::SerialLoop:
348 case OpenACCDirectiveKind::KernelsLoop:
354 case OpenACCClauseKind::Collapse: {
355 switch (DirectiveKind) {
356 case OpenACCDirectiveKind::Loop:
357 case OpenACCDirectiveKind::ParallelLoop:
358 case OpenACCDirectiveKind::SerialLoop:
359 case OpenACCDirectiveKind::KernelsLoop:
365 case OpenACCClauseKind::Tile: {
366 switch (DirectiveKind) {
367 case OpenACCDirectiveKind::Loop:
368 case OpenACCDirectiveKind::ParallelLoop:
369 case OpenACCDirectiveKind::SerialLoop:
370 case OpenACCDirectiveKind::KernelsLoop:
377 case OpenACCClauseKind::Gang: {
378 switch (DirectiveKind) {
379 case OpenACCDirectiveKind::Loop:
380 case OpenACCDirectiveKind::ParallelLoop:
381 case OpenACCDirectiveKind::SerialLoop:
382 case OpenACCDirectiveKind::KernelsLoop:
383 case OpenACCDirectiveKind::Routine:
388 case OpenACCClauseKind::Worker: {
389 switch (DirectiveKind) {
390 case OpenACCDirectiveKind::Loop:
391 case OpenACCDirectiveKind::ParallelLoop:
392 case OpenACCDirectiveKind::SerialLoop:
393 case OpenACCDirectiveKind::KernelsLoop:
394 case OpenACCDirectiveKind::Routine:
400 case OpenACCClauseKind::Vector: {
401 switch (DirectiveKind) {
402 case OpenACCDirectiveKind::Loop:
403 case OpenACCDirectiveKind::ParallelLoop:
404 case OpenACCDirectiveKind::SerialLoop:
405 case OpenACCDirectiveKind::KernelsLoop:
406 case OpenACCDirectiveKind::Routine:
412 case OpenACCClauseKind::Finalize: {
413 switch (DirectiveKind) {
414 case OpenACCDirectiveKind::ExitData:
420 case OpenACCClauseKind::IfPresent: {
421 switch (DirectiveKind) {
422 case OpenACCDirectiveKind::HostData:
423 case OpenACCDirectiveKind::Update:
429 case OpenACCClauseKind::Delete: {
430 switch (DirectiveKind) {
431 case OpenACCDirectiveKind::ExitData:
438 case OpenACCClauseKind::Detach: {
439 switch (DirectiveKind) {
440 case OpenACCDirectiveKind::ExitData:
447 case OpenACCClauseKind::DeviceNum: {
448 switch (DirectiveKind) {
449 case OpenACCDirectiveKind::Init:
450 case OpenACCDirectiveKind::Shutdown:
451 case OpenACCDirectiveKind::Set:
458 case OpenACCClauseKind::UseDevice: {
459 switch (DirectiveKind) {
460 case OpenACCDirectiveKind::HostData:
472 llvm_unreachable(
"Invalid clause kind");
475bool checkAlreadyHasClauseOfKind(
478 const auto *Itr = llvm::find_if(ExistingClauses, [&](
const OpenACCClause *
C) {
481 if (Itr != ExistingClauses.end()) {
482 S.
Diag(Clause.
getBeginLoc(), diag::err_acc_duplicate_clause_disallowed)
484 S.
Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
490bool checkValidAfterDeviceType(
497 NewClause.getDirectiveKind() != OpenACCDirectiveKind::Loop &&
498 NewClause.getDirectiveKind() != OpenACCDirectiveKind::Data)
517 case OpenACCClauseKind::Async:
518 case OpenACCClauseKind::Wait:
519 case OpenACCClauseKind::NumGangs:
520 case OpenACCClauseKind::NumWorkers:
521 case OpenACCClauseKind::VectorLength:
526 }
else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Loop) {
531 case OpenACCClauseKind::Collapse:
532 case OpenACCClauseKind::Gang:
533 case OpenACCClauseKind::Worker:
534 case OpenACCClauseKind::Vector:
535 case OpenACCClauseKind::Seq:
536 case OpenACCClauseKind::Independent:
537 case OpenACCClauseKind::Auto:
538 case OpenACCClauseKind::Tile:
546 case OpenACCClauseKind::Async:
547 case OpenACCClauseKind::Wait:
548 case OpenACCClauseKind::NumGangs:
549 case OpenACCClauseKind::NumWorkers:
550 case OpenACCClauseKind::VectorLength:
551 case OpenACCClauseKind::Collapse:
552 case OpenACCClauseKind::Gang:
553 case OpenACCClauseKind::Worker:
554 case OpenACCClauseKind::Vector:
555 case OpenACCClauseKind::Seq:
556 case OpenACCClauseKind::Independent:
557 case OpenACCClauseKind::Auto:
558 case OpenACCClauseKind::Tile:
563 }
else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Data) {
567 case OpenACCClauseKind::Async:
568 case OpenACCClauseKind::Wait:
574 S.
Diag(NewClause.
getBeginLoc(), diag::err_acc_clause_after_device_type)
576 << NewClause.getDirectiveKind();
577 S.
Diag(DeviceTypeClause.
getBeginLoc(), diag::note_acc_previous_clause_here);
588 DK == OpenACCDirectiveKind::Loop || DK == OpenACCDirectiveKind::Wait ||
589 DK == OpenACCDirectiveKind::Init ||
590 DK == OpenACCDirectiveKind::Shutdown;
593class SemaOpenACCClauseVisitor {
597 bool NotImplemented =
false;
600 NotImplemented =
true;
609 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCSeqClause>);
611 if (Itr != ExistingClauses.end()) {
612 SemaRef.
Diag(Clause.
getBeginLoc(), diag::err_acc_clause_cannot_combine)
615 SemaRef.
Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
625 : SemaRef(S), Ctx(S.getASTContext()), ExistingClauses(ExistingClauses) {}
629 bool diagNotImplemented() {
return NotImplemented; }
633#define VISIT_CLAUSE(CLAUSE_NAME) \
634 case OpenACCClauseKind::CLAUSE_NAME: \
635 return Visit##CLAUSE_NAME##Clause(Clause);
636#define CLAUSE_ALIAS(ALIAS, CLAUSE_NAME, DEPRECATED) \
637 case OpenACCClauseKind::ALIAS: \
639 SemaRef.Diag(Clause.getBeginLoc(), diag::warn_acc_deprecated_alias_name) \
640 << Clause.getClauseKind() << OpenACCClauseKind::CLAUSE_NAME; \
641 return Visit##CLAUSE_NAME##Clause(Clause);
642#include "clang/Basic/OpenACCClauses.def"
644 return isNotImplemented();
646 llvm_unreachable(
"Invalid clause kind");
649#define VISIT_CLAUSE(CLAUSE_NAME) \
650 OpenACCClause *Visit##CLAUSE_NAME##Clause( \
651 SemaOpenACC::OpenACCParsedClause &Clause);
652#include "clang/Basic/OpenACCClauses.def"
665 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
681 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
693 NewSizeExprs.push_back(Res.
get());
708 return isNotImplemented();
718 checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
729 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCSelfClause>);
730 if (Itr != ExistingClauses.end()) {
732 SemaRef.
Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
746 return isNotImplemented();
755 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
763 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCIfClause>);
764 if (Itr != ExistingClauses.end()) {
766 SemaRef.
Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
778 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
805 auto *GangClauseItr =
806 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
807 auto *ReductionClauseItr =
808 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
810 if (GangClauseItr != ExistingClauses.end() &&
811 ReductionClauseItr != ExistingClauses.end()) {
813 diag::err_acc_gang_reduction_numgangs_conflict)
814 << OpenACCClauseKind::Reduction << OpenACCClauseKind::Gang
816 SemaRef.
Diag((*ReductionClauseItr)->getBeginLoc(),
817 diag::note_acc_previous_clause_here);
818 SemaRef.
Diag((*GangClauseItr)->getBeginLoc(),
819 diag::note_acc_previous_clause_here);
831 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
833 if (
Parallel != ExistingClauses.end()) {
835 diag::err_acc_reduction_num_gangs_conflict)
838 SemaRef.
Diag((*Parallel)->getBeginLoc(),
839 diag::note_acc_previous_clause_here);
848 auto GangClauses = llvm::make_filter_range(
849 ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
851 for (
auto *GC : GangClauses) {
852 if (cast<OpenACCGangClause>(GC)->hasExprOfKind(OpenACCGangKind::Num)) {
854 diag::err_acc_num_arg_conflict_reverse)
855 << OpenACCClauseKind::NumGangs << OpenACCClauseKind::Gang
857 SemaRef.
Diag(GC->getBeginLoc(), diag::note_acc_previous_clause_here);
868OpenACCClause *SemaOpenACCClauseVisitor::VisitNumWorkersClause(
873 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
880 auto WorkerClauses = llvm::make_filter_range(
881 ExistingClauses, llvm::IsaPred<OpenACCWorkerClause>);
883 for (
auto *WC : WorkerClauses) {
884 if (cast<OpenACCWorkerClause>(WC)->hasIntExpr()) {
886 diag::err_acc_num_arg_conflict_reverse)
887 << OpenACCClauseKind::NumWorkers << OpenACCClauseKind::Worker
889 SemaRef.
Diag(WC->getBeginLoc(), diag::note_acc_previous_clause_here);
896 "Invalid number of expressions for NumWorkers");
902OpenACCClause *SemaOpenACCClauseVisitor::VisitVectorLengthClause(
907 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
914 auto VectorClauses = llvm::make_filter_range(
915 ExistingClauses, llvm::IsaPred<OpenACCVectorClause>);
917 for (
auto *VC : VectorClauses) {
918 if (cast<OpenACCVectorClause>(VC)->hasIntExpr()) {
920 diag::err_acc_num_arg_conflict_reverse)
921 << OpenACCClauseKind::VectorLength << OpenACCClauseKind::Vector
923 SemaRef.
Diag(VC->getBeginLoc(), diag::note_acc_previous_clause_here);
930 "Invalid number of expressions for NumWorkers");
943 return isNotImplemented();
948 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
952 "Invalid number of expressions for Async");
959OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceNumClause(
964 return isNotImplemented();
967 "Invalid number of expressions for device_num");
984OpenACCClause *SemaOpenACCClauseVisitor::VisitFirstPrivateClause(
1013 return isNotImplemented();
1030 return isNotImplemented();
1047 return isNotImplemented();
1064 return isNotImplemented();
1090 llvm::erase_if(VarList, [&](
Expr *
E) {
1105 llvm::erase_if(VarList, [&](
Expr *
E) {
1125OpenACCClause *SemaOpenACCClauseVisitor::VisitUseDeviceClause(
1134OpenACCClause *SemaOpenACCClauseVisitor::VisitDevicePtrClause(
1141 return isNotImplemented();
1146 llvm::erase_if(VarList, [&](
Expr *
E) {
1164 return isNotImplemented();
1171OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause(
1178 return isNotImplemented();
1194 llvm::find_if(ExistingClauses,
1195 llvm::IsaPred<OpenACCIndependentClause, OpenACCSeqClause>);
1196 if (Itr != ExistingClauses.end()) {
1199 SemaRef.
Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
1207OpenACCClause *SemaOpenACCClauseVisitor::VisitIndependentClause(
1211 const auto *Itr = llvm::find_if(
1212 ExistingClauses, llvm::IsaPred<OpenACCAutoClause, OpenACCSeqClause>);
1213 if (Itr != ExistingClauses.end()) {
1216 SemaRef.
Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
1225 if (isa<OpenACCAsteriskSizeExpr>(
E))
1227 return S.ActOnIntExpr(OpenACCDirectiveKind::Invalid, OpenACCClauseKind::Gang,
1232 return DK == OpenACCDirectiveKind::Loop &&
1233 AssocKind == OpenACCDirectiveKind::Invalid;
1237 return DK == OpenACCDirectiveKind::Loop &&
1238 AssocKind != OpenACCDirectiveKind::Invalid;
1245 << GK << CK << IsOrphanLoop(DK, AssocKind) << DK
1246 << HasAssocKind(DK, AssocKind) << AssocKind;
1253 << TagKind << CK << IsOrphanLoop(DK, AssocKind) << DK
1254 << HasAssocKind(DK, AssocKind) << AssocKind;
1262 case OpenACCGangKind::Static:
1263 return CheckGangStaticExpr(S,
E);
1264 case OpenACCGangKind::Num:
1268 return DiagIntArgInvalid(S,
E, GK, OpenACCClauseKind::Gang, DK, AssocKind);
1269 case OpenACCGangKind::Dim: {
1277 S.ActOnIntExpr(OpenACCDirectiveKind::Invalid, OpenACCClauseKind::Gang,
1286 std::optional<llvm::APSInt> ICE =
1289 if (!ICE || *ICE <= 0 || ICE > 3) {
1291 << ICE.has_value() << ICE.value_or(llvm::APSInt{}).getExtValue();
1299 llvm_unreachable(
"Unknown gang kind in gang parallel check");
1311 case OpenACCGangKind::Dim:
1312 return DiagIntArgInvalid(S,
E, GK, OpenACCClauseKind::Gang, DK, AssocKind);
1313 case OpenACCGangKind::Num: {
1325 : S.getActiveComputeConstructInfo().Clauses;
1328 llvm::find_if(Collection, llvm::IsaPred<OpenACCNumGangsClause>);
1330 if (Itr != Collection.end()) {
1332 <<
"num" << OpenACCClauseKind::Gang << DK
1333 << HasAssocKind(DK, AssocKind) << AssocKind
1334 << OpenACCClauseKind::NumGangs;
1336 S.
Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
1341 case OpenACCGangKind::Static:
1342 return CheckGangStaticExpr(S,
E);
1345 llvm_unreachable(
"Unknown gang kind in gang kernels check");
1354 case OpenACCGangKind::Dim:
1355 case OpenACCGangKind::Num:
1356 return DiagIntArgInvalid(S,
E, GK, OpenACCClauseKind::Gang, DK, AssocKind);
1357 case OpenACCGangKind::Static:
1358 return CheckGangStaticExpr(S,
E);
1360 llvm_unreachable(
"Unknown gang kind in gang serial check");
1365 if (DiagIfSeqClause(Clause))
1372 return isNotImplemented();
1379 case OpenACCDirectiveKind::Invalid:
1380 case OpenACCDirectiveKind::Parallel:
1383 case OpenACCDirectiveKind::Serial:
1386 DiagIntArgInvalid(SemaRef, IntExpr,
"length", OpenACCClauseKind::Vector,
1391 case OpenACCDirectiveKind::Kernels: {
1394 llvm::IsaPred<OpenACCVectorLengthClause>);
1397 <<
"length" << OpenACCClauseKind::Vector
1402 << OpenACCClauseKind::VectorLength;
1403 SemaRef.
Diag((*Itr)->getBeginLoc(),
1404 diag::note_acc_previous_clause_here);
1411 llvm_unreachable(
"Non compute construct in active compute construct");
1415 DiagIntArgInvalid(SemaRef, IntExpr,
"length", OpenACCClauseKind::Vector,
1420 OpenACCDirectiveKind::KernelsLoop) {
1421 const auto *Itr = llvm::find_if(
1422 ExistingClauses, llvm::IsaPred<OpenACCVectorLengthClause>);
1423 if (Itr != ExistingClauses.end()) {
1425 <<
"length" << OpenACCClauseKind::Vector
1430 << OpenACCClauseKind::VectorLength;
1431 SemaRef.
Diag((*Itr)->getBeginLoc(),
1432 diag::note_acc_previous_clause_here);
1447 SemaRef.
Diag(Clause.
getBeginLoc(), diag::err_acc_clause_in_clause_region)
1448 << OpenACCClauseKind::Vector << OpenACCClauseKind::Vector
1451 diag::note_acc_previous_clause_here);
1463 if (DiagIfSeqClause(Clause))
1470 return isNotImplemented();
1478 case OpenACCDirectiveKind::Invalid:
1479 case OpenACCDirectiveKind::ParallelLoop:
1480 case OpenACCDirectiveKind::SerialLoop:
1481 case OpenACCDirectiveKind::Parallel:
1482 case OpenACCDirectiveKind::Serial:
1483 DiagIntArgInvalid(SemaRef, IntExpr, OpenACCGangKind::Num,
1488 case OpenACCDirectiveKind::KernelsLoop:
1489 case OpenACCDirectiveKind::Kernels: {
1492 llvm::IsaPred<OpenACCNumWorkersClause>);
1499 << OpenACCClauseKind::NumWorkers;
1500 SemaRef.
Diag((*Itr)->getBeginLoc(),
1501 diag::note_acc_previous_clause_here);
1508 llvm_unreachable(
"Non compute construct in active compute construct");
1513 DiagIntArgInvalid(SemaRef, IntExpr, OpenACCGangKind::Num,
1519 "Unknown combined directive kind?");
1520 const auto *Itr = llvm::find_if(ExistingClauses,
1521 llvm::IsaPred<OpenACCNumWorkersClause>);
1522 if (Itr != ExistingClauses.end()) {
1528 << OpenACCClauseKind::NumWorkers;
1529 SemaRef.
Diag((*Itr)->getBeginLoc(),
1530 diag::note_acc_previous_clause_here);
1545 SemaRef.
Diag(Clause.
getBeginLoc(), diag::err_acc_clause_in_clause_region)
1546 << OpenACCClauseKind::Worker << OpenACCClauseKind::Worker
1549 diag::note_acc_previous_clause_here);
1559 SemaRef.
Diag(Clause.
getBeginLoc(), diag::err_acc_clause_in_clause_region)
1560 << OpenACCClauseKind::Worker << OpenACCClauseKind::Vector
1563 diag::note_acc_previous_clause_here);
1575 if (DiagIfSeqClause(Clause))
1582 return isNotImplemented();
1589 OpenACCDirectiveKind::Invalid) ||
1592 auto ActiveComputeConstructContainer =
1596 auto *NumGangsClauseItr = llvm::find_if(
1597 ActiveComputeConstructContainer, llvm::IsaPred<OpenACCNumGangsClause>);
1599 if (NumGangsClauseItr != ActiveComputeConstructContainer.end() &&
1600 cast<OpenACCNumGangsClause>(*NumGangsClauseItr)->getIntExprs().size() >
1602 auto *ReductionClauseItr =
1603 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
1605 if (ReductionClauseItr != ExistingClauses.end()) {
1607 diag::err_acc_gang_reduction_numgangs_conflict)
1608 << OpenACCClauseKind::Gang << OpenACCClauseKind::Reduction
1611 SemaRef.
Diag((*ReductionClauseItr)->getBeginLoc(),
1612 diag::note_acc_previous_clause_here);
1613 SemaRef.
Diag((*NumGangsClauseItr)->getBeginLoc(),
1614 diag::note_acc_previous_clause_here);
1627 for (
unsigned I = 0; I < Clause.
getIntExprs().size(); ++I) {
1638 if (ExistingElemLoc[
static_cast<unsigned>(GK)].isValid()) {
1640 <<
static_cast<unsigned>(GK);
1641 SemaRef.
Diag(ExistingElemLoc[
static_cast<unsigned>(GK)],
1642 diag::note_acc_previous_expr_here);
1646 ExistingElemLoc[
static_cast<unsigned>(GK)] = ER.
get()->
getBeginLoc();
1647 GangKinds.push_back(GK);
1648 IntExprs.push_back(ER.
get());
1659 SemaRef.
Diag(Clause.
getBeginLoc(), diag::err_acc_clause_in_clause_region)
1660 << OpenACCClauseKind::Gang << OpenACCClauseKind::Gang
1664 diag::note_acc_previous_clause_here);
1674 SemaRef.
Diag(Clause.
getBeginLoc(), diag::err_acc_clause_in_clause_region)
1675 << OpenACCClauseKind::Gang << OpenACCClauseKind::Worker
1678 diag::note_acc_previous_clause_here);
1688 SemaRef.
Diag(Clause.
getBeginLoc(), diag::err_acc_clause_in_clause_region)
1689 << OpenACCClauseKind::Gang << OpenACCClauseKind::Vector
1692 diag::note_acc_previous_clause_here);
1699 GangKinds, IntExprs, Clause.
getEndLoc());
1702OpenACCClause *SemaOpenACCClauseVisitor::VisitFinalizeClause(
1710OpenACCClause *SemaOpenACCClauseVisitor::VisitIfPresentClause(
1713 return isNotImplemented();
1726 return isNotImplemented();
1731 llvm::find_if(ExistingClauses,
1732 llvm::IsaPred<OpenACCAutoClause, OpenACCIndependentClause>);
1733 if (Itr != ExistingClauses.end()) {
1736 SemaRef.
Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
1743 Itr = llvm::find_if(ExistingClauses,
1747 if (Itr != ExistingClauses.end()) {
1748 SemaRef.
Diag(Clause.
getBeginLoc(), diag::err_acc_clause_cannot_combine)
1751 SemaRef.
Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
1759OpenACCClause *SemaOpenACCClauseVisitor::VisitReductionClause(
1766 OpenACCDirectiveKind::Invalid) ||
1769 auto ActiveComputeConstructContainer =
1773 auto *NumGangsClauseItr = llvm::find_if(
1774 ActiveComputeConstructContainer, llvm::IsaPred<OpenACCNumGangsClause>);
1776 if (NumGangsClauseItr != ActiveComputeConstructContainer.end() &&
1777 cast<OpenACCNumGangsClause>(*NumGangsClauseItr)->getIntExprs().size() >
1779 auto *GangClauseItr =
1780 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
1782 if (GangClauseItr != ExistingClauses.end()) {
1784 diag::err_acc_gang_reduction_numgangs_conflict)
1785 << OpenACCClauseKind::Reduction << OpenACCClauseKind::Gang
1788 SemaRef.
Diag((*GangClauseItr)->getBeginLoc(),
1789 diag::note_acc_previous_clause_here);
1790 SemaRef.
Diag((*NumGangsClauseItr)->getBeginLoc(),
1791 diag::note_acc_previous_clause_here);
1819 auto NumGangsClauses = llvm::make_filter_range(
1820 ExistingClauses, llvm::IsaPred<OpenACCNumGangsClause>);
1822 for (
auto *NGC : NumGangsClauses) {
1824 cast<OpenACCNumGangsClause>(NGC)->getIntExprs().size();
1828 diag::err_acc_reduction_num_gangs_conflict)
1831 SemaRef.
Diag(NGC->getBeginLoc(), diag::note_acc_previous_clause_here);
1844 ValidVars.push_back(Res.
get());
1853OpenACCClause *SemaOpenACCClauseVisitor::VisitCollapseClause(
1860 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
1873void CollectActiveReductionClauses(
1876 for (
auto *CurClause : CurClauses) {
1877 if (
auto *RedClause = dyn_cast<OpenACCReductionClause>(CurClause);
1878 RedClause && !RedClause->getVarList().empty())
1879 ActiveClauses.push_back(RedClause);
1887 case OpenACCDirectiveKind::Parallel:
1888 case OpenACCDirectiveKind::ParallelLoop:
1889 case OpenACCDirectiveKind::Serial:
1890 case OpenACCDirectiveKind::SerialLoop:
1891 case OpenACCDirectiveKind::Kernels:
1892 case OpenACCDirectiveKind::KernelsLoop:
1893 case OpenACCDirectiveKind::Loop:
1895 case OpenACCDirectiveKind::Data:
1896 case OpenACCDirectiveKind::HostData:
1898 case OpenACCDirectiveKind::EnterData:
1899 case OpenACCDirectiveKind::ExitData:
1900 case OpenACCDirectiveKind::Wait:
1901 case OpenACCDirectiveKind::Init:
1902 case OpenACCDirectiveKind::Shutdown:
1903 llvm_unreachable(
"Doesn't have an associated stmt");
1905 case OpenACCDirectiveKind::Invalid:
1906 llvm_unreachable(
"Unhandled directive kind?");
1908 llvm_unreachable(
"Unhandled directive kind?");
1919 : SemaRef(S), OldActiveComputeConstructInfo(S.ActiveComputeConstructInfo),
1920 DirKind(DK), OldLoopGangClauseOnKernel(S.LoopGangClauseOnKernel),
1921 OldLoopWorkerClauseLoc(S.LoopWorkerClauseLoc),
1922 OldLoopVectorClauseLoc(S.LoopVectorClauseLoc),
1923 OldLoopWithoutSeqInfo(S.LoopWithoutSeqInfo),
1924 ActiveReductionClauses(S.ActiveReductionClauses),
1925 LoopRAII(SemaRef, PreserveLoopRAIIDepthInAssociatedStmtRAII(DirKind)) {
1931 CollectActiveReductionClauses(S.ActiveReductionClauses, Clauses);
1932 SemaRef.ActiveComputeConstructInfo.Kind = DirKind;
1933 SemaRef.ActiveComputeConstructInfo.Clauses = Clauses;
1948 SemaRef.ActiveComputeConstructInfo.Kind = DirKind;
1949 SemaRef.ActiveComputeConstructInfo.Clauses = Clauses;
1951 CollectActiveReductionClauses(S.ActiveReductionClauses, Clauses);
1962 if (Clauses.end() ==
1963 llvm::find_if(Clauses, llvm::IsaPred<OpenACCSeqClause>))
1976 auto *Itr = llvm::find_if(Clauses, llvm::IsaPred<OpenACCGangClause>);
1977 if (Itr != Clauses.end())
1981 if (UnInstClauses.empty()) {
1982 auto *Itr = llvm::find_if(Clauses, llvm::IsaPred<OpenACCWorkerClause>);
1983 if (Itr != Clauses.end())
1986 auto *Itr2 = llvm::find_if(Clauses, llvm::IsaPred<OpenACCVectorClause>);
1987 if (Itr2 != Clauses.end())
1991 CollectActiveReductionClauses(S.ActiveReductionClauses, Clauses);
1998 if (Clauses.end() ==
1999 llvm::find_if(Clauses, llvm::IsaPred<OpenACCSeqClause>))
2012 UnInstClauses.empty()) {
2014 auto *Itr = llvm::find_if(Clauses, llvm::IsaPred<OpenACCGangClause>);
2015 if (Itr != Clauses.end())
2020 if (UnInstClauses.empty()) {
2021 auto *Itr = llvm::find_if(Clauses, llvm::IsaPred<OpenACCWorkerClause>);
2022 if (Itr != Clauses.end())
2025 auto *Itr2 = llvm::find_if(Clauses, llvm::IsaPred<OpenACCVectorClause>);
2026 if (Itr2 != Clauses.end())
2037 SemaRef.LoopInfo.CurLevelHasLoopAlready =
false;
2038 SemaRef.CollapseInfo.CollapseDepthSatisfied =
true;
2039 SemaRef.TileInfo.TileDepthSatisfied =
true;
2046 auto *CollapseClauseItr =
2047 llvm::find_if(Clauses, llvm::IsaPred<OpenACCCollapseClause>);
2048 auto *UnInstCollapseClauseItr =
2049 llvm::find_if(UnInstClauses, llvm::IsaPred<OpenACCCollapseClause>);
2051 if (Clauses.end() == CollapseClauseItr)
2055 cast<OpenACCCollapseClause>(*CollapseClauseItr);
2057 SemaRef.CollapseInfo.ActiveCollapse = CollapseClause;
2067 if (UnInstCollapseClauseItr != UnInstClauses.end() &&
2068 !cast<OpenACCCollapseClause>(*UnInstCollapseClauseItr)
2070 ->isInstantiationDependent())
2073 SemaRef.CollapseInfo.CollapseDepthSatisfied =
false;
2074 SemaRef.CollapseInfo.CurCollapseCount =
2075 cast<ConstantExpr>(LoopCount)->getResultAsAPSInt();
2076 SemaRef.CollapseInfo.DirectiveKind = DirKind;
2085 if (UnInstClauses.size() > 0)
2087 auto *TileClauseItr =
2088 llvm::find_if(Clauses, llvm::IsaPred<OpenACCTileClause>);
2090 if (Clauses.end() == TileClauseItr)
2094 SemaRef.TileInfo.ActiveTile = TileClause;
2095 SemaRef.TileInfo.TileDepthSatisfied =
false;
2097 SemaRef.TileInfo.DirectiveKind = DirKind;
2108 SemaRef.ActiveComputeConstructInfo = OldActiveComputeConstructInfo;
2109 SemaRef.LoopGangClauseOnKernel = OldLoopGangClauseOnKernel;
2110 SemaRef.LoopWorkerClauseLoc = OldLoopWorkerClauseLoc;
2111 SemaRef.LoopVectorClauseLoc = OldLoopVectorClauseLoc;
2112 SemaRef.LoopWithoutSeqInfo = OldLoopWithoutSeqInfo;
2113 SemaRef.ActiveReductionClauses.swap(ActiveReductionClauses);
2135 if (
const auto *DevTypeClause =
2136 llvm::find_if(ExistingClauses,
2138 return isa<OpenACCDeviceTypeClause>(
C);
2140 DevTypeClause != ExistingClauses.end()) {
2141 if (checkValidAfterDeviceType(
2142 *
this, *cast<OpenACCDeviceTypeClause>(*DevTypeClause), Clause))
2146 SemaOpenACCClauseVisitor Visitor{*
this, ExistingClauses};
2149 "Created wrong clause?");
2151 if (Visitor.diagNotImplemented())
2162bool areVarsEqual(
Expr *VarExpr1,
Expr *VarExpr2) {
2174 if (isa<ArraySectionExpr>(VarExpr1)) {
2175 auto *Expr2AS = dyn_cast<ArraySectionExpr>(VarExpr2);
2179 auto *Expr1AS = cast<ArraySectionExpr>(VarExpr1);
2181 if (!areVarsEqual(Expr1AS->getBase(), Expr2AS->getBase()))
2189 if (isa<ArraySubscriptExpr>(VarExpr1)) {
2190 auto *Expr2AS = dyn_cast<ArraySubscriptExpr>(VarExpr2);
2194 auto *Expr1AS = cast<ArraySubscriptExpr>(VarExpr1);
2196 if (!areVarsEqual(Expr1AS->getBase(), Expr2AS->getBase()))
2206 if (isa<DeclRefExpr>(VarExpr1)) {
2207 auto *Expr2DRE = dyn_cast<DeclRefExpr>(VarExpr2);
2211 auto *Expr1DRE = cast<DeclRefExpr>(VarExpr1);
2213 return Expr1DRE->getDecl()->getMostRecentDecl() ==
2214 Expr2DRE->getDecl()->getMostRecentDecl();
2217 llvm_unreachable(
"Unknown variable type encountered");
2233 auto TypeIsValid = [](
QualType Ty) {
2234 return Ty->isDependentType() || Ty->isScalarType();
2237 if (isa<ArraySectionExpr>(VarExpr)) {
2238 Expr *ASExpr = VarExpr;
2242 if (!TypeIsValid(EltTy)) {
2248 if (!RD->isStruct() && !RD->isClass()) {
2249 Diag(VarExpr->
getExprLoc(), diag::err_acc_reduction_composite_type)
2254 if (!RD->isCompleteDefinition()) {
2255 Diag(VarExpr->
getExprLoc(), diag::err_acc_reduction_composite_type)
2259 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
2260 CXXRD && !CXXRD->isAggregate()) {
2261 Diag(VarExpr->
getExprLoc(), diag::err_acc_reduction_composite_type)
2267 if (!TypeIsValid(FD->getType())) {
2269 diag::err_acc_reduction_composite_member_type);
2270 Diag(FD->getLocation(), diag::note_acc_reduction_composite_member_loc);
2274 }
else if (!TypeIsValid(VarExpr->
getType())) {
2285 if (RClause->getReductionOp() == ReductionOp)
2288 for (
Expr *OldVarExpr : RClause->getVarList()) {
2289 if (OldVarExpr->isInstantiationDependent())
2292 if (areVarsEqual(VarExpr, OldVarExpr)) {
2294 << ReductionOp << RClause->getReductionOp();
2295 Diag(OldVarExpr->getExprLoc(), diag::note_acc_previous_clause_here);
2339 Diag(DirLoc, diag::warn_acc_construct_unimplemented) << K;
2354 "Only one of directive or clause kind should be provided");
2363 unsigned getDiagKind()
const {
2364 if (ClauseKind != OpenACCClauseKind::Invalid)
2366 if (DirectiveKind != OpenACCDirectiveKind::Invalid)
2374 : ICEConvertDiagnoser(
false,
2377 DirectiveKind(DK), ClauseKind(CK), IntExpr(IntExpr) {}
2386 return S.
Diag(
Loc, diag::err_acc_int_expr_requires_integer)
2387 << getDiagKind() << ClauseKind << DirectiveKind <<
T;
2392 return S.
Diag(
Loc, diag::err_acc_int_expr_incomplete_class_type)
2399 return S.
Diag(
Loc, diag::err_acc_int_expr_explicit_conversion)
2406 return S.
Diag(Conv->
getLocation(), diag::note_acc_int_expr_conversion)
2412 return S.
Diag(
Loc, diag::err_acc_int_expr_multiple_conversions) <<
T;
2417 return S.
Diag(Conv->
getLocation(), diag::note_acc_int_expr_conversion)
2424 llvm_unreachable(
"conversion functions are permitted");
2426 } IntExprDiagnoser(DK, CK, IntExpr);
2432 Loc, IntExpr, IntExprDiagnoser);
2436 IntExpr = IntExprResult.
get();
2458 Diag(VarExpr->
getExprLoc(), diag::note_acc_expected_pointer_var);
2470 return Diag(VarExpr->
getExprLoc(), diag::err_acc_var_not_pointer_type)
2471 << ClauseKind << Ty;
2482 isa<ArraySectionExpr, ArraySubscriptExpr>(CurVarExpr)) {
2483 Diag(VarExpr->
getExprLoc(), diag::err_acc_not_a_var_ref_use_device);
2489 while (isa<ArraySectionExpr, ArraySubscriptExpr>(CurVarExpr)) {
2490 if (
auto *SubScrpt = dyn_cast<ArraySubscriptExpr>(CurVarExpr))
2498 if (
const auto *DRE = dyn_cast<DeclRefExpr>(CurVarExpr)) {
2499 if (isa<VarDecl, NonTypeTemplateParmDecl>(
2500 DRE->getFoundDecl()->getCanonicalDecl()))
2512 if (
const auto *ME = dyn_cast<MemberExpr>(CurVarExpr)) {
2513 if (isa<FieldDecl>(ME->getMemberDecl()->getCanonicalDecl()))
2525 if (isa<DependentScopeDeclRefExpr>(CurVarExpr) ||
2527 isa<CXXDependentScopeMemberExpr>(CurVarExpr)))
2532 if (isa<RecoveryExpr>(CurVarExpr))
2536 Diag(VarExpr->
getExprLoc(), diag::err_acc_not_a_var_ref_use_device);
2551 if (
Base->hasPlaceholderType() &&
2552 !
Base->hasPlaceholderType(BuiltinType::ArraySection)) {
2565 LowerBound =
Result.get();
2567 if (Length && Length->getType()->isNonOverloadPlaceholderType()) {
2581 if (!
Base->isTypeDependent()) {
2588 Diag(
Base->getExprLoc(), diag::err_acc_typecheck_subarray_value)
2589 <<
Base->getSourceRange());
2593 Diag(
Base->getExprLoc(), diag::err_acc_subarray_function_type)
2594 << ResultTy <<
Base->getSourceRange();
2599 diag::err_acc_subarray_incomplete_type,
2603 if (!
Base->hasPlaceholderType(BuiltinType::ArraySection)) {
2614 return Recovery.
isUsable() ? Recovery.
get() :
nullptr;
2629 if (Length && !Length->isTypeDependent()) {
2632 Length->getExprLoc(), Length);
2641 if (!Length && (OriginalBaseTy.
isNull() ||
2646 Diag(ColonLoc, diag::err_acc_subarray_no_length) << IsArray;
2651 Length = Recovery.
isUsable() ? Recovery.
get() :
nullptr;
2662 std::optional<llvm::APSInt> BaseSize;
2665 BaseSize = ArrayTy->
getSize();
2668 auto GetBoundValue = [&](
Expr *
E) -> std::optional<llvm::APSInt> {
2670 return std::nullopt;
2674 return std::nullopt;
2678 std::optional<llvm::APSInt> LowerBoundValue = GetBoundValue(LowerBound);
2679 std::optional<llvm::APSInt> LengthValue = GetBoundValue(Length);
2682 if (LowerBoundValue.has_value()) {
2683 if (LowerBoundValue->isNegative()) {
2685 << 0 <<
toString(*LowerBoundValue, 10);
2686 LowerBoundValue.reset();
2687 LowerBound = GetRecovery(LowerBound, LowerBound->
getType());
2688 }
else if (BaseSize.has_value() &&
2689 llvm::APSInt::compareValues(*LowerBoundValue, *BaseSize) >= 0) {
2691 Diag(LowerBound->
getExprLoc(), diag::err_acc_subarray_out_of_range)
2692 << 0 <<
toString(*LowerBoundValue, 10)
2694 LowerBoundValue.reset();
2695 LowerBound = GetRecovery(LowerBound, LowerBound->
getType());
2700 if (LengthValue.has_value()) {
2701 if (LengthValue->isNegative()) {
2702 Diag(Length->getExprLoc(), diag::err_acc_subarray_negative)
2703 << 1 <<
toString(*LengthValue, 10);
2704 LengthValue.reset();
2705 Length = GetRecovery(Length, Length->getType());
2706 }
else if (BaseSize.has_value() &&
2707 llvm::APSInt::compareValues(*LengthValue, *BaseSize) > 0) {
2709 Diag(Length->getExprLoc(), diag::err_acc_subarray_out_of_range)
2712 LengthValue.reset();
2713 Length = GetRecovery(Length, Length->getType());
2718 auto AddAPSInt = [](llvm::APSInt LHS, llvm::APSInt RHS) -> llvm::APSInt {
2719 if (LHS.isSigned() == RHS.isSigned())
2722 unsigned Width = std::max(LHS.getBitWidth(), RHS.getBitWidth()) + 1;
2723 return llvm::APSInt(LHS.sext(Width) + RHS.sext(Width),
true);
2728 if (BaseSize.has_value() && LowerBoundValue.has_value() &&
2729 LengthValue.has_value() &&
2730 llvm::APSInt::compareValues(AddAPSInt(*LowerBoundValue, *LengthValue),
2733 diag::err_acc_subarray_base_plus_length_out_of_range)
2738 LowerBoundValue.reset();
2739 LowerBound = GetRecovery(LowerBound, LowerBound->
getType());
2740 LengthValue.reset();
2741 Length = GetRecovery(Length, Length->getType());
2746 if (
Base->isTypeDependent() ||
2748 (Length && Length->isInstantiationDependent()))
2751 return new (Context)
2762 "Loop argument non integer?");
2768 std::optional<llvm::APSInt> ICE =
2774 if (!ICE || *ICE <= 0) {
2776 << ICE.has_value() << ICE.value_or(llvm::APSInt{}).getExtValue();
2794 return CheckGangParallelExpr(*
this, DK, ActiveComputeConstructInfo.Kind, GK,
2797 return CheckGangSerialExpr(*
this, DK, ActiveComputeConstructInfo.Kind, GK,
2800 return CheckGangKernelsExpr(*
this, ExistingClauses, DK,
2801 ActiveComputeConstructInfo.Kind, GK,
E);
2803 switch (ActiveComputeConstructInfo.Kind) {
2807 return CheckGangParallelExpr(*
this, DK, ActiveComputeConstructInfo.Kind,
2811 return CheckGangSerialExpr(*
this, DK, ActiveComputeConstructInfo.Kind, GK,
2815 return CheckGangKernelsExpr(*
this, ExistingClauses, DK,
2816 ActiveComputeConstructInfo.Kind, GK,
E);
2818 llvm_unreachable(
"Non compute construct in active compute construct?");
2823 llvm_unreachable(
"Invalid directive kind for a Gang clause");
2825 llvm_unreachable(
"Compute construct directive not handled?");
2837 const auto *ReductionItr =
2838 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
2840 if (ReductionItr != ExistingClauses.end()) {
2841 const auto GangZip = llvm::zip_equal(GangKinds, IntExprs);
2842 const auto GangItr = llvm::find_if(GangZip, [](
const auto &Tuple) {
2846 if (GangItr != GangZip.end()) {
2847 const Expr *DimExpr = std::get<1>(*GangItr);
2851 "Improperly formed gang argument");
2852 if (
const auto *DimVal = dyn_cast<ConstantExpr>(DimExpr);
2853 DimVal && DimVal->getResultAsAPSInt() > 1) {
2854 Diag(DimVal->getBeginLoc(), diag::err_acc_gang_reduction_conflict)
2856 Diag((*ReductionItr)->getBeginLoc(),
2857 diag::note_acc_previous_clause_here);
2864 GangKinds, IntExprs, EndLoc);
2877 const auto GangClauses = llvm::make_filter_range(
2878 ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
2880 for (
auto *GC : GangClauses) {
2881 const auto *GangClause = cast<OpenACCGangClause>(GC);
2882 for (
unsigned I = 0; I < GangClause->getNumExprs(); ++I) {
2883 std::pair<OpenACCGangKind, const Expr *> EPair = GangClause->getExpr(I);
2887 if (
const auto *DimVal = dyn_cast<ConstantExpr>(EPair.second);
2888 DimVal && DimVal->getResultAsAPSInt() > 1) {
2889 Diag(BeginLoc, diag::err_acc_gang_reduction_conflict)
2890 << 1 << DirectiveKind;
2891 Diag(GangClause->getBeginLoc(), diag::note_acc_previous_clause_here);
2899 getASTContext(), BeginLoc, LParenLoc, ReductionOp, Vars, EndLoc);
2909 "size argument non integer?");
2913 isa<OpenACCAsteriskSizeExpr>(SizeExpr))
2916 std::optional<llvm::APSInt> ICE =
2921 if (!ICE || *ICE <= 0) {
2923 << ICE.has_value() << ICE.value_or(llvm::APSInt{}).getExtValue();
2935 if (!LoopInfo.TopLevelLoopSeen)
2938 if (CollapseInfo.CurCollapseCount && *CollapseInfo.CurCollapseCount > 0) {
2939 Diag(WhileLoc, diag::err_acc_invalid_in_loop)
2940 << 1 << CollapseInfo.DirectiveKind
2942 assert(CollapseInfo.ActiveCollapse &&
"Collapse count without object?");
2943 Diag(CollapseInfo.ActiveCollapse->getBeginLoc(),
2944 diag::note_acc_active_clause_here)
2949 CollapseInfo.CurCollapseCount = std::nullopt;
2952 if (TileInfo.CurTileCount && *TileInfo.CurTileCount > 0) {
2953 Diag(WhileLoc, diag::err_acc_invalid_in_loop)
2954 << 1 << TileInfo.DirectiveKind
2956 assert(TileInfo.ActiveTile &&
"tile count without object?");
2957 Diag(TileInfo.ActiveTile->getBeginLoc(), diag::note_acc_active_clause_here)
2962 TileInfo.CurTileCount = std::nullopt;
2970 if (!LoopInfo.TopLevelLoopSeen)
2973 if (CollapseInfo.CurCollapseCount && *CollapseInfo.CurCollapseCount > 0) {
2974 Diag(DoLoc, diag::err_acc_invalid_in_loop)
2975 << 2 << CollapseInfo.DirectiveKind
2977 assert(CollapseInfo.ActiveCollapse &&
"Collapse count without object?");
2978 Diag(CollapseInfo.ActiveCollapse->getBeginLoc(),
2979 diag::note_acc_active_clause_here)
2984 CollapseInfo.CurCollapseCount = std::nullopt;
2987 if (TileInfo.CurTileCount && *TileInfo.CurTileCount > 0) {
2988 Diag(DoLoc, diag::err_acc_invalid_in_loop)
2990 assert(TileInfo.ActiveTile &&
"tile count without object?");
2991 Diag(TileInfo.ActiveTile->getBeginLoc(), diag::note_acc_active_clause_here)
2996 TileInfo.CurTileCount = std::nullopt;
3001 ForStmtBeginChecker &
C) {
3002 assert(
getLangOpts().OpenACC &&
"Check enabled when not OpenACC?");
3005 LoopInfo.TopLevelLoopSeen =
true;
3007 if (CollapseInfo.CurCollapseCount && *CollapseInfo.CurCollapseCount > 0) {
3015 if (LoopInfo.CurLevelHasLoopAlready) {
3016 Diag(ForLoc, diag::err_acc_clause_multiple_loops)
3018 assert(CollapseInfo.ActiveCollapse &&
"No collapse object?");
3019 Diag(CollapseInfo.ActiveCollapse->getBeginLoc(),
3020 diag::note_acc_active_clause_here)
3023 --(*CollapseInfo.CurCollapseCount);
3027 if (*CollapseInfo.CurCollapseCount == 0)
3028 CollapseInfo.CollapseDepthSatisfied =
true;
3032 if (TileInfo.CurTileCount && *TileInfo.CurTileCount > 0) {
3035 if (LoopInfo.CurLevelHasLoopAlready) {
3036 Diag(ForLoc, diag::err_acc_clause_multiple_loops)
3038 assert(TileInfo.ActiveTile &&
"No tile object?");
3039 Diag(TileInfo.ActiveTile->getBeginLoc(),
3040 diag::note_acc_active_clause_here)
3043 --(*TileInfo.CurTileCount);
3046 if (*TileInfo.CurTileCount == 0)
3047 TileInfo.TileDepthSatisfied =
true;
3053 LoopInfo.CurLevelHasLoopAlready =
false;
3057bool isValidLoopVariableType(
QualType LoopVarTy) {
3080 for (
const auto *TD :
3081 llvm::make_filter_range(RD->decls(), llvm::IsaPred<TypedefNameDecl>)) {
3082 const auto *TDND = cast<TypedefNameDecl>(TD)->getCanonicalDecl();
3084 if (TDND->getName() !=
"iterator_category")
3088 if (TDND->getUnderlyingType().isNull())
3092 TDND->getUnderlyingType()->getAsCXXRecordDecl();
3095 if (!ItrCategoryDecl)
3098 auto IsRandomAccessIteratorTag = [](
const CXXRecordDecl *RD) {
3099 if (RD->getName() !=
"random_access_iterator_tag")
3105 if (IsRandomAccessIteratorTag(ItrCategoryDecl))
3112 if (IsRandomAccessIteratorTag(BS.getType()->getAsCXXRecordDecl()))
3125void SemaOpenACC::ForStmtBeginChecker::check() {
3131 AlreadyChecked =
true;
3151 if (!RangeFor.has_value())
3155 const DeclStmt *RangeStmt = (*RangeFor)->getBeginStmt();
3164 if (!isValidLoopVariableType(VarType)) {
3166 <<
SemaRef.LoopWithoutSeqInfo.Kind << VarType;
3168 diag::note_acc_construct_here)
3169 <<
SemaRef.LoopWithoutSeqInfo.Kind;
3178 if (Cond.has_value())
3180 if (
Inc.has_value())
3183const ValueDecl *SemaOpenACC::ForStmtBeginChecker::checkInit() {
3187 <<
SemaRef.LoopWithoutSeqInfo.Kind;
3189 diag::note_acc_construct_here)
3190 <<
SemaRef.LoopWithoutSeqInfo.Kind;
3195 auto DiagLoopVar = [&]() {
3198 <<
SemaRef.LoopWithoutSeqInfo.Kind;
3200 diag::note_acc_construct_here)
3201 <<
SemaRef.LoopWithoutSeqInfo.Kind;
3206 if (
const auto *ExprTemp = dyn_cast<ExprWithCleanups>(
Init))
3207 Init = ExprTemp->getSubExpr();
3208 if (
const auto *
E = dyn_cast<Expr>(
Init))
3213 if (
const auto *BO = dyn_cast<BinaryOperator>(
Init)) {
3216 if (!BO->isAssignmentOp())
3217 return DiagLoopVar();
3221 if (
const auto *DRE = dyn_cast<DeclRefExpr>(LHS))
3222 InitVar = DRE->getDecl();
3223 }
else if (
const auto *DS = dyn_cast<DeclStmt>(
Init)) {
3225 if (!DS->isSingleDecl())
3226 return DiagLoopVar();
3228 InitVar = dyn_cast<ValueDecl>(DS->getSingleDecl());
3233 if (!isa<VarDecl>(InitVar))
3234 return DiagLoopVar();
3238 !cast<VarDecl>(InitVar)->hasInit())
3239 return DiagLoopVar();
3241 }
else if (
auto *CE = dyn_cast<CXXOperatorCallExpr>(
Init)) {
3243 if (CE->getOperator() != OO_Equal)
3244 return DiagLoopVar();
3248 if (
auto *DRE = dyn_cast<DeclRefExpr>(LHS)) {
3249 InitVar = DRE->getDecl();
3250 }
else if (
auto *ME = dyn_cast<MemberExpr>(LHS)) {
3251 if (isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()))
3252 InitVar = ME->getMemberDecl();
3257 return DiagLoopVar();
3263 if (!isValidLoopVariableType(VarType)) {
3266 <<
SemaRef.LoopWithoutSeqInfo.Kind << VarType;
3268 diag::note_acc_construct_here)
3269 <<
SemaRef.LoopWithoutSeqInfo.Kind;
3276void SemaOpenACC::ForStmtBeginChecker::checkCond() {
3278 SemaRef.
Diag(ForLoc, diag::err_acc_loop_terminating_condition)
3279 <<
SemaRef.LoopWithoutSeqInfo.Kind;
3281 <<
SemaRef.LoopWithoutSeqInfo.Kind;
3290void SemaOpenACC::ForStmtBeginChecker::checkInc(
const ValueDecl *
Init) {
3293 SemaRef.
Diag(ForLoc, diag::err_acc_loop_not_monotonic)
3294 <<
SemaRef.LoopWithoutSeqInfo.Kind;
3296 <<
SemaRef.LoopWithoutSeqInfo.Kind;
3299 auto DiagIncVar = [
this] {
3300 SemaRef.
Diag((*Inc)->getBeginLoc(), diag::err_acc_loop_not_monotonic)
3301 <<
SemaRef.LoopWithoutSeqInfo.Kind;
3303 <<
SemaRef.LoopWithoutSeqInfo.Kind;
3307 if (
const auto *ExprTemp = dyn_cast<ExprWithCleanups>(*Inc))
3308 Inc = ExprTemp->getSubExpr();
3309 if (
const auto *
E = dyn_cast<Expr>(*Inc))
3314 if (
const auto *FE = dyn_cast<FullExpr>(
E))
3315 E = FE->getSubExpr();
3321 if (
const auto *DRE = dyn_cast<DeclRefExpr>(
E))
3322 return dyn_cast<ValueDecl>(DRE->getDecl());
3324 if (
const auto *ME = dyn_cast<MemberExpr>(
E))
3325 if (isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()))
3326 return ME->getMemberDecl();
3334 if (
const auto *UO = dyn_cast<UnaryOperator>(*Inc)) {
3336 if (!UO->isIncrementDecrementOp())
3337 return DiagIncVar();
3339 }
else if (
const auto *BO = dyn_cast<BinaryOperator>(*Inc)) {
3340 switch (BO->getOpcode()) {
3342 return DiagIncVar();
3356 }
else if (
const auto *CE = dyn_cast<CXXOperatorCallExpr>(*Inc)) {
3357 switch (CE->getOperator()) {
3359 return DiagIncVar();
3377 }
else if (
const auto *ME = dyn_cast<CXXMemberCallExpr>(*Inc)) {
3384 return DiagIncVar();
3390 return DiagIncVar();
3397 const Stmt *Second,
const Stmt *OldThird,
3398 const Stmt *Third) {
3402 std::optional<const Stmt *> S;
3403 if (OldSecond == Second)
3407 std::optional<const Stmt *>
T;
3408 if (OldThird == Third)
3413 bool InitChanged =
false;
3414 if (OldFirst !=
First) {
3422 if (
const auto *DS = dyn_cast<DeclStmt>(OldFirst))
3423 if (
const VarDecl *VD = dyn_cast_if_present<VarDecl>(
3424 DS->isSingleDecl() ? DS->getSingleDecl() :
nullptr))
3425 OldVDTy = VD->getType();
3426 if (
const auto *DS = dyn_cast<DeclStmt>(
First))
3427 if (
const VarDecl *VD = dyn_cast_if_present<VarDecl>(
3428 DS->isSingleDecl() ? DS->getSingleDecl() :
nullptr))
3429 NewVDTy = VD->getType();
3436 ForStmtBeginChecker FSBC{*
this, ForLoc,
First, InitChanged, S,
T};
3437 if (!LoopInfo.TopLevelLoopSeen) {
3441 ForStmtBeginHelper(ForLoc, FSBC);
3445 const Stmt *Second,
const Stmt *Third) {
3449 ForStmtBeginChecker FSBC{*
this, ForLoc,
First,
true,
3451 if (!LoopInfo.TopLevelLoopSeen) {
3455 ForStmtBeginHelper(ForLoc, FSBC);
3459 const Stmt *OldRangeFor,
3460 const Stmt *RangeFor) {
3464 std::optional<const CXXForRangeStmt *> RF;
3466 if (OldRangeFor == RangeFor)
3469 RF = cast<CXXForRangeStmt>(RangeFor);
3471 ForStmtBeginChecker FSBC{*
this, ForLoc, RF};
3472 if (!LoopInfo.TopLevelLoopSeen) {
3475 ForStmtBeginHelper(ForLoc, FSBC);
3479 const Stmt *RangeFor) {
3483 ForStmtBeginChecker FSBC{*
this, ForLoc, cast<CXXForRangeStmt>(RangeFor)};
3484 if (!LoopInfo.TopLevelLoopSeen) {
3487 ForStmtBeginHelper(ForLoc, FSBC);
3497 isa<ForStmt, NullStmt, ForStmt, CXXForRangeStmt, WhileStmt, DoStmt>(
3502 if (isa<OpenACCConstructStmt>(CurStmt))
3507 if (
const auto *CS = dyn_cast<CompoundStmt>(CurStmt)) {
3508 for (
const auto *ChildStmt : CS->children()) {
3509 SourceLocation ChildStmtLoc = FindInterveningCodeInLoop(ChildStmt);
3511 return ChildStmtLoc;
3525 LoopInfo.CurLevelHasLoopAlready =
true;
3530 bool IsActiveCollapse = CollapseInfo.CurCollapseCount &&
3531 *CollapseInfo.CurCollapseCount > 0 &&
3532 !CollapseInfo.ActiveCollapse->hasForce();
3533 bool IsActiveTile = TileInfo.CurTileCount && *TileInfo.CurTileCount > 0;
3535 if (IsActiveCollapse || IsActiveTile) {
3538 if (OtherStmtLoc.
isValid() && IsActiveCollapse) {
3539 Diag(OtherStmtLoc, diag::err_acc_intervening_code)
3541 Diag(CollapseInfo.ActiveCollapse->getBeginLoc(),
3542 diag::note_acc_active_clause_here)
3546 if (OtherStmtLoc.
isValid() && IsActiveTile) {
3547 Diag(OtherStmtLoc, diag::err_acc_intervening_code)
3549 Diag(TileInfo.ActiveTile->getBeginLoc(),
3550 diag::note_acc_active_clause_here)
3560 assert(!Clauses.empty() &&
"empty clause list not supported");
3563 llvm::raw_string_ostream OS{Output};
3565 if (Clauses.size() == 1) {
3566 OS <<
'\'' << Clauses[0] <<
'\'';
3575 [&] { OS <<
", "; });
3577 OS <<
" or \'" << Clauses.back() <<
'\'';
3593 if (CollapseInfo.CurCollapseCount && *CollapseInfo.CurCollapseCount > 0) {
3594 Diag(StartLoc, diag::err_acc_invalid_in_loop)
3595 << 0 << CollapseInfo.DirectiveKind
3597 assert(CollapseInfo.ActiveCollapse &&
"Collapse count without object?");
3598 Diag(CollapseInfo.ActiveCollapse->getBeginLoc(),
3599 diag::note_acc_active_clause_here)
3602 if (TileInfo.CurTileCount && *TileInfo.CurTileCount > 0) {
3603 Diag(StartLoc, diag::err_acc_invalid_in_loop)
3604 << 0 << TileInfo.DirectiveKind
3606 assert(TileInfo.ActiveTile &&
"Tile count without object?");
3607 Diag(TileInfo.ActiveTile->getBeginLoc(), diag::note_acc_active_clause_here)
3615 llvm::find_if(Clauses,
3621 return Diag(StartLoc, diag::err_acc_construct_one_clause_of)
3623 << GetListOfClauses(
3633 llvm::find_if(Clauses,
3636 return Diag(StartLoc, diag::err_acc_construct_one_clause_of)
3638 << GetListOfClauses({
3646 llvm::find_if(Clauses,
3649 return Diag(StartLoc, diag::err_acc_construct_one_clause_of)
3651 << GetListOfClauses({
3659 llvm::find_if(Clauses, llvm::IsaPred<OpenACCUseDeviceClause>) ==
3661 return Diag(StartLoc, diag::err_acc_construct_one_clause_of)
3664 return diagnoseConstructAppertainment(*
this, K, StartLoc,
true);
3682 AssocStmt.
isUsable() ? AssocStmt.
get() :
nullptr);
3689 AssocStmt.
isUsable() ? AssocStmt.
get() :
nullptr);
3693 getASTContext(), ActiveComputeConstructInfo.Kind, StartLoc, DirLoc,
3694 EndLoc, Clauses, AssocStmt.
isUsable() ? AssocStmt.
get() :
nullptr);
3699 AssocStmt.
isUsable() ? AssocStmt.
get() :
nullptr);
3712 AssocStmt.
isUsable() ? AssocStmt.
get() :
nullptr);
3716 getASTContext(), StartLoc, DirLoc, LParenLoc, Exprs.front(), MiscLoc,
3717 Exprs.drop_front(), RParenLoc, EndLoc, Clauses);
3728 llvm_unreachable(
"Unhandled case in directive handling?");
3736 llvm_unreachable(
"Unimplemented associated statement application");
3743 "these don't have associated statements, so shouldn't get here");
3766 if (!isa<CXXForRangeStmt, ForStmt>(AssocStmt.
get())) {
3769 Diag(DirectiveLoc, diag::note_acc_construct_here) << K;
3773 if (!CollapseInfo.CollapseDepthSatisfied || !TileInfo.TileDepthSatisfied) {
3774 if (!CollapseInfo.CollapseDepthSatisfied) {
3775 Diag(DirectiveLoc, diag::err_acc_insufficient_loops)
3777 assert(CollapseInfo.ActiveCollapse &&
"Collapse count without object?");
3778 Diag(CollapseInfo.ActiveCollapse->getBeginLoc(),
3779 diag::note_acc_active_clause_here)
3783 if (!TileInfo.TileDepthSatisfied) {
3784 Diag(DirectiveLoc, diag::err_acc_insufficient_loops)
3786 assert(TileInfo.ActiveTile &&
"Collapse count without object?");
3787 Diag(TileInfo.ActiveTile->getBeginLoc(),
3788 diag::note_acc_active_clause_here)
3794 return AssocStmt.
get();
3796 llvm_unreachable(
"Invalid associated statement application");
3806 return diagnoseConstructAppertainment(*
this, K, StartLoc,
false);
Defines some OpenACC-specific enums and functions.
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
static NamedDecl * getDeclFromExpr(Expr *E)
This file declares semantic analysis for OpenACC constructs and clauses.
This file defines OpenACC AST classes for statement-level contructs.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const ConstantArrayType * getAsConstantArrayType(QualType T) const
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
CanQualType ArraySectionTy
This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...
static QualType getBaseOriginalType(const Expr *Base)
Return original type of the base expression for array section.
QualType getElementType() const
Represents a base class of a C++ class.
Represents a C++ conversion function within a class.
Represents a C++ struct/union/class.
llvm::APInt getSize() const
Return the constant array size as an APInt.
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
bool isStdNamespace() const
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
const Decl * getSingleDecl() const
SourceLocation getLocation() const
SourceLocation getBeginLoc() const LLVM_READONLY
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
This represents one expression.
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer,...
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
bool containsErrors() const
Whether this expression contains subexpressions which had errors, e.g.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Represents a member of a struct/union/class.
static OpenACCAsteriskSizeExpr * Create(const ASTContext &C, SourceLocation Loc)
static OpenACCAsyncClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCAttachClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCAutoClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
This is the base type for all OpenACC Clauses.
OpenACCClauseKind getClauseKind() const
SourceLocation getBeginLoc() const
Represents a 'collapse' clause on a 'loop' construct.
static OpenACCCollapseClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, bool HasForce, Expr *LoopCount, SourceLocation EndLoc)
const Expr * getLoopCount() const
static OpenACCCombinedConstruct * Create(const ASTContext &C, OpenACCDirectiveKind K, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
static OpenACCComputeConstruct * Create(const ASTContext &C, OpenACCDirectiveKind K, SourceLocation BeginLoc, SourceLocation DirectiveLoc, SourceLocation EndLoc, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
static OpenACCCopyClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyInClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsReadOnly, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyOutClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCreateClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDataConstruct * Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
A 'default' clause, has the optional 'none' or 'present' argument.
static OpenACCDefaultClause * Create(const ASTContext &C, OpenACCDefaultClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
static OpenACCDeleteClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDetachClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDeviceNumClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCDevicePtrClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
A 'device_type' or 'dtype' clause, takes a list of either an 'asterisk' or an identifier.
static OpenACCDeviceTypeClause * Create(const ASTContext &C, OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< DeviceTypeArgument > Archs, SourceLocation EndLoc)
static OpenACCEnterDataConstruct * Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses)
static OpenACCExitDataConstruct * Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses)
static OpenACCFinalizeClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCFirstPrivateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCGangClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< OpenACCGangKind > GangKinds, ArrayRef< Expr * > IntExprs, SourceLocation EndLoc)
static OpenACCHostDataConstruct * Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
static OpenACCIfClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static OpenACCIfPresentClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCIndependentClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCInitConstruct * Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses)
static OpenACCLoopConstruct * Create(const ASTContext &C, OpenACCDirectiveKind ParentKind, SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< const OpenACCClause * > Clauses, Stmt *Loop)
static OpenACCNoCreateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCNumGangsClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > IntExprs, SourceLocation EndLoc)
static OpenACCNumWorkersClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCPresentClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCPrivateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCReductionClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCReductionOperator Operator, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCSelfClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static OpenACCSeqClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCShutdownConstruct * Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses)
static OpenACCTileClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > SizeExprs, SourceLocation EndLoc)
llvm::ArrayRef< Expr * > getSizeExprs()
static OpenACCUseDeviceClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCVectorClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCVectorLengthClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCWaitClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef< Expr * > QueueIdExprs, SourceLocation EndLoc)
static OpenACCWaitConstruct * Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation LParenLoc, Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef< Expr * > QueueIdExprs, SourceLocation RParenLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses)
static OpenACCWorkerClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
A generic diagnostic builder for errors which may or may not be deferred.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
ASTContext & getASTContext() const
const LangOptions & getLangOpts() const
AssociatedStmtRAII(SemaOpenACC &, OpenACCDirectiveKind, SourceLocation, ArrayRef< const OpenACCClause * >, ArrayRef< OpenACCClause * >)
void SetTileInfoBeforeAssociatedStmt(ArrayRef< const OpenACCClause * > UnInstClauses, ArrayRef< OpenACCClause * > Clauses)
void SetCollapseInfoBeforeAssociatedStmt(ArrayRef< const OpenACCClause * > UnInstClauses, ArrayRef< OpenACCClause * > Clauses)
A type to represent all the data for an OpenACC Clause that has been parsed, but not yet created/sema...
ArrayRef< Expr * > getIntExprs()
ArrayRef< Expr * > getQueueIdExprs() const
OpenACCDirectiveKind getDirectiveKind() const
ArrayRef< OpenACCGangKind > getGangKinds() const
OpenACCReductionOperator getReductionOp() const
SourceLocation getEndLoc() const
OpenACCClauseKind getClauseKind() const
const Expr * getConditionExpr() const
SourceLocation getLParenLoc() const
ArrayRef< DeviceTypeArgument > getDeviceTypeArchitectures() const
SourceLocation getBeginLoc() const
SourceLocation getQueuesLoc() const
void setVarListDetails(ArrayRef< Expr * > VarList, bool IsReadOnly, bool IsZero)
Expr * getDevNumExpr() const
ArrayRef< Expr * > getVarList()
unsigned getNumIntExprs() const
Expr * getLoopCount() const
OpenACCDefaultClauseKind getDefaultClauseKind() const
ExprResult ActOnVar(OpenACCClauseKind CK, Expr *VarExpr)
Called when encountering a 'var' for OpenACC, ensures it is actually a declaration reference to a var...
ComputeConstructInfo & getActiveComputeConstructInfo()
bool ActOnStartStmtDirective(OpenACCDirectiveKind K, SourceLocation StartLoc, ArrayRef< const OpenACCClause * > Clauses)
Called after the directive, including its clauses, have been parsed and parsing has consumed the 'ann...
ExprResult BuildOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc)
ExprResult ActOnIntExpr(OpenACCDirectiveKind DK, OpenACCClauseKind CK, SourceLocation Loc, Expr *IntExpr)
Called when encountering an 'int-expr' for OpenACC, and manages conversions and diagnostics to 'int'.
void ActOnWhileStmt(SourceLocation WhileLoc)
SourceLocation LoopWorkerClauseLoc
If there is a current 'active' loop construct with a 'worker' clause on it (on any sort of construct)...
OpenACCClause * ActOnClause(ArrayRef< const OpenACCClause * > ExistingClauses, OpenACCParsedClause &Clause)
Called after parsing an OpenACC Clause so that it can be checked.
bool ActOnStartDeclDirective(OpenACCDirectiveKind K, SourceLocation StartLoc)
Called after the directive, including its clauses, have been parsed and parsing has consumed the 'ann...
bool CheckVarIsPointerType(OpenACCClauseKind ClauseKind, Expr *VarExpr)
Called to check the 'var' type is a variable of pointer type, necessary for 'deviceptr' and 'attach' ...
struct clang::SemaOpenACC::LoopGangOnKernelTy LoopGangClauseOnKernel
ExprResult CheckReductionVar(OpenACCDirectiveKind DirectiveKind, OpenACCReductionOperator ReductionOp, Expr *VarExpr)
Called while semantically analyzing the reduction clause, ensuring the var is the correct kind of ref...
ExprResult CheckCollapseLoopCount(Expr *LoopCount)
Checks the loop depth value for a collapse clause.
struct clang::SemaOpenACC::LoopWithoutSeqCheckingInfo LoopWithoutSeqInfo
StmtResult ActOnEndStmtDirective(OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation DirLoc, SourceLocation LParenLoc, SourceLocation MiscLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult AssocStmt)
Called after the directive has been completely parsed, including the declaration group or associated ...
DeclGroupRef ActOnEndDeclDirective()
Called after the directive has been completely parsed, including the declaration group or associated ...
OpenACCClause * CheckReductionClause(ArrayRef< const OpenACCClause * > ExistingClauses, OpenACCDirectiveKind DirectiveKind, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCReductionOperator ReductionOp, ArrayRef< Expr * > Vars, SourceLocation EndLoc)
SourceLocation LoopVectorClauseLoc
If there is a current 'active' loop construct with a 'vector' clause on it (on any sort of construct)...
void ActOnConstruct(OpenACCDirectiveKind K, SourceLocation DirLoc)
Called after the construct has been parsed, but clauses haven't been parsed.
ExprResult ActOnOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc)
ExprResult CheckGangExpr(ArrayRef< const OpenACCClause * > ExistingClauses, OpenACCDirectiveKind DK, OpenACCGangKind GK, Expr *E)
void ActOnDoStmt(SourceLocation DoLoc)
void ActOnRangeForStmtBegin(SourceLocation ForLoc, const Stmt *OldRangeFor, const Stmt *RangeFor)
void ActOnForStmtEnd(SourceLocation ForLoc, StmtResult Body)
OpenACCClause * CheckGangClause(OpenACCDirectiveKind DirKind, ArrayRef< const OpenACCClause * > ExistingClauses, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< OpenACCGangKind > GangKinds, ArrayRef< Expr * > IntExprs, SourceLocation EndLoc)
StmtResult ActOnAssociatedStmt(SourceLocation DirectiveLoc, OpenACCDirectiveKind K, ArrayRef< const OpenACCClause * > Clauses, StmtResult AssocStmt)
Called when we encounter an associated statement for our construct, this should check legality of the...
void ActOnForStmtBegin(SourceLocation ForLoc, const Stmt *First, const Stmt *Second, const Stmt *Third)
ExprResult ActOnArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, Expr *Length, SourceLocation RBLoc)
Checks and creates an Array Section used in an OpenACC construct/clause.
ExprResult CheckTileSizeExpr(Expr *SizeExpr)
Checks a single size expr for a tile clause.
Sema - This implements semantic analysis and AST building for C.
void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl=nullptr, ExpressionEvaluationContextRecord::ExpressionKind Type=ExpressionEvaluationContextRecord::EK_Other)
ExprResult PerformContextualImplicitConversion(SourceLocation Loc, Expr *FromE, ContextualImplicitConverter &Converter)
Perform a contextual implicit conversion.
ExprResult DefaultFunctionArrayLvalueConversion(Expr *E, bool Diagnose=true)
ASTContext & getASTContext() const
void PopExpressionEvaluationContext()
ExprResult DefaultLvalueConversion(Expr *E)
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
void DiscardCleanupsInEvaluationContext()
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
Stmt - This represents one statement.
SourceLocation getEndLoc() const LLVM_READONLY
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isDependentSizedArrayType() const
bool isConstantArrayType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
bool isEnumeralType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isNonOverloadPlaceholderType() const
Test for a placeholder type other than Overload; see BuiltinType::isNonOverloadPlaceholderType.
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isFunctionType() const
bool isAnyPointerType() const
bool isRecordType() const
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
SmallVector< BoundNodes, 1 > match(MatcherT Matcher, const NodeT &Node, ASTContext &Context)
Returns the results of matching Matcher on Node.
bool Inc(InterpState &S, CodePtr OpPC)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
The JSON file list parser is used to communicate input to InstallAPI.
bool isOpenACCComputeDirectiveKind(OpenACCDirectiveKind K)
bool isOpenACCCombinedDirectiveKind(OpenACCDirectiveKind K)
bool isOpenACCDataDirectiveKind(OpenACCDirectiveKind K)
@ OK_Ordinary
An ordinary object is located at an address in memory.
OpenACCClauseKind
Represents the kind of an OpenACC clause.
@ DevicePtr
'deviceptr' clause, allowed on Compute and Combined Constructs, plus 'data' and 'declare'.
@ Collapse
'collapse' clause, allowed on 'loop' and Combined constructs.
@ Invalid
Represents an invalid clause, for the purposes of parsing.
@ Copy
'copy' clause, allowed on Compute and Combined Constructs, plus 'data' and 'declare'.
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
@ Attach
'attach' clause, allowed on Compute and Combined constructs, plus 'data' and 'enter data'.
@ Default
'default' clause, allowed on parallel, serial, kernel (and compound) constructs.
@ UseDevice
'use_device' clause, allowed on 'host_data' construct.
@ NoCreate
'no_create' clause, allowed on allowed on Compute and Combined constructs, plus 'data'.
@ Reduction
'reduction' clause, allowed on Parallel, Serial, Loop, and the combined constructs.
@ CopyOut
'copyout' clause, allowed on Compute and Combined constructs, plus 'data', 'exit data',...
@ Tile
'tile' clause, allowed on 'loop' and Combined constructs.
@ Present
'present' clause, allowed on Compute and Combined constructs, plus 'data' and 'declare'.
@ CopyIn
'copyin' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
@ Detach
'detach' clause, allowed on the 'exit data' construct.
@ Delete
'delete' clause, allowed on the 'exit data' construct.
@ Result
The result type of a method or function.
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
const FunctionProtoType * T
EvalResult is a struct with detailed info about an evaluated expression.
APValue Val
Val - This is the value the expression can be folded to.
OpenACCDirectiveKind DirKind