24#include "llvm/ADT/StringExtras.h"
25#include "llvm/Support/Casting.h"
56 return S.
Diag(StartLoc, diag::err_acc_construct_appertainment) << K;
62void CollectActiveReductionClauses(
65 for (
auto *CurClause : CurClauses) {
66 if (
auto *RedClause = dyn_cast<OpenACCReductionClause>(CurClause);
67 RedClause && !RedClause->getVarList().empty())
68 ActiveClauses.push_back(RedClause);
98 llvm_unreachable(
"Doesn't have an associated stmt");
100 llvm_unreachable(
"Unhandled directive kind?");
102 llvm_unreachable(
"Unhandled directive kind?");
113 : SemaRef(S), OldActiveComputeConstructInfo(S.ActiveComputeConstructInfo),
118 ActiveReductionClauses(S.ActiveReductionClauses),
119 LoopRAII(SemaRef, PreserveLoopRAIIDepthInAssociatedStmtRAII(DirKind)) {
125 CollectActiveReductionClauses(S.ActiveReductionClauses, Clauses);
126 SemaRef.ActiveComputeConstructInfo.Kind = DirKind;
127 SemaRef.ActiveComputeConstructInfo.Clauses = Clauses;
135 SemaRef.LoopGangClauseOnKernel = {};
136 SemaRef.LoopWorkerClauseLoc = {};
137 SemaRef.LoopVectorClauseLoc = {};
138 SemaRef.LoopWithoutSeqInfo = {};
142 SemaRef.ActiveComputeConstructInfo.Kind = DirKind;
143 SemaRef.ActiveComputeConstructInfo.Clauses = Clauses;
145 CollectActiveReductionClauses(S.ActiveReductionClauses, Clauses);
149 SemaRef.LoopGangClauseOnKernel = {};
150 SemaRef.LoopWorkerClauseLoc = {};
151 SemaRef.LoopVectorClauseLoc = {};
155 SemaRef.LoopWithoutSeqInfo = {};
157 llvm::find_if(Clauses, llvm::IsaPred<OpenACCSeqClause>))
158 SemaRef.LoopWithoutSeqInfo = {DirKind, DirLoc};
170 auto *Itr = llvm::find_if(Clauses, llvm::IsaPred<OpenACCGangClause>);
171 if (Itr != Clauses.end())
172 SemaRef.LoopGangClauseOnKernel = {(*Itr)->getBeginLoc(), DirKind};
175 if (UnInstClauses.empty()) {
176 auto *Itr = llvm::find_if(Clauses, llvm::IsaPred<OpenACCWorkerClause>);
177 if (Itr != Clauses.end())
178 SemaRef.LoopWorkerClauseLoc = (*Itr)->getBeginLoc();
180 auto *Itr2 = llvm::find_if(Clauses, llvm::IsaPred<OpenACCVectorClause>);
181 if (Itr2 != Clauses.end())
182 SemaRef.LoopVectorClauseLoc = (*Itr2)->getBeginLoc();
185 CollectActiveReductionClauses(S.ActiveReductionClauses, Clauses);
191 SemaRef.LoopWithoutSeqInfo = {};
193 llvm::find_if(Clauses, llvm::IsaPred<OpenACCSeqClause>))
194 SemaRef.LoopWithoutSeqInfo = {DirKind, DirLoc};
204 if (SemaRef.getActiveComputeConstructInfo().Kind ==
206 UnInstClauses.empty()) {
208 auto *Itr = llvm::find_if(Clauses, llvm::IsaPred<OpenACCGangClause>);
209 if (Itr != Clauses.end())
210 SemaRef.LoopGangClauseOnKernel = {(*Itr)->getBeginLoc(),
214 if (UnInstClauses.empty()) {
215 auto *Itr = llvm::find_if(Clauses, llvm::IsaPred<OpenACCWorkerClause>);
216 if (Itr != Clauses.end())
217 SemaRef.LoopWorkerClauseLoc = (*Itr)->getBeginLoc();
219 auto *Itr2 = llvm::find_if(Clauses, llvm::IsaPred<OpenACCVectorClause>);
220 if (Itr2 != Clauses.end())
221 SemaRef.LoopVectorClauseLoc = (*Itr2)->getBeginLoc();
236 if (!
New->getLoopCount())
240 if (!
New->getLoopCount())
244 if (
New->getLoopCount()->isInstantiationDependent())
273 SemaRef.LoopInfo.CurLevelHasLoopAlready =
false;
274 SemaRef.CollapseInfo.CollapseDepthSatisfied =
true;
275 SemaRef.CollapseInfo.CurCollapseCount = 0;
276 SemaRef.TileInfo.TileDepthSatisfied =
true;
287 auto *UnInstClauseItr =
288 llvm::find_if(UnInstClauses, llvm::IsaPred<OpenACCCollapseClause>);
290 llvm::find_if(Clauses, llvm::IsaPred<OpenACCCollapseClause>);
299 while (ClauseItr != Clauses.end()) {
303 UnInstClauseItr == UnInstClauses.end()
308 getBestCollapseCandidate(FoundClause, CurClause, UnInstCurClause);
311 UnInstClauseItr == UnInstClauses.end()
313 : std::find_if(std::next(UnInstClauseItr), UnInstClauses.end(),
314 llvm::IsaPred<OpenACCCollapseClause>);
315 ClauseItr = std::find_if(std::next(ClauseItr), Clauses.end(),
316 llvm::IsaPred<OpenACCCollapseClause>);
322 SemaRef.CollapseInfo.ActiveCollapse = FoundClause;
323 SemaRef.CollapseInfo.CollapseDepthSatisfied =
false;
324 SemaRef.CollapseInfo.CurCollapseCount =
326 SemaRef.CollapseInfo.DirectiveKind = DirKind;
335 if (UnInstClauses.size() > 0)
337 auto *TileClauseItr =
338 llvm::find_if(Clauses, llvm::IsaPred<OpenACCTileClause>);
340 if (Clauses.end() == TileClauseItr)
347 while (Clauses.end() !=
348 (TileClauseItr = std::find_if(std::next(TileClauseItr), Clauses.end(),
349 llvm::IsaPred<OpenACCTileClause>))) {
352 TileClause = NewClause;
355 SemaRef.TileInfo.ActiveTile = TileClause;
356 SemaRef.TileInfo.TileDepthSatisfied =
false;
357 SemaRef.TileInfo.CurTileCount =
358 static_cast<unsigned>(TileClause->
getSizeExprs().size());
359 SemaRef.TileInfo.DirectiveKind = DirKind;
370 SemaRef.ActiveComputeConstructInfo = OldActiveComputeConstructInfo;
371 SemaRef.LoopGangClauseOnKernel = OldLoopGangClauseOnKernel;
372 SemaRef.LoopWorkerClauseLoc = OldLoopWorkerClauseLoc;
373 SemaRef.LoopVectorClauseLoc = OldLoopVectorClauseLoc;
374 SemaRef.LoopWithoutSeqInfo = OldLoopWithoutSeqInfo;
375 SemaRef.ActiveReductionClauses.swap(ActiveReductionClauses);
386 SemaRef.PushExpressionEvaluationContext(
403 "Only one of directive or clause kind should be provided");
412 unsigned getDiagKind()
const {
423 : ICEConvertDiagnoser(
false,
426 DirectiveKind(DK), ClauseKind(CK), IntExpr(IntExpr) {}
431 return T->isIntegerType();
435 return S.
Diag(Loc, diag::err_acc_int_expr_requires_integer)
436 << getDiagKind() << ClauseKind << DirectiveKind <<
T;
441 return S.
Diag(Loc, diag::err_acc_int_expr_incomplete_class_type)
448 return S.
Diag(Loc, diag::err_acc_int_expr_explicit_conversion)
461 return S.
Diag(Loc, diag::err_acc_int_expr_multiple_conversions) <<
T;
473 llvm_unreachable(
"conversion functions are permitted");
475 } IntExprDiagnoser(DK, CK, IntExpr);
481 Loc, IntExpr, IntExprDiagnoser);
485 IntExpr = IntExprResult.
get();
519 return Diag(VarExpr->
getExprLoc(), diag::err_acc_var_not_pointer_type)
527 CacheInfo.ParsingCacheVarList =
true;
528 CacheInfo.IsInvalidCacheRef =
false;
533 CacheInfo.ParsingCacheVarList =
false;
534 CacheInfo.IsInvalidCacheRef =
false;
536 SemaRef.CleanupVarDeclMarking();
546 bool WasParsingInvalidCacheRef =
547 CacheInfo.ParsingCacheVarList && CacheInfo.IsInvalidCacheRef;
548 CacheInfo.ParsingCacheVarList =
false;
549 CacheInfo.IsInvalidCacheRef =
false;
559 if (
auto *SubScrpt = dyn_cast<ArraySubscriptExpr>(CurVarExpr))
567 if (
const auto *DRE = dyn_cast<DeclRefExpr>(CurVarExpr)) {
569 DRE->getFoundDecl()->getCanonicalDecl()))
570 return WasParsingInvalidCacheRef ?
ExprEmpty() : VarExpr;
573 if (
const auto *ME = dyn_cast<MemberExpr>(CurVarExpr)) {
575 return WasParsingInvalidCacheRef ?
ExprEmpty() : VarExpr;
582 return WasParsingInvalidCacheRef ?
ExprEmpty() : VarExpr;
594 if (!
getLangOpts().OpenACC || !CacheInfo.ParsingCacheVarList || !D ||
620 Diag(Loc, diag::warn_acc_cache_var_not_outside_loop);
622 CacheInfo.IsInvalidCacheRef =
true;
655 if (!ArrTy->isConstantArrayType()) {
656 S.
Diag(InnerLoc, clang::diag::warn_acc_var_referenced_non_const_array)
661 return CheckVarType(S, CK, VarExpr, InnerLoc, ArrTy->getElementType());
666 diag::err_incomplete_type))
677 bool HasNonDeletedDefaultCtor =
678 llvm::find_if(RD->ctors(), [](
const CXXConstructorDecl *CD) {
679 return CD->isDefaultConstructor() && !CD->isDeleted();
680 }) != RD->ctors().end();
681 if (!HasNonDeletedDefaultCtor && !RD->needsImplicitDefaultConstructor()) {
682 S.
Diag(InnerLoc, clang::diag::warn_acc_var_referenced_lacks_op)
683 << InnerTy << CK << clang::diag::AccVarReferencedReason::DefCtor;
687 if (!RD->hasSimpleCopyConstructor()) {
695 S.
Diag(InnerLoc, clang::diag::warn_acc_var_referenced_lacks_op)
696 << InnerTy << CK << clang::diag::AccVarReferencedReason::CopyCtor;
707 bool DestructorDeleted =
708 RD->getDestructor() && RD->getDestructor()->isDeleted();
709 if (DestructorDeleted && !RD->needsImplicitDestructor()) {
710 S.
Diag(InnerLoc, clang::diag::warn_acc_var_referenced_lacks_op)
711 << InnerTy << CK << clang::diag::AccVarReferencedReason::Dtor;
721 return CheckVarType(S, CK, VarExpr, InnerExpr->
getBeginLoc(),
729 SemaRef.CleanupVarDeclMarking();
747 diag::err_acc_not_a_var_ref_use_device_declare)
755 diag::ext_acc_array_section_use_device_declare)
762 if (
auto *SubScrpt = dyn_cast<ArraySubscriptExpr>(CurVarExpr))
770 if (
const auto *DRE = dyn_cast<DeclRefExpr>(CurVarExpr)) {
772 DRE->getFoundDecl()->getCanonicalDecl()))
773 return CheckVarType(*
this, CK, VarExpr, CurVarExpr);
782 if (
const auto *ME = dyn_cast<MemberExpr>(CurVarExpr)) {
790 const auto *
This = dyn_cast<CXXThisExpr>(ME->getBase());
792 return CheckVarType(*
this, CK, VarExpr, CurVarExpr);
794 return CheckVarType(*
this, CK, VarExpr, CurVarExpr);
803 return CheckVarType(*
this, CK, VarExpr, CurVarExpr);
810 return CheckVarType(*
this, CK, VarExpr, CurVarExpr);
818 Diag(VarExpr->
getExprLoc(), diag::err_acc_not_a_var_ref_use_device_declare)
821 Diag(VarExpr->
getExprLoc(), diag::err_acc_not_a_var_ref_use_device_declare)
837 if (
Base->hasPlaceholderType() &&
838 !
Base->hasPlaceholderType(BuiltinType::ArraySection)) {
851 LowerBound =
Result.get();
853 if (Length && Length->getType()->isNonOverloadPlaceholderType()) {
867 if (!
Base->isTypeDependent()) {
875 Diag(
Base->getExprLoc(), diag::err_acc_typecheck_subarray_value)
876 <<
Base->getSourceRange());
880 Diag(
Base->getExprLoc(), diag::err_acc_subarray_function_type)
881 << ResultTy <<
Base->getSourceRange();
885 if (
SemaRef.RequireCompleteType(
Base->getExprLoc(), ResultTy,
886 diag::err_acc_subarray_incomplete_type,
890 if (!
Base->hasPlaceholderType(BuiltinType::ArraySection)) {
901 return Recovery.
isUsable() ? Recovery.
get() :
nullptr;
911 LBRes =
SemaRef.DefaultLvalueConversion(LBRes.
get());
913 LBRes.
isUsable() ? LBRes.
get() : GetRecovery(LowerBound, Context.IntTy);
916 if (Length && !Length->isTypeDependent()) {
919 Length->getExprLoc(), Length);
922 LenRes =
SemaRef.DefaultLvalueConversion(LenRes.
get());
924 LenRes.
isUsable() ? LenRes.
get() : GetRecovery(Length, Context.IntTy);
928 if (!Length && (OriginalBaseTy.
isNull() ||
934 Diag(DiagLoc, diag::err_acc_subarray_no_length) << IsArray;
939 Length = Recovery.
isUsable() ? Recovery.
get() :
nullptr;
950 std::optional<llvm::APSInt> BaseSize;
952 const auto *ArrayTy = Context.getAsConstantArrayType(OriginalBaseTy);
953 BaseSize = ArrayTy->getSize();
956 auto GetBoundValue = [&](
Expr *E) -> std::optional<llvm::APSInt> {
966 std::optional<llvm::APSInt> LowerBoundValue = GetBoundValue(LowerBound);
967 std::optional<llvm::APSInt> LengthValue = GetBoundValue(Length);
970 if (LowerBoundValue.has_value()) {
971 if (LowerBoundValue->isNegative()) {
973 << 0 <<
toString(*LowerBoundValue, 10);
974 LowerBoundValue.reset();
975 LowerBound = GetRecovery(LowerBound, LowerBound->
getType());
976 }
else if (BaseSize.has_value() &&
977 llvm::APSInt::compareValues(*LowerBoundValue, *BaseSize) >= 0) {
979 Diag(LowerBound->
getExprLoc(), diag::err_acc_subarray_out_of_range)
980 << 0 <<
toString(*LowerBoundValue, 10)
982 LowerBoundValue.reset();
983 LowerBound = GetRecovery(LowerBound, LowerBound->
getType());
988 if (LengthValue.has_value()) {
989 if (LengthValue->isNegative()) {
990 Diag(Length->getExprLoc(), diag::err_acc_subarray_negative)
993 Length = GetRecovery(Length, Length->getType());
994 }
else if (BaseSize.has_value() &&
995 llvm::APSInt::compareValues(*LengthValue, *BaseSize) > 0) {
997 Diag(Length->getExprLoc(), diag::err_acc_subarray_out_of_range)
1000 LengthValue.reset();
1001 Length = GetRecovery(Length, Length->getType());
1006 auto AddAPSInt = [](llvm::APSInt LHS, llvm::APSInt RHS) -> llvm::APSInt {
1007 if (LHS.isSigned() == RHS.isSigned() &&
1008 LHS.getBitWidth() == RHS.getBitWidth())
1012 unsigned Width = std::max(LHS.getBitWidth(), RHS.getBitWidth()) + 1;
1013 return llvm::APSInt(LHS.sext(Width) + RHS.sext(Width),
true);
1018 if (BaseSize.has_value() && LowerBoundValue.has_value() &&
1019 LengthValue.has_value() &&
1020 llvm::APSInt::compareValues(AddAPSInt(*LowerBoundValue, *LengthValue),
1023 diag::err_acc_subarray_base_plus_length_out_of_range)
1028 LowerBoundValue.reset();
1029 LowerBound = GetRecovery(LowerBound, LowerBound->
getType());
1030 LengthValue.reset();
1031 Length = GetRecovery(Length, Length->getType());
1035 QualType ArrayExprTy = Context.ArraySectionTy;
1036 if (
Base->isTypeDependent() ||
1038 (Length && Length->isTypeDependent()))
1039 ArrayExprTy = Context.DependentTy;
1041 return new (Context)
1050 if (!LoopInfo.TopLevelLoopSeen)
1053 if (CollapseInfo.CurCollapseCount && *CollapseInfo.CurCollapseCount > 0) {
1054 Diag(WhileLoc, diag::err_acc_invalid_in_loop)
1055 << 1 << CollapseInfo.DirectiveKind
1057 assert(CollapseInfo.ActiveCollapse &&
"Collapse count without object?");
1058 Diag(CollapseInfo.ActiveCollapse->getBeginLoc(),
1059 diag::note_acc_active_clause_here)
1064 CollapseInfo.CurCollapseCount = std::nullopt;
1067 if (TileInfo.CurTileCount && *TileInfo.CurTileCount > 0) {
1068 Diag(WhileLoc, diag::err_acc_invalid_in_loop)
1069 << 1 << TileInfo.DirectiveKind
1071 assert(TileInfo.ActiveTile &&
"tile count without object?");
1072 Diag(TileInfo.ActiveTile->getBeginLoc(), diag::note_acc_active_clause_here)
1077 TileInfo.CurTileCount = std::nullopt;
1085 if (!LoopInfo.TopLevelLoopSeen)
1088 if (CollapseInfo.CurCollapseCount && *CollapseInfo.CurCollapseCount > 0) {
1089 Diag(DoLoc, diag::err_acc_invalid_in_loop)
1090 << 2 << CollapseInfo.DirectiveKind
1092 assert(CollapseInfo.ActiveCollapse &&
"Collapse count without object?");
1093 Diag(CollapseInfo.ActiveCollapse->getBeginLoc(),
1094 diag::note_acc_active_clause_here)
1099 CollapseInfo.CurCollapseCount = std::nullopt;
1102 if (TileInfo.CurTileCount && *TileInfo.CurTileCount > 0) {
1103 Diag(DoLoc, diag::err_acc_invalid_in_loop)
1105 assert(TileInfo.ActiveTile &&
"tile count without object?");
1106 Diag(TileInfo.ActiveTile->getBeginLoc(), diag::note_acc_active_clause_here)
1111 TileInfo.CurTileCount = std::nullopt;
1116 ForStmtBeginChecker &
C) {
1117 assert(
getLangOpts().OpenACC &&
"Check enabled when not OpenACC?");
1120 LoopInfo.TopLevelLoopSeen =
true;
1122 if (CollapseInfo.CurCollapseCount && *CollapseInfo.CurCollapseCount > 0) {
1131 if (LoopInfo.CurLevelHasLoopAlready) {
1132 Diag(ForLoc, diag::err_acc_clause_multiple_loops)
1134 assert(CollapseInfo.ActiveCollapse &&
"No collapse object?");
1136 diag::note_acc_active_clause_here)
1139 --(*CollapseInfo.CurCollapseCount);
1143 if (*CollapseInfo.CurCollapseCount == 0)
1144 CollapseInfo.CollapseDepthSatisfied =
true;
1148 if (TileInfo.CurTileCount && *TileInfo.CurTileCount > 0) {
1152 if (LoopInfo.CurLevelHasLoopAlready) {
1153 Diag(ForLoc, diag::err_acc_clause_multiple_loops)
1155 assert(TileInfo.ActiveTile &&
"No tile object?");
1156 Diag(TileInfo.ActiveTile->getBeginLoc(),
1157 diag::note_acc_active_clause_here)
1160 TileInfo.CurTileCount = *TileInfo.CurTileCount - 1;
1163 if (*TileInfo.CurTileCount == 0)
1164 TileInfo.TileDepthSatisfied =
true;
1170 LoopInfo.CurLevelHasLoopAlready =
false;
1174bool isValidLoopVariableType(QualType LoopVarTy) {
1197 for (
const auto *TD :
1198 llvm::make_filter_range(RD->decls(), llvm::IsaPred<TypedefNameDecl>)) {
1201 if (TDND->getName() !=
"iterator_category")
1205 if (TDND->getUnderlyingType().isNull())
1208 const CXXRecordDecl *ItrCategoryDecl =
1209 TDND->getUnderlyingType()->getAsCXXRecordDecl();
1212 if (!ItrCategoryDecl)
1215 auto IsRandomAccessIteratorTag = [](
const CXXRecordDecl *RD) {
1216 if (RD->getName() !=
"random_access_iterator_tag")
1219 return RD->getEnclosingNamespaceContext()->isStdNamespace();
1222 if (IsRandomAccessIteratorTag(ItrCategoryDecl))
1228 for (CXXBaseSpecifier BS : ItrCategoryDecl->
bases())
1229 if (IsRandomAccessIteratorTag(BS.getType()->getAsCXXRecordDecl()))
1238const ValueDecl *getDeclFromExpr(
const Expr *E) {
1240 if (
const auto *FE = dyn_cast<FullExpr>(E))
1241 E = FE->getSubExpr();
1247 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E))
1248 return DRE->getDecl();
1250 if (
const auto *ME = dyn_cast<MemberExpr>(E))
1252 return ME->getMemberDecl();
1258void SemaOpenACC::ForStmtBeginChecker::checkRangeFor() {
1259 const RangeForInfo &RFI = std::get<RangeForInfo>(Info);
1261 if (RFI.Uninstantiated == RFI.CurrentVersion)
1264 const DeclStmt *UninstRangeStmt =
1265 IsInstantiation ? RFI.Uninstantiated->getBeginStmt() :
nullptr;
1266 const DeclStmt *RangeStmt = RFI.CurrentVersion->getBeginStmt();
1270 if (UninstRangeStmt) {
1271 const ValueDecl *InitVar =
1275 if (!isValidLoopVariableType(VarType))
1285 if (!isValidLoopVariableType(VarType)) {
1287 <<
SemaRef.LoopWithoutSeqInfo.Kind << VarType;
1289 diag::note_acc_construct_here)
1290 <<
SemaRef.LoopWithoutSeqInfo.Kind;
1295bool SemaOpenACC::ForStmtBeginChecker::checkForInit(
const Stmt *InitStmt,
1296 const ValueDecl *&InitVar,
1301 SemaRef.Diag(ForLoc, diag::err_acc_loop_variable)
1302 <<
SemaRef.LoopWithoutSeqInfo.Kind;
1304 diag::note_acc_construct_here)
1305 <<
SemaRef.LoopWithoutSeqInfo.Kind;
1309 auto DiagLoopVar = [
this,
Diag, InitStmt]() {
1312 <<
SemaRef.LoopWithoutSeqInfo.Kind;
1314 diag::note_acc_construct_here)
1315 <<
SemaRef.LoopWithoutSeqInfo.Kind;
1320 if (
const auto *ExprTemp = dyn_cast<ExprWithCleanups>(InitStmt))
1321 InitStmt = ExprTemp->getSubExpr();
1322 if (
const auto *E = dyn_cast<Expr>(InitStmt))
1326 if (
const auto *BO = dyn_cast<BinaryOperator>(InitStmt)) {
1329 if (!BO->isAssignmentOp())
1330 return DiagLoopVar();
1332 const Expr *LHS = BO->getLHS()->IgnoreParenImpCasts();
1333 if (
const auto *DRE = dyn_cast<DeclRefExpr>(LHS))
1334 InitVar = DRE->getDecl();
1335 }
else if (
const auto *DS = dyn_cast<DeclStmt>(InitStmt)) {
1337 if (!DS->isSingleDecl())
1338 return DiagLoopVar();
1339 InitVar = dyn_cast<ValueDecl>(DS->getSingleDecl());
1344 return DiagLoopVar();
1349 return DiagLoopVar();
1351 }
else if (
auto *CE = dyn_cast<CXXOperatorCallExpr>(InitStmt)) {
1353 if (CE->getOperator() != OO_Equal)
1354 return DiagLoopVar();
1355 if (CE->getNumArgs() < 1)
1356 return DiagLoopVar();
1359 if (
auto *DRE = dyn_cast<DeclRefExpr>(LHS)) {
1360 InitVar = DRE->getDecl();
1361 }
else if (
auto *ME = dyn_cast<MemberExpr>(LHS)) {
1363 InitVar = ME->getMemberDecl();
1369 return DiagLoopVar();
1375 if (!isValidLoopVariableType(VarType)) {
1378 <<
SemaRef.LoopWithoutSeqInfo.Kind << VarType;
1380 diag::note_acc_construct_here)
1381 <<
SemaRef.LoopWithoutSeqInfo.Kind;
1389bool SemaOpenACC::ForStmtBeginChecker::checkForCond(
const Stmt *CondStmt,
1390 const ValueDecl *InitVar,
1395 SemaRef.Diag(ForLoc, diag::err_acc_loop_terminating_condition)
1396 <<
SemaRef.LoopWithoutSeqInfo.Kind;
1398 diag::note_acc_construct_here)
1399 <<
SemaRef.LoopWithoutSeqInfo.Kind;
1404 auto DiagCondVar = [
this,
Diag, CondStmt] {
1407 diag::err_acc_loop_terminating_condition)
1408 <<
SemaRef.LoopWithoutSeqInfo.Kind;
1410 diag::note_acc_construct_here)
1411 <<
SemaRef.LoopWithoutSeqInfo.Kind;
1416 if (
const auto *ExprTemp = dyn_cast<ExprWithCleanups>(CondStmt))
1417 CondStmt = ExprTemp->getSubExpr();
1418 if (
const auto *E = dyn_cast<Expr>(CondStmt))
1421 const ValueDecl *CondVar =
nullptr;
1422 if (
const auto *BO = dyn_cast<BinaryOperator>(CondStmt)) {
1423 switch (BO->getOpcode()) {
1425 return DiagCondVar();
1438 CondVar = getDeclFromExpr(BO->getLHS());
1441 CondVar = getDeclFromExpr(BO->getRHS());
1443 }
else if (
const auto *CE = dyn_cast<CXXOperatorCallExpr>(CondStmt)) {
1446 if (!CE->isComparisonOp() || CE->getOperator() == OO_Spaceship)
1447 return DiagCondVar();
1449 if (CE->getNumArgs() < 1)
1454 CondVar = getDeclFromExpr(CE->getArg(0));
1458 CE->getNumArgs() > 1))
1459 CondVar = getDeclFromExpr(CE->getArg(1));
1461 return DiagCondVar();
1465 return DiagCondVar();
1470 return DiagCondVar();
1479bool isValidForIncRHSAssign(
const ValueDecl *InitVar,
const Expr *RHS) {
1481 auto isValid = [](
const ValueDecl *InitVar,
const Expr *InnerLHS,
1482 const Expr *InnerRHS,
bool IsAddition) {
1484 if (!InnerLHS->getType()->isIntegerType() &&
1485 !InnerRHS->getType()->isIntegerType())
1493 const ValueDecl *LHSDecl = getDeclFromExpr(InnerLHS);
1494 const ValueDecl *RHSDecl = getDeclFromExpr(InnerRHS);
1496 if (!LHSDecl || !RHSDecl)
1512 if (
const auto *BO = dyn_cast<BinaryOperator>(RHS)) {
1514 if (OpC != BO_Add && OpC != BO_Sub)
1516 return isValid(InitVar, BO->getLHS(), BO->getRHS(), OpC == BO_Add);
1517 }
else if (
const auto *CE = dyn_cast<CXXOperatorCallExpr>(RHS)) {
1519 if (Op != OO_Plus && Op != OO_Minus)
1524 if (CE->getNumArgs() != 2)
1526 return isValid(InitVar, CE->getArg(0), CE->getArg(1), Op == OO_Plus);
1533bool SemaOpenACC::ForStmtBeginChecker::checkForInc(
const Stmt *IncStmt,
1534 const ValueDecl *InitVar,
1538 SemaRef.Diag(ForLoc, diag::err_acc_loop_not_monotonic)
1539 <<
SemaRef.LoopWithoutSeqInfo.Kind;
1541 diag::note_acc_construct_here)
1542 <<
SemaRef.LoopWithoutSeqInfo.Kind;
1546 auto DiagIncVar = [
this,
Diag, IncStmt] {
1549 <<
SemaRef.LoopWithoutSeqInfo.Kind;
1551 diag::note_acc_construct_here)
1552 <<
SemaRef.LoopWithoutSeqInfo.Kind;
1557 if (
const auto *ExprTemp = dyn_cast<ExprWithCleanups>(IncStmt))
1558 IncStmt = ExprTemp->getSubExpr();
1559 if (
const auto *E = dyn_cast<Expr>(IncStmt))
1562 const ValueDecl *IncVar =
nullptr;
1564 if (
const auto *UO = dyn_cast<UnaryOperator>(IncStmt)) {
1566 if (!UO->isIncrementDecrementOp())
1567 return DiagIncVar();
1568 IncVar = getDeclFromExpr(UO->getSubExpr());
1569 }
else if (
const auto *BO = dyn_cast<BinaryOperator>(IncStmt)) {
1570 switch (BO->getOpcode()) {
1572 return DiagIncVar();
1579 if (!isValidForIncRHSAssign(InitVar, BO->getRHS()))
1580 return DiagIncVar();
1583 IncVar = getDeclFromExpr(BO->getLHS());
1584 }
else if (
const auto *CE = dyn_cast<CXXOperatorCallExpr>(IncStmt)) {
1585 if (CE->getNumArgs() < 1)
1586 return DiagIncVar();
1588 switch (CE->getOperator()) {
1590 return DiagIncVar();
1599 if (CE->getNumArgs() != 2 ||
1600 !isValidForIncRHSAssign(InitVar, CE->getArg(1)))
1601 return DiagIncVar();
1605 IncVar = getDeclFromExpr(CE->getArg(0));
1607 return DiagIncVar();
1611 return DiagIncVar();
1617 return DiagIncVar();
1622void SemaOpenACC::ForStmtBeginChecker::checkFor() {
1623 const CheckForInfo &CFI = std::get<CheckForInfo>(Info);
1625 if (!IsInstantiation) {
1628 const ValueDecl *CurInitVar =
nullptr;
1629 checkForInit(CFI.Current.Init, CurInitVar,
true);
1630 checkForCond(CFI.Current.Condition, CurInitVar,
true);
1631 checkForInc(CFI.Current.Increment, CurInitVar,
true);
1633 const ValueDecl *UninstInitVar =
nullptr;
1637 bool UninstInitFailed =
1638 checkForInit(CFI.Uninst.Init, UninstInitVar,
false);
1644 auto InitChanged = [=]() {
1645 if (CFI.Uninst.Init == CFI.Current.Init)
1651 if (
const auto *DS = dyn_cast<DeclStmt>(CFI.Uninst.Init))
1652 if (
const VarDecl *VD = dyn_cast_if_present<VarDecl>(
1653 DS->isSingleDecl() ? DS->getSingleDecl() :
nullptr))
1654 OldVDTy = VD->getType();
1655 if (
const auto *DS = dyn_cast<DeclStmt>(CFI.Current.Init))
1656 if (
const VarDecl *VD = dyn_cast_if_present<VarDecl>(
1657 DS->isSingleDecl() ? DS->getSingleDecl() :
nullptr))
1658 NewVDTy = VD->getType();
1669 bool ShouldDiagNewInit = !UninstInitFailed && InitChanged();
1670 const ValueDecl *CurInitVar =
nullptr;
1671 checkForInit(CFI.Current.Init, CurInitVar, ShouldDiagNewInit);
1675 if (CFI.Uninst.Condition != CFI.Current.Condition &&
1676 !checkForCond(CFI.Uninst.Condition, UninstInitVar,
false))
1677 checkForCond(CFI.Current.Condition, CurInitVar,
true);
1678 if (CFI.Uninst.Increment != CFI.Current.Increment &&
1679 !checkForInc(CFI.Uninst.Increment, UninstInitVar,
false))
1680 checkForInc(CFI.Current.Increment, CurInitVar,
true);
1684void SemaOpenACC::ForStmtBeginChecker::check() {
1695 AlreadyChecked =
true;
1712 if (std::holds_alternative<RangeForInfo>(Info))
1713 return checkRangeFor();
1720 const Stmt *Second,
const Stmt *OldThird,
1721 const Stmt *Third) {
1725 ForStmtBeginChecker FSBC{*
this, ForLoc, OldFirst, OldSecond,
1726 OldThird,
First, Second, Third};
1729 if (!LoopInfo.TopLevelLoopSeen) {
1733 ForStmtBeginHelper(ForLoc, FSBC);
1737 const Stmt *Second,
const Stmt *Third) {
1741 ForStmtBeginChecker FSBC{*
this, ForLoc,
First, Second, Third};
1745 if (!LoopInfo.TopLevelLoopSeen)
1748 ForStmtBeginHelper(ForLoc, FSBC);
1752 const Stmt *OldRangeFor,
1753 const Stmt *RangeFor) {
1754 if (!
getLangOpts().OpenACC || OldRangeFor ==
nullptr || RangeFor ==
nullptr)
1757 ForStmtBeginChecker FSBC{*
this, ForLoc,
1758 cast_if_present<CXXForRangeStmt>(OldRangeFor),
1759 cast_if_present<CXXForRangeStmt>(RangeFor)};
1762 if (!LoopInfo.TopLevelLoopSeen) {
1765 ForStmtBeginHelper(ForLoc, FSBC);
1769 const Stmt *RangeFor) {
1770 if (!
getLangOpts().OpenACC || RangeFor ==
nullptr)
1773 ForStmtBeginChecker FSBC = {*
this, ForLoc,
1774 cast_if_present<CXXForRangeStmt>(RangeFor)};
1778 if (!LoopInfo.TopLevelLoopSeen)
1781 ForStmtBeginHelper(ForLoc, FSBC);
1801 if (
const auto *CS = dyn_cast<CompoundStmt>(CurStmt)) {
1802 for (
const auto *ChildStmt : CS->children()) {
1803 SourceLocation ChildStmtLoc = FindInterveningCodeInLoop(ChildStmt);
1805 return ChildStmtLoc;
1808 return SourceLocation{};
1819 LoopInfo.CurLevelHasLoopAlready =
true;
1824 bool IsActiveCollapse = CollapseInfo.CurCollapseCount &&
1825 *CollapseInfo.CurCollapseCount > 0 &&
1826 !CollapseInfo.ActiveCollapse->hasForce();
1827 bool IsActiveTile = TileInfo.CurTileCount && *TileInfo.CurTileCount > 0;
1829 if (IsActiveCollapse || IsActiveTile) {
1832 if (OtherStmtLoc.
isValid() && IsActiveCollapse) {
1833 Diag(OtherStmtLoc, diag::err_acc_intervening_code)
1835 Diag(CollapseInfo.ActiveCollapse->getBeginLoc(),
1836 diag::note_acc_active_clause_here)
1840 if (OtherStmtLoc.
isValid() && IsActiveTile) {
1841 Diag(OtherStmtLoc, diag::err_acc_intervening_code)
1843 Diag(TileInfo.ActiveTile->getBeginLoc(),
1844 diag::note_acc_active_clause_here)
1864 }
else if (
auto *DRE = dyn_cast<DeclRefExpr>(RoutineName)) {
1865 ValueDecl *VD = DRE->getDecl();
1867 if (
auto *FD = dyn_cast<FunctionDecl>(VD))
1871 if (
auto *VarD = dyn_cast<VarDecl>(VD)) {
1872 QualType VarDTy = VarD->getType();
1875 if (RD->isGenericLambda())
1878 return RD->getLambdaCallOperator();
1894 assert(RoutineName &&
"Routine name cannot be null here");
1905 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(RoutineName)) {
1912 if (
const auto *VarD = dyn_cast<VarDecl>(VD)) {
1916 if (RD->isGenericLambda()) {
1956 auto *ContextDecl = dyn_cast<FunctionDecl>(
getCurContext());
1964 for (
const auto *A : ContextDecl->attrs()) {
1967 Diag(A->getLocation(), diag::note_acc_construct_here)
1973 MagicStaticLocs.insert({ContextDecl->getCanonicalDecl(), VD->
getBeginLoc()});
1975void SemaOpenACC::CheckLastRoutineDeclNameConflict(
const NamedDecl *ND) {
1984 if (!LastRoutineDecl)
2017 if (NDLine - LastLine > 1)
2025 diag::warn_acc_confusing_routine_name);
2041 if (!RD || !RD->isLambda())
2044 CheckLastRoutineDeclNameConflict(VD);
2050 CheckLastRoutineDeclNameConflict(FD);
2062 SemaRef.DiscardCleanupsInEvaluationContext();
2063 SemaRef.PopExpressionEvaluationContext();
2070 if (CollapseInfo.CurCollapseCount && *CollapseInfo.CurCollapseCount > 0) {
2071 Diag(StartLoc, diag::err_acc_invalid_in_loop)
2072 << 0 << CollapseInfo.DirectiveKind
2074 assert(CollapseInfo.ActiveCollapse &&
"Collapse count without object?");
2075 Diag(CollapseInfo.ActiveCollapse->getBeginLoc(),
2076 diag::note_acc_active_clause_here)
2079 if (TileInfo.CurTileCount && *TileInfo.CurTileCount > 0) {
2080 Diag(StartLoc, diag::err_acc_invalid_in_loop)
2081 << 0 << TileInfo.DirectiveKind
2083 assert(TileInfo.ActiveTile &&
"Tile count without object?");
2084 Diag(TileInfo.ActiveTile->getBeginLoc(), diag::note_acc_active_clause_here)
2088 if (DiagnoseRequiredClauses(K, StartLoc, Clauses))
2090 return diagnoseConstructAppertainment(*
this, K, StartLoc,
true);
2105 return OpenACCComputeConstruct::Create(
2107 AssocStmt.
isUsable() ? AssocStmt.
get() :
nullptr);
2114 AssocStmt.
isUsable() ? AssocStmt.
get() :
nullptr);
2118 getASTContext(), ActiveComputeConstructInfo.Kind, StartLoc, DirLoc,
2119 EndLoc, Clauses, AssocStmt.
isUsable() ? AssocStmt.
get() :
nullptr);
2124 AssocStmt.
isUsable() ? AssocStmt.
get() :
nullptr);
2137 AssocStmt.
isUsable() ? AssocStmt.
get() :
nullptr);
2141 getASTContext(), StartLoc, DirLoc, LParenLoc, Exprs.front(), MiscLoc,
2142 Exprs.drop_front(), RParenLoc, EndLoc, Clauses);
2162 getASTContext(), StartLoc, DirLoc, AtomicKind, EndLoc, Clauses,
2163 AssocStmt.
isUsable() ? AssocStmt.
get() :
nullptr);
2166 assert(Clauses.empty() &&
"Cache doesn't allow clauses");
2168 LParenLoc, MiscLoc, Exprs, RParenLoc,
2172 llvm_unreachable(
"routine shouldn't handled here");
2177 RParenLoc, EndLoc, Clauses);
2182 llvm_unreachable(
"Unhandled case in directive handling?");
2191 llvm_unreachable(
"Unimplemented associated statement application");
2200 "these don't have associated statements, so shouldn't get here");
2228 Diag(DirectiveLoc, diag::note_acc_construct_here) << K;
2232 if (!CollapseInfo.CollapseDepthSatisfied || !TileInfo.TileDepthSatisfied) {
2233 if (!CollapseInfo.CollapseDepthSatisfied) {
2234 Diag(DirectiveLoc, diag::err_acc_insufficient_loops)
2236 assert(CollapseInfo.ActiveCollapse &&
"Collapse count without object?");
2237 Diag(CollapseInfo.ActiveCollapse->getBeginLoc(),
2238 diag::note_acc_active_clause_here)
2242 if (!TileInfo.TileDepthSatisfied) {
2243 Diag(DirectiveLoc, diag::err_acc_insufficient_loops)
2245 assert(TileInfo.ActiveTile &&
"Collapse count without object?");
2246 Diag(TileInfo.ActiveTile->getBeginLoc(),
2247 diag::note_acc_active_clause_here)
2253 return AssocStmt.
get();
2255 llvm_unreachable(
"Invalid associated statement application");
2263bool CheckValidRoutineGangWorkerVectorSeqClauses(
2275 auto *FirstDeviceType =
2276 llvm::find_if(Clauses, llvm::IsaPred<OpenACCDeviceTypeClause>);
2281 std::find_if(Clauses.begin(), FirstDeviceType, RequiredPred);
2283 if (ClauseItr != FirstDeviceType)
2287 if (FirstDeviceType == Clauses.end())
2288 return SemaRef.
Diag(DirectiveLoc, diag::err_acc_construct_one_clause_of)
2290 <<
"'gang', 'seq', 'vector', or 'worker'";
2294 auto *PrevDeviceType = FirstDeviceType;
2296 while (PrevDeviceType != Clauses.end()) {
2297 auto *NextDeviceType =
2298 std::find_if(std::next(PrevDeviceType), Clauses.end(),
2299 llvm::IsaPred<OpenACCDeviceTypeClause>);
2301 ClauseItr = std::find_if(PrevDeviceType, NextDeviceType, RequiredPred);
2303 if (ClauseItr == NextDeviceType)
2304 return SemaRef.
Diag((*PrevDeviceType)->getBeginLoc(),
2305 diag::err_acc_clause_routine_one_of_in_region);
2307 PrevDeviceType = NextDeviceType;
2320 SemaRef.DiscardCleanupsInEvaluationContext();
2321 SemaRef.PopExpressionEvaluationContext();
2323 if (DiagnoseRequiredClauses(K, StartLoc, Clauses))
2326 CheckValidRoutineGangWorkerVectorSeqClauses(*
this, StartLoc, Clauses))
2329 return diagnoseConstructAppertainment(*
this, K, StartLoc,
false);
2342 if (Clauses.empty()) {
2343 Diag(EndLoc, diag::err_acc_declare_required_clauses);
2357 llvm_unreachable(
"routine shouldn't be handled here");
2359 llvm_unreachable(
"unhandled case in directive handling?");
2370 if (
auto *FD = dyn_cast<FunctionDecl>(D))
2374 if (
auto *FTD = dyn_cast<FunctionTemplateDecl>(D))
2375 return FTD->getTemplatedDecl();
2377 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
2379 FD->getType().isNull() ?
nullptr : FD->getType()->getAsCXXRecordDecl();
2381 if (RD && RD->isGenericLambda())
2382 return RD->getDependentLambdaCallOperator()->getTemplatedDecl();
2383 if (RD && RD->isLambda())
2384 return RD->getLambdaCallOperator();
2388 if (
auto *VD = dyn_cast<VarDecl>(D)) {
2390 if (!
Init ||
Init->getType().isNull())
2393 const auto *RD =
Init->getType()->getAsCXXRecordDecl();
2394 if (RD && RD->isGenericLambda())
2395 return RD->getDependentLambdaCallOperator()->getTemplatedDecl();
2396 if (RD && RD->isLambda())
2397 return RD->getLambdaCallOperator();
2412 ArrayRef<const OpenACCClause *> Clauses,
2414 OpenACCRoutineDeclAttr *A =
2415 OpenACCRoutineDeclAttr::Create(
SemaRef.getASTContext(), DirLoc);
2416 A->Clauses.assign(Clauses.begin(), Clauses.end());
2424 Decl *NextParsedDecl) {
2426 FunctionDecl *NextParsedFDecl = LegalizeNextParsedDecl(NextParsedDecl);
2428 if (!NextParsedFDecl) {
2430 SemaRef.Diag(DirLoc, diag::err_acc_decl_for_routine);
2438 Itr != MagicStaticLocs.end()) {
2439 Diag(Itr->second, diag::err_acc_magic_static_in_routine);
2440 Diag(DirLoc, diag::note_acc_construct_here)
2446 auto BindItr = llvm::find_if(Clauses, llvm::IsaPred<OpenACCBindClause>);
2447 if (BindItr != Clauses.end()) {
2448 for (
auto *A : NextParsedFDecl->
attrs()) {
2452 if (
auto *RA = dyn_cast<OpenACCRoutineDeclAttr>(A)) {
2454 llvm::find_if(RA->Clauses, llvm::IsaPred<OpenACCBindClause>);
2455 if (OtherBindItr != RA->Clauses.end() &&
2458 Diag((*BindItr)->getBeginLoc(), diag::err_acc_duplicate_unnamed_bind);
2459 Diag((*OtherBindItr)->getEndLoc(),
2460 diag::note_acc_previous_clause_here)
2461 << (*BindItr)->getClauseKind();
2472 if (
auto *RA = dyn_cast<OpenACCRoutineAnnotAttr>(A);
2473 RA && RA->getRange().getEnd().isValid()) {
2474 Diag((*BindItr)->getBeginLoc(), diag::err_acc_duplicate_bind);
2475 Diag(RA->getRange().getEnd(), diag::note_acc_previous_clause_here)
2482 CreateRoutineDeclAttr(*
this, DirLoc, Clauses, NextParsedFDecl);
2493 if ((FD = getFunctionFromRoutineName(FuncRef))) {
2498 Itr != MagicStaticLocs.end()) {
2499 Diag(Itr->second, diag::err_acc_magic_static_in_routine);
2500 Diag(DirLoc, diag::note_acc_construct_here)
2509 auto BindItr = llvm::find_if(Clauses, llvm::IsaPred<OpenACCBindClause>);
2511 if (BindItr != Clauses.end()) {
2512 BindLoc = (*BindItr)->getBeginLoc();
2516 for (
auto *A : FD->
attrs()) {
2517 if (
auto *RA = dyn_cast<OpenACCRoutineDeclAttr>(A)) {
2519 llvm::find_if(RA->Clauses, llvm::IsaPred<OpenACCBindClause>);
2520 if (OtherBindItr != RA->Clauses.end()) {
2521 Diag((*BindItr)->getBeginLoc(), diag::err_acc_duplicate_bind);
2522 Diag((*OtherBindItr)->getEndLoc(),
2523 diag::note_acc_previous_clause_here)
2524 << (*BindItr)->getClauseKind();
2529 if (
auto *RA = dyn_cast<OpenACCRoutineAnnotAttr>(A);
2530 RA && RA->getRange().getEnd().isValid()) {
2531 Diag((*BindItr)->getBeginLoc(), diag::err_acc_duplicate_bind);
2532 Diag(RA->getRange().getEnd(), diag::note_acc_previous_clause_here)
2533 << (*BindItr)->getClauseKind();
2541 auto *RAA = OpenACCRoutineAnnotAttr::CreateImplicit(
getASTContext(),
2546 for (
auto *CurFD : FD->
redecls())
2552 RParenLoc, EndLoc, Clauses);
2560 RoutineRefList.emplace_back(FD, LastRoutineDecl);
2562 return LastRoutineDecl;
2566 for (
auto [FD, RoutineDecl] : RoutineRefList)
2567 SemaRef.Consumer.HandleOpenACCRoutineReference(FD, RoutineDecl);
2575 assert((!ReferencedFunc || !NextDecl) &&
2576 "Only one of these should be filled");
2579 Decl *NextLineDecl =
nullptr;
2585 return NextDecl.
get();
2589 StartLoc, DirLoc, LParenLoc, ReferencedFunc, RParenLoc, Clauses, EndLoc)};
2597 assert((!ReferencedFunc || !NextStmt) &&
2598 "Only one of these should be filled");
2601 Decl *NextLineDecl =
nullptr;
2604 NextLineDecl = DS->getSingleDecl();
2611 RParenLoc, Clauses, EndLoc)};
2615OpenACCRoutineDeclAttr *
2617 OpenACCRoutineDeclAttr *
New =
2618 OpenACCRoutineDeclAttr::Create(
getASTContext(), Old.getLocation());
2621 New->Clauses = Old.Clauses;
2635enum class InitKind {
Invalid,
Zero, One, AllOnes, Least, Largest };
2638 case InitKind::Invalid:
2639 llvm_unreachable(
"invalid init kind");
2640 case InitKind::Zero:
2641 return llvm::APFloat::getZero(Context.getFloatTypeSemantics(Ty));
2643 return llvm::APFloat::getOne(Context.getFloatTypeSemantics(Ty));
2644 case InitKind::AllOnes:
2645 return llvm::APFloat::getAllOnesValue(Context.getFloatTypeSemantics(Ty));
2646 case InitKind::Least:
2647 return llvm::APFloat::getLargest(Context.getFloatTypeSemantics(Ty),
2649 case InitKind::Largest:
2650 return llvm::APFloat::getLargest(Context.getFloatTypeSemantics(Ty));
2652 llvm_unreachable(
"unknown init kind");
2655llvm::APInt getInitIntValue(ASTContext &Context, InitKind IK, QualType Ty) {
2657 case InitKind::Invalid:
2658 llvm_unreachable(
"invalid init kind");
2659 case InitKind::Zero:
2663 case InitKind::AllOnes:
2664 return llvm::APInt::getAllOnes(Context.
getIntWidth(Ty));
2665 case InitKind::Least:
2667 return llvm::APInt::getSignedMinValue(Context.
getIntWidth(Ty));
2668 return llvm::APInt::getMinValue(Context.
getIntWidth(Ty));
2669 case InitKind::Largest:
2671 return llvm::APInt::getSignedMaxValue(Context.
getIntWidth(Ty));
2672 return llvm::APInt::getMaxValue(Context.
getIntWidth(Ty));
2674 llvm_unreachable(
"unknown init kind");
2679Expr *GenerateReductionInitRecipeExpr(ASTContext &Context,
2680 SourceRange ExprRange, QualType Ty,
2682 if (IK == InitKind::Invalid)
2685 if (IK == InitKind::Zero) {
2687 new (Context) InitListExpr(Context, ExprRange.
getBegin(), {},
2688 ExprRange.
getEnd(),
false);
2694 llvm::SmallVector<Expr *> Exprs;
2697 for (
auto *F : RD->fields()) {
2698 if (Expr *NewExpr = GenerateReductionInitRecipeExpr(Context, ExprRange,
2700 Exprs.push_back(NewExpr);
2705 for (uint64_t Idx = 0; Idx < AT->getZExtSize(); ++Idx) {
2706 if (Expr *NewExpr = GenerateReductionInitRecipeExpr(
2707 Context, ExprRange, AT->getElementType(), IK))
2708 Exprs.push_back(NewExpr);
2727 if (
const auto *Cplx = Ty->
getAs<ComplexType>()) {
2732 QualType EltTy = Cplx->getElementType();
2735 Context, getInitFloatValue(Context, InitKind::Zero, EltTy),
2736 true, EltTy, ExprRange.
getBegin()));
2738 Context, getInitFloatValue(Context, InitKind::Zero, EltTy),
2739 true, EltTy, ExprRange.
getBegin()));
2742 Context, getInitIntValue(Context, InitKind::Zero, EltTy), EltTy,
2745 Context, getInitIntValue(Context, InitKind::Zero, EltTy), EltTy,
2755 (IK == InitKind::One ||
2756 IK == InitKind::AllOnes ||
2757 IK == InitKind::Largest),
2760 Exprs.push_back(
new (Context)
2761 CXXNullPtrLiteralExpr(Ty, ExprRange.
getBegin()));
2764 Context, getInitIntValue(Context, IK, Ty), Ty, ExprRange.
getBegin()));
2769 new (Context) InitListExpr(Context, ExprRange.
getBegin(), Exprs,
2770 ExprRange.
getEnd(),
false);
2775VarDecl *CreateAllocaDecl(ASTContext &Ctx, DeclContext *DC,
2776 SourceLocation BeginLoc, IdentifierInfo *VarName,
2778 auto *VD =
VarDecl::Create(Ctx, DC, BeginLoc, BeginLoc, VarName, VarTy,
2784ExprResult FinishValueInit(Sema &S, InitializedEntity &Entity,
2785 SourceLocation Loc, QualType VarTy, Expr *InitExpr) {
2789 InitializationKind
Kind =
2791 InitializationSequence InitSeq(S, Entity, Kind, InitExpr,
2795 return InitSeq.Perform(S, Entity, Kind, InitExpr, &VarTy);
2810 if (
const auto *ASE =
2812 VarTy = ASE->getElementType();
2814 VarDecl *AllocaDecl = CreateAllocaDecl(
2816 &
getASTContext().Idents.get(
"openacc.private.init"), VarTy);
2827 if (
Init.isUsable()) {
2846 if (
const auto *ASE =
2848 VarTy = ASE->getElementType();
2850 VarDecl *AllocaDecl = CreateAllocaDecl(
2852 &
getASTContext().Idents.get(
"openacc.firstprivate.init"), VarTy);
2854 VarDecl *Temporary = CreateAllocaDecl(
2875 if (
Init.isUsable()) {
2889 CK_ArrayToPointerDecay, TemporaryDRE,
nullptr,
2892 for (std::size_t I = 0; I < ArrTy->getLimitedSize(); ++I) {
2915 CopySeq.
Perform(
SemaRef.SemaRef, CopyEntity, CopyKind, Subscript);
2916 Args.push_back(ElemRes.
get());
2929 if (
Init.isUsable()) {
2948 if (
const auto *ASE =
2950 VarTy = ASE->getElementType();
2957 if (CreateReductionCombinerRecipe(VarExpr->
getBeginLoc(), ReductionOperator,
2958 VarTy, CombinerRecipes))
2961 VarDecl *AllocaDecl = CreateAllocaDecl(
2963 &
getASTContext().Idents.get(
"openacc.reduction.init"), VarTy);
2968 InitKind IK = InitKind::Invalid;
2969 switch (ReductionOperator) {
2974 IK = InitKind::Invalid;
2977 IK = InitKind::Least;
2980 IK = InitKind::Largest;
2983 IK = InitKind::AllOnes;
2993 IK = InitKind::Zero;
2997 Expr *InitExpr = GenerateReductionInitRecipeExpr(
3005 if (
Init.isUsable()) {
3013bool SemaOpenACC::CreateReductionCombinerRecipe(
3025 switch (ReductionOperator) {
3030 CombinerRecipes.push_back({
nullptr,
nullptr,
nullptr});
3033 BinOp = BinaryOperatorKind::BO_AddAssign;
3036 BinOp = BinaryOperatorKind::BO_MulAssign;
3039 BinOp = BinaryOperatorKind::BO_AndAssign;
3042 BinOp = BinaryOperatorKind::BO_OrAssign;
3045 BinOp = BinaryOperatorKind::BO_XorAssign;
3050 BinOp = BinaryOperatorKind::BO_LT;
3053 BinOp = BinaryOperatorKind::BO_LAnd;
3056 BinOp = BinaryOperatorKind::BO_LOr;
3063 VarTy = AT->getElementType();
3065 assert(!VarTy->
isArrayType() &&
"Only 1 level of array allowed");
3067 enum class CombinerFailureKind {
3074 auto genCombiner = [&,
this](DeclRefExpr *LHSDRE, DeclRefExpr *RHSDRE)
3075 -> std::pair<ExprResult, CombinerFailureKind> {
3077 SemaRef.BuildBinOp(
SemaRef.getCurScope(), Loc, BinOp, LHSDRE, RHSDRE,
3079 switch (ReductionOperator) {
3087 return {BinOpRes, BinOpRes.
isUsable() ? CombinerFailureKind::None
3088 : CombinerFailureKind::BinOp};
3097 return {BinOpRes, CombinerFailureKind::BinOp};
3103 CondRes =
SemaRef.ActOnConditionalOp(Loc, Loc, BinOpRes.
get(), LHSDRE,
3106 CondRes =
SemaRef.ActOnConditionalOp(Loc, Loc, BinOpRes.
get(), RHSDRE,
3110 return {CondRes, CombinerFailureKind::Conditional};
3114 BinaryOperatorKind::BO_Assign,
3115 LHSDRE, CondRes.
get(),
3118 ? CombinerFailureKind::None
3119 : CombinerFailureKind::Assignment};
3126 return {BinOpRes, CombinerFailureKind::BinOp};
3130 BinaryOperatorKind::BO_Assign,
3131 LHSDRE, BinOpRes.
get(),
3134 ? CombinerFailureKind::None
3135 : CombinerFailureKind::Assignment};
3138 llvm_unreachable(
"Invalid should have been caught above");
3140 llvm_unreachable(
"Unhandled case");
3143 auto tryCombiner = [&,
this](DeclRefExpr *LHSDRE, DeclRefExpr *RHSDRE,
3147 Sema::TentativeAnalysisScope Trap{
SemaRef};
3148 return genCombiner(LHSDRE, RHSDRE);
3150 return genCombiner(LHSDRE, RHSDRE);
3153 struct CombinerAttemptTy {
3154 CombinerFailureKind FailKind;
3156 DeclRefExpr *LHSDRE;
3158 DeclRefExpr *RHSDRE;
3162 auto formCombiner = [&,
this](QualType Ty) -> CombinerAttemptTy {
3163 VarDecl *LHSDecl = CreateAllocaDecl(
3165 &
getASTContext().Idents.get(
"openacc.reduction.combiner.lhs"), Ty);
3167 getASTContext(), NestedNameSpecifierLoc{}, SourceLocation{}, LHSDecl,
3169 DeclarationNameInfo{DeclarationName{LHSDecl->
getDeclName()},
3172 VarDecl *RHSDecl = CreateAllocaDecl(
3174 &
getASTContext().Idents.get(
"openacc.reduction.combiner.lhs"), Ty);
3176 getASTContext(), NestedNameSpecifierLoc{}, SourceLocation{}, RHSDecl,
3178 DeclarationNameInfo{DeclarationName{RHSDecl->getDeclName()},
3179 RHSDecl->getBeginLoc()},
3182 std::pair<ExprResult, CombinerFailureKind> BinOpResult =
3183 tryCombiner(LHSDRE, RHSDRE,
true);
3185 return {BinOpResult.second, LHSDecl, LHSDRE, RHSDecl, RHSDRE,
3186 BinOpResult.first.get()};
3189 CombinerAttemptTy TopLevelCombinerInfo = formCombiner(VarTy);
3191 if (TopLevelCombinerInfo.Op) {
3192 if (!TopLevelCombinerInfo.Op->containsErrors() &&
3193 TopLevelCombinerInfo.Op->isInstantiationDependent()) {
3196 CombinerRecipes.push_back({
nullptr,
nullptr,
nullptr});
3198 }
else if (!TopLevelCombinerInfo.Op->containsErrors()) {
3200 CombinerRecipes.push_back({TopLevelCombinerInfo.LHS,
3201 TopLevelCombinerInfo.RHS,
3202 TopLevelCombinerInfo.Op});
3207 auto EmitFailureNote = [&](CombinerFailureKind CFK) {
3208 if (CFK == CombinerFailureKind::BinOp)
3209 return Diag(Loc, diag::note_acc_reduction_combiner_forming)
3211 return Diag(Loc, diag::note_acc_reduction_combiner_forming) << CFK;
3219 Diag(Loc, diag::err_acc_reduction_recipe_no_op) << VarTy;
3220 EmitFailureNote(TopLevelCombinerInfo.FailKind);
3221 tryCombiner(TopLevelCombinerInfo.LHSDRE, TopLevelCombinerInfo.RHSDRE,
3226 for (
const FieldDecl *FD : RD->
fields()) {
3227 CombinerAttemptTy FieldCombinerInfo = formCombiner(FD->getType());
3229 if (!FieldCombinerInfo.Op || FieldCombinerInfo.Op->containsErrors()) {
3230 Diag(Loc, diag::err_acc_reduction_recipe_no_op) << FD->getType();
3231 Diag(FD->getBeginLoc(), diag::note_acc_reduction_recipe_noop_field) << RD;
3232 EmitFailureNote(FieldCombinerInfo.FailKind);
3233 tryCombiner(FieldCombinerInfo.LHSDRE, FieldCombinerInfo.RHSDRE,
3238 if (FieldCombinerInfo.Op->isInstantiationDependent()) {
3241 CombinerRecipes.push_back({
nullptr,
nullptr,
nullptr});
3243 CombinerRecipes.push_back(
3244 {FieldCombinerInfo.LHS, FieldCombinerInfo.RHS, FieldCombinerInfo.Op});
This file defines OpenACC nodes for declarative directives.
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.
This file declares semantic analysis for OpenACC constructs and clauses.
Defines the SourceManager interface.
This file defines OpenACC AST classes for statement-level contructs.
static OpenACCAtomicConstruct * Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, OpenACCAtomicKind AtKind, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *AssociatedStmt)
static OpenACCCacheConstruct * Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation LParenLoc, SourceLocation ReadOnlyLoc, ArrayRef< Expr * > VarList, SourceLocation RParenLoc, SourceLocation End)
static OpenACCCombinedConstruct * Create(const ASTContext &C, OpenACCDirectiveKind K, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
static OpenACCDataConstruct * Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
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 OpenACCHostDataConstruct * Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
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 OpenACCSetConstruct * Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses)
static OpenACCShutdownConstruct * Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses)
static OpenACCUpdateConstruct * Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses)
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)
a trap message and trap category.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const ConstantArrayType * getAsConstantArrayType(QualType T) const
unsigned getIntWidth(QualType T) const
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
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.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
QualType getElementType() const
StringRef getOpcodeStr() const
static CXXBoolLiteralExpr * Create(const ASTContext &C, bool Val, QualType Ty, SourceLocation Loc)
Represents a C++ conversion function within a class.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
void addDecl(Decl *D)
Add the declaration D into this context.
bool isSingleDecl() const
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl.
const Decl * getSingleDecl() const
Decl - This represents one declaration (or definition), e.g.
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
bool isInvalidDecl() const
SourceLocation getLocation() const
DeclContext * getDeclContext()
SourceLocation getBeginLoc() const LLVM_READONLY
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
The name of a declaration.
bool isIdentifier() const
Predicate functions for querying what type of name this is.
SourceLocation getBeginLoc() const LLVM_READONLY
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,...
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.
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...
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Represents difference between two FPOptions values.
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Represents a function declaration or definition.
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool isDeleted() const
Whether this function has been deleted.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Describes an C or C++ initializer list.
Describes the kind of initialization being performed, along with location information for tokens rela...
static InitializationKind CreateDefault(SourceLocation InitLoc)
Create a default initialization.
static InitializationKind CreateForInit(SourceLocation Loc, bool DirectInit, Expr *Init)
Create an initialization from an initializer (which, for direct initialization from a parenthesized l...
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
Describes the sequence of initializations required to initialize a given object or reference with a s...
ExprResult Perform(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType *ResultType=nullptr)
Perform the actual initialization of the given entity based on the computed initialization sequence.
Describes an entity that is being initialized.
static InitializedEntity InitializeElement(ASTContext &Context, unsigned Index, const InitializedEntity &Parent)
Create the initialization entity for an array element.
static InitializedEntity InitializeVariable(VarDecl *Var)
Create the initialization entity for a variable.
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
This represents a decl that may have a name.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
A C++ nested-name-specifier augmented with source location information.
static OpaquePtr make(DeclGroupRef P)
static OpenACCAsteriskSizeExpr * Create(const ASTContext &C, SourceLocation Loc)
SourceLocation getBeginLoc() const
Represents a 'collapse' clause on a 'loop' construct.
const Expr * getLoopCount() const
static OpenACCDeclareDecl * Create(ASTContext &Ctx, DeclContext *DC, SourceLocation StartLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< const OpenACCClause * > Clauses)
static OpenACCRoutineDecl * Create(ASTContext &Ctx, DeclContext *DC, SourceLocation StartLoc, SourceLocation DirLoc, SourceLocation LParenLoc, Expr *FuncRef, SourceLocation RParenLoc, SourceLocation EndLoc, ArrayRef< const OpenACCClause * > Clauses)
const Expr * getFunctionReference() const
ArrayRef< Expr * > getSizeExprs() const
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 getCanonicalType() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
field_range fields() const
Base for LValueReferenceType and RValueReferenceType.
Scope - A scope is a transient data structure that is used while parsing the program.
unsigned getDepth() const
Returns the depth of this scope. The translation-unit has scope depth 0.
bool isOpenACCLoopConstructScope() const
bool isDeclScope(const Decl *D) const
isDeclScope - Return true if this is the scope that the specified decl is declared in.
const Scope * getParent() const
getParent - Return the scope that this is nested in.
A generic diagnostic builder for errors which may or may not be deferred.
ASTContext & getASTContext() const
const LangOptions & getLangOpts() const
DeclContext * getCurContext() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
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)
ExprResult ActOnRoutineName(Expr *RoutineName)
OpenACCPrivateRecipe CreatePrivateInitRecipe(const Expr *VarExpr)
bool ActOnStartDeclDirective(OpenACCDirectiveKind K, SourceLocation StartLoc, ArrayRef< const OpenACCClause * > Clauses)
Called after the directive, including its clauses, have been parsed and parsing has consumed the 'ann...
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 ActOnVariableDeclarator(VarDecl *VD)
Function called when a variable declarator is created, which lets us implement the 'routine' 'functio...
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)...
DeclGroupRef ActOnEndRoutineDeclDirective(SourceLocation StartLoc, SourceLocation DirLoc, SourceLocation LParenLoc, Expr *ReferencedFunc, SourceLocation RParenLoc, ArrayRef< const OpenACCClause * > Clauses, SourceLocation EndLoc, DeclGroupPtrTy NextDecl)
void ActOnInvalidParseVar()
Called only if the parse of a 'var' was invalid, else 'ActOnVar' should be called.
void CheckRoutineDecl(SourceLocation DirLoc, ArrayRef< const OpenACCClause * > Clauses, Decl *NextParsedDecl)
void ActOnEndOfTranslationUnit(TranslationUnitDecl *TU)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
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
StmtResult ActOnEndRoutineStmtDirective(SourceLocation StartLoc, SourceLocation DirLoc, SourceLocation LParenLoc, Expr *ReferencedFunc, SourceLocation RParenLoc, ArrayRef< const OpenACCClause * > Clauses, SourceLocation EndLoc, Stmt *NextStmt)
void CheckDeclReference(SourceLocation Loc, Expr *E, Decl *D)
StmtResult ActOnAssociatedStmt(SourceLocation DirectiveLoc, OpenACCDirectiveKind K, OpenACCAtomicKind AtKind, ArrayRef< const OpenACCClause * > Clauses, StmtResult AssocStmt)
Called when we encounter an associated statement for our construct, this should check legality of the...
OpenACCRoutineDeclAttr * mergeRoutineDeclAttr(const OpenACCRoutineDeclAttr &Old)
void ActOnFunctionDeclarator(FunctionDecl *FD)
Called when a function decl is created, which lets us implement the 'routine' 'doesn't match next thi...
ExprResult ActOnCacheVar(Expr *VarExpr)
Helper function called by ActonVar that is used to check a 'cache' var.
struct clang::SemaOpenACC::LoopWithoutSeqCheckingInfo LoopWithoutSeqInfo
DeclGroupRef ActOnEndDeclDirective(OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation DirLoc, SourceLocation LParenLoc, SourceLocation RParenLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
Called after the directive has been completely parsed, including the declaration group or associated ...
SourceLocation LoopVectorClauseLoc
If there is a current 'active' loop construct with a 'vector' clause on it (on any sort of construct)...
ExprResult ActOnVar(OpenACCDirectiveKind DK, OpenACCClauseKind CK, Expr *VarExpr)
Called when encountering a 'var' for OpenACC, ensures it is actually a declaration reference to a var...
void ActOnConstruct(OpenACCDirectiveKind K, SourceLocation DirLoc)
Called after the construct has been parsed, but clauses haven't been parsed.
ExprResult ActOnOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc)
void ActOnDoStmt(SourceLocation DoLoc)
void ActOnVariableInit(VarDecl *VD, QualType InitType)
Called when a variable is initialized, so we can implement the 'routine 'doesn't match the next thing...
void ActOnRangeForStmtBegin(SourceLocation ForLoc, const Stmt *OldRangeFor, const Stmt *RangeFor)
void ActOnStartParseVar(OpenACCDirectiveKind DK, OpenACCClauseKind CK)
Called right before a 'var' is parsed, so we can set the state for parsing a 'cache' var.
OpenACCFirstPrivateRecipe CreateFirstPrivateInitRecipe(const Expr *VarExpr)
StmtResult ActOnEndStmtDirective(OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation DirLoc, SourceLocation LParenLoc, SourceLocation MiscLoc, ArrayRef< Expr * > Exprs, OpenACCAtomicKind AK, SourceLocation RParenLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult AssocStmt)
Called after the directive has been completely parsed, including the declaration group or associated ...
void ActOnForStmtEnd(SourceLocation ForLoc, StmtResult Body)
StmtResult CheckAtomicAssociatedStmt(SourceLocation AtomicDirLoc, OpenACCAtomicKind AtKind, StmtResult AssocStmt)
Called to check the form of the atomic construct which has some fairly sizable restrictions.
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.
OpenACCReductionRecipeWithStorage CreateReductionInitRecipe(OpenACCReductionOperator ReductionOperator, const Expr *VarExpr)
CXXMethodDecl * getMethod() const
RAII class used to indicate that we are performing provisional semantic analysis to determine the val...
Sema - This implements semantic analysis and AST building for C.
@ Normal
Apply the normal rules for complete types.
@ 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.
SourceManager & SourceMgr
SpecialMemberOverloadResult LookupSpecialMember(CXXRecordDecl *D, CXXSpecialMemberKind SM, bool ConstArg, bool VolatileArg, bool RValueThis, bool ConstThis, bool VolatileThis)
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
unsigned getSpellingLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
SourceLocation getEnd() const
SourceLocation getBegin() const
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
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
The top declaration context.
bool isDependentSizedArrayType() const
bool isBlockPointerType() const
bool isBooleanType() const
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isConstantArrayType() const
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
bool isEnumeralType() const
bool isScalarType() 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...
bool isFixedPointType() const
Return true if this is a fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isFunctionType() const
bool isObjCObjectPointerType() const
bool isFloatingType() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isNullPtrType() const
bool isRecordType() const
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.
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
void setInitStyle(InitializationStyle Style)
@ CallInit
Call-style initialization (C++98)
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
SmallVector< BoundNodes, 1 > match(MatcherT Matcher, const NodeT &Node, ASTContext &Context)
Returns the results of matching Matcher on Node.
Top level wrappers for InstallAPI frontend operations.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ Invalid
Invalid Reduction Clause Kind.
bool isa(CodeGen::Address addr)
@ Conditional
A conditional (?:) operator.
@ OK_Ordinary
An ordinary object is located at an address in memory.
OpenACCClauseKind
Represents the kind of an OpenACC clause.
@ Collapse
'collapse' clause, allowed on 'loop' and Combined constructs.
@ Private
'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel loop', and 'serial loop' constru...
@ Invalid
Represents an invalid clause, for the purposes of parsing.
@ UseDevice
'use_device' clause, allowed on 'host_data' construct.
@ Reduction
'reduction' clause, allowed on Parallel, Serial, Loop, and the combined constructs.
@ FirstPrivate
'firstprivate' clause, allowed on 'parallel', 'serial', 'parallel loop', and 'serial loop' constructs...
@ Tile
'tile' clause, allowed on 'loop' and Combined constructs.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ Result
The result type of a method or function.
const FunctionProtoType * T
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
U cast(CodeGen::Address addr)
ActionResult< Expr * > ExprResult
ActionResult< Stmt * > StmtResult
@ NOUR_None
This is an odr-use.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
EvalResult is a struct with detailed info about an evaluated expression.
APValue Val
Val - This is the value the expression can be folded to.
static OpenACCFirstPrivateRecipe Empty()
static OpenACCPrivateRecipe Empty()
static OpenACCReductionRecipeWithStorage Empty()