Lines Matching +full:cs +full:- +full:extra +full:- +full:delay
1 //===--- SemaOpenMP.cpp - Semantic Analysis for OpenMP constructs ---------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
55 //===----------------------------------------------------------------------===//
56 // Stack of data-sharing attributes for variables
57 //===----------------------------------------------------------------------===//
75 /// clauses and their data-sharing attributes.
102 /// User-defined allocator
180 /// get the data (loop counters etc.) about enclosing loop-based construct.
238 /// Stack of used declaration and their data-sharing attributes.
281 : Stack.back().first.size() - IgnoredStackElements;
288 return &Stack.back().first[Size - 1];
305 return &Stack.back().first[Size - 2];
388 return Top && Top->BodyComplete;
417 "Data-sharing attributes stack is empty!");
436 --Self.IgnoredStackElements;
451 "Expected loop-based directive.");
457 "Expected loop-based directive.");
463 "Expected loop-based directive.");
468 getTopOfStack().PossiblyLoopCounter = D ? D->getCanonicalDecl() : D;
474 /// Start new OpenMP region stack in new non-capturing function.
482 /// Pop region stack for non-capturing function.
500 Criticals.try_emplace(D->getDirectiveName().getAsString(), D, Hint);
506 return I->second;
523 /// for-loops (from outer to inner).
528 /// for-loops (from outer to inner).
533 /// for-loops (from outer to inner).
536 /// Get the loop control variable for the I-th loop (or nullptr) in
543 Stack->UsedInScanDirective.insert(D);
549 return Stack->UsedInScanDirective.contains(D);
594 ->getDecl() == VD;
600 /// Returns data-sharing attributes for the specified declaration.
602 /// Returns data-sharing attributes for the specified declaration.
604 /// Checks if the specified variables has data-sharing attributes which
614 /// Checks if the specified variables has data-sharing attributes which
622 /// Checks if the specified variables has explicit data-sharing
646 return Top ? Top->Directive : OMPD_unknown;
650 return Top ? Top->MappedDirective : OMPD_unknown;
657 Top->Directive = NewDK;
664 Top->MappedDirective = NewDK;
681 return Parent ? Parent->Directive : OMPD_unknown;
690 return llvm::any_of(D->clauselists(), [](const OMPClause *C) {
702 for (const OMPClause *CPrev : D->clauselists()) {
703 if (CNew->getClauseKind() == CPrev->getClauseKind()) {
704 SemaRef.Diag(CNew->getBeginLoc(),
706 << getOpenMPClauseName(CNew->getClauseKind());
707 SemaRef.Diag(CPrev->getBeginLoc(),
709 << getOpenMPClauseName(CPrev->getClauseKind());
765 /// Check whether the implicit-behavior has been set in defaultmap
871 /// false - otherwise.
874 return Top->OrderedRegion.has_value();
880 if (Top->OrderedRegion)
881 return *Top->OrderedRegion;
885 /// 'ordered' clause), false - otherwise.
888 return Parent->OrderedRegion.has_value();
895 if (Parent->OrderedRegion)
896 return *Parent->OrderedRegion;
904 /// 'order' clause), false - otherwise.
907 return Parent->RegionHasOrderConcurrent;
915 /// 'nowait' clause), false - otherwise.
918 return Parent->NowaitRegion;
928 return Top ? Top->UntiedRegion : false;
933 Parent->CancelRegion |= Cancel;
938 return Top ? Top->CancelRegion : false;
944 Parent->PrevScanLocation = Loc;
949 return Top ? Top->PrevScanLocation.isValid() : false;
954 return Top ? Top->PrevScanLocation : SourceLocation();
959 Parent->PrevOrderedLocation = Loc;
964 return Top ? Top->PrevOrderedLocation.isValid() : false;
969 return Top ? Top->PrevOrderedLocation : SourceLocation();
981 return Top ? Top->AssociatedLoops : 0;
986 return Top ? Top->HasMutipleLoops : false;
993 Parent->InnerTeamsRegionLoc = TeamsRegionLoc;
1002 return Top ? Top->InnerTeamsRegionLoc : SourceLocation();
1007 return Top ? Top->CurScope : nullptr;
1012 return Top ? Top->ConstructLoc : SourceLocation();
1037 auto MI = SI->MappedExprComponents.find(VD);
1038 if (MI != SI->MappedExprComponents.end())
1040 MI->second.Components)
1041 if (Check(L, MI->second.Kind))
1062 MI->second.Components)
1063 if (Check(L, MI->second.Kind))
1083 return getStackSize() - 1;
1087 assert(Parent && isOpenMPWorksharingDirective(Parent->Directive));
1088 Parent->DoacrossDepends.try_emplace(C, OpsOffs);
1116 E->getDecl()) == OMPDeclareTargetDeclAttr::MT_Link &&
1142 /// Marks the declaration as implicitly firstprivate nin the task-based
1147 /// Checks if the decl is implicitly firstprivate in the task-based region.
1164 return I->getSecond();
1172 return I->getSecond();
1181 return Top ? Top->DeclareMapperVar : nullptr;
1187 StackElem.IteratorVarDecls.push_back(VD->getCanonicalDecl());
1195 return llvm::is_contained(Top->IteratorVarDecls, VD->getCanonicalDecl());
1203 if (I->DefaultAttr == DSA_firstprivate || I->DefaultAttr == DSA_private)
1205 StackLevel--;
1210 for (const auto &IFD : I->ImplicitDefaultFirstprivateFDs)
1220 if (I->DefaultAttr == DSA_firstprivate || I->DefaultAttr == DSA_private)
1224 for (const auto &IFD : I->ImplicitDefaultFirstprivateFDs)
1235 if (I->DefaultAttr == DSA_private || I->DefaultAttr == DSA_firstprivate) {
1236 I->ImplicitDefaultFirstprivateFDs.emplace_back(FD, StackLevel, VD);
1239 StackLevel--;
1258 E = FE->getSubExpr();
1261 E = MTE->getSubExpr();
1264 E = Binder->getSubExpr();
1267 E = ICE->getSubExprAsWritten();
1268 return E->IgnoreParens();
1277 if (const auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit())))
1278 D = ME->getMemberDecl();
1282 VD = VD->getCanonicalDecl();
1286 FD = FD->getCanonicalDecl();
1304 // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
1306 // File-scope or namespace-scope variables referenced in called routines
1309 if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(VD))
1312 // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced
1316 if (VD && VD->hasGlobalStorage())
1319 // Non-static data members are shared by default.
1326 // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
1330 if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() &&
1331 (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) {
1336 DVar.DKind = Iter->Directive;
1339 if (Iter->SharingMap.count(D)) {
1340 const DSAInfo &Data = Iter->SharingMap.lookup(D);
1344 DVar.ImplicitDSALoc = Iter->DefaultAttrLoc;
1350 // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
1352 // In a parallel or task construct, the data-sharing attributes of these
1354 switch (Iter->DefaultAttr) {
1357 DVar.ImplicitDSALoc = Iter->DefaultAttrLoc;
1362 if (VD && VD->getStorageDuration() == SD_Static &&
1363 VD->getDeclContext()->isFileContext()) {
1368 DVar.ImplicitDSALoc = Iter->DefaultAttrLoc;
1373 // and that does not have a predetermined data-sharing attribute
1374 if (VD && VD->getStorageDuration() == SD_Static &&
1375 VD->getDeclContext()->isFileContext()) {
1380 DVar.ImplicitDSALoc = Iter->DefaultAttrLoc;
1383 // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
1387 DVar.ImplicitDSALoc = Iter->DefaultAttrLoc;
1395 // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
1405 // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables
1408 // whose data-sharing attribute is not determined by the rules above is
1416 } while (I != E && !isImplicitTaskingRegion(I->Directive));
1422 // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
1425 // variables inherit their data-sharing attributes from the enclosing
1441 assert(It->second && "Unexpected nullptr expr in the aligned map");
1442 return It->second;
1456 assert(It->second && "Unexpected nullptr expr in the aligned map");
1457 return It->second;
1461 assert(!isStackEmpty() && "Data-sharing attributes stack is empty");
1470 assert(!isStackEmpty() && "Data-sharing attributes stack is empty");
1475 return It->second;
1481 assert(!isStackEmpty() && "Data-sharing attributes stack is empty");
1483 for (unsigned I = Level + 1; I > 0; --I) {
1484 const SharingMapTy &StackElem = getStackElemAtLevel(I - 1);
1487 return It->second;
1495 assert(Parent && "Data-sharing attributes stack is empty");
1497 auto It = Parent->LCVMap.find(D);
1498 if (It != Parent->LCVMap.end())
1499 return It->second;
1505 assert(Parent && "Data-sharing attributes stack is empty");
1506 if (Parent->LCVMap.size() < I)
1508 for (const auto &Pair : Parent->LCVMap)
1542 DSAInfo &Data = getTopOfStack().SharingMap[PrivateCopy->getDecl()];
1562 for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end());
1564 Decl->addAttr(*I);
1566 Decl->setImplicit();
1568 Decl->addAttr(
1577 D->setReferenced();
1578 D->markUsed(S.Context);
1587 assert(!isStackEmpty() && "Data-sharing attributes stack is empty");
1612 assert(!isStackEmpty() && "Data-sharing attributes stack is empty");
1638 assert(!isStackEmpty() && "Data-sharing attributes stack is empty.");
1640 const DSAInfo &Data = I->SharingMap.lookup(D);
1644 const ReductionData &ReductionData = I->ReductionMap.lookup(D);
1650 assert(I->TaskgroupReductionRef && "taskgroup reduction reference "
1653 TaskgroupDescriptor = I->TaskgroupReductionRef;
1654 return DSAVarData(I->Directive, OMPC_reduction, Data.RefExpr.getPointer(),
1655 Data.PrivateCopy, I->DefaultAttrLoc, OMPC_REDUCTION_task,
1665 assert(!isStackEmpty() && "Data-sharing attributes stack is empty.");
1667 const DSAInfo &Data = I->SharingMap.lookup(D);
1671 const ReductionData &ReductionData = I->ReductionMap.lookup(D);
1677 assert(I->TaskgroupReductionRef && "taskgroup reduction reference "
1680 TaskgroupDescriptor = I->TaskgroupReductionRef;
1681 return DSAVarData(I->Directive, OMPC_reduction, Data.RefExpr.getPointer(),
1682 Data.PrivateCopy, I->DefaultAttrLoc, OMPC_REDUCTION_task,
1689 D = D->getCanonicalDecl();
1691 if (isImplicitOrExplicitTaskingRegion(I->Directive) ||
1692 isOpenMPTargetExecutionDirective(I->Directive)) {
1693 if (I->CurScope) {
1694 Scope *TopScope = I->CurScope->getParent();
1696 while (CurScope && CurScope != TopScope && !CurScope->isDeclScope(D))
1697 CurScope = CurScope->getParent();
1700 for (DeclContext *DC = D->getDeclContext(); DC; DC = DC->getParent())
1701 if (I->Context == DC)
1717 ? Type->getAsCXXRecordDecl()
1720 if (const ClassTemplateDecl *CTD = CTSD->getSpecializedTemplate())
1721 RD = CTD->getTemplatedDecl();
1725 RD->hasDefinition() && RD->hasMutableFields());
1742 bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) ==
1744 SemaRef.Diag(D->getLocation(),
1761 DVar.RefExpr = TI->getSecond().RefExpr.getPointer();
1763 DVar.Modifier = TI->getSecond().Modifier;
1766 if (VD && VD->hasAttr<OMPThreadPrivateDeclAttr>()) {
1768 SemaRef, VD, D->getType().getNonReferenceType(),
1769 VD->getAttr<OMPThreadPrivateDeclAttr>()->getLocation());
1774 // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
1777 if ((VD && VD->getTLSKind() != VarDecl::TLS_None &&
1778 !(VD->hasAttr<OMPThreadPrivateDeclAttr>() &&
1781 (VD && VD->getStorageClass() == SC_Register &&
1782 VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) {
1784 SemaRef, VD, D->getType().getNonReferenceType(), D->getLocation());
1790 VD->isLocalVarDeclOrParm() && !isStackEmpty() &&
1801 buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(),
1802 D->getLocation());
1808 auto DSAIter = IterTarget->SharingMap.find(D);
1809 if (DSAIter != IterTarget->SharingMap.end() &&
1810 isOpenMPPrivate(DSAIter->getSecond().Attributes)) {
1811 DVar.RefExpr = DSAIter->getSecond().RefExpr.getPointer();
1820 buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(),
1821 IterTarget->ConstructLoc);
1833 // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
1836 // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
1840 if (VD && VD->isStaticDataMember()) {
1847 auto It = I->SharingMap.find(D);
1848 if (It != I->SharingMap.end()) {
1849 const DSAInfo &Data = It->getSecond();
1853 DVar.ImplicitDSALoc = I->DefaultAttrLoc;
1854 DVar.DKind = I->Directive;
1866 // The predetermined shared attribute for const-qualified types having no
1869 // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
1873 if (isConstNotMutableType(SemaRef, D->getType())) {
1874 // Variables with const-qualified type having no mutable member may be
1898 auto It = I->SharingMap.find(D);
1899 if (It != I->SharingMap.end()) {
1900 const DSAInfo &Data = It->getSecond();
1904 DVar.ImplicitDSALoc = I->DefaultAttrLoc;
1905 DVar.DKind = I->Directive;
1932 const_iterator StartI = std::next(begin(), getStackSize() - 1 - Level);
1951 if (!DPred(I->Directive) &&
1952 !isImplicitOrExplicitTaskingRegion(I->Directive))
1956 if (I == NewI && CPred(DVar.CKind, DVar.AppliedToPointee, I->DefaultAttr))
1973 if (StartI == EndI || !DPred(StartI->Directive))
1991 if (I != StackElem.SharingMap.end() && I->getSecond().RefExpr.getPointer() &&
1992 CPred(I->getSecond().Attributes, I->getSecond().AppliedToPointee) &&
1993 (!NotLastprivate || !I->getSecond().RefExpr.getInt()))
2020 if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc))
2032 void SemaOpenMP::pushOpenMPFunctionRegion() { DSAStack->pushFunction(); }
2035 DSAStack->popFunction(OldFSI);
2067 // TODO: We should always delay diagnostics here in case a target
2121 if (VD->getType().getNonReferenceType()->isScalarType())
2125 if (VD->getType().getNonReferenceType()->isAnyPointerType())
2127 if (VD->getType().getNonReferenceType()->isScalarType())
2140 D = cast<ValueDecl>(D->getCanonicalDecl());
2141 QualType Ty = D->getType();
2144 if (DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, Level)) {
2148 // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses].
2154 // | scl | | | | - | | bycopy|
2155 // | scl | | - | x | - | - | bycopy|
2156 // | scl | | x | - | - | - | null |
2157 // | scl | x | | | - | | byref |
2158 // | scl | x | - | x | - | - | bycopy|
2159 // | scl | x | x | - | - | - | null |
2160 // | scl | | - | - | - | x | byref |
2161 // | scl | x | - | - | - | x | byref |
2163 // | agg | n.a. | | | - | | byref |
2164 // | agg | n.a. | - | x | - | - | byref |
2165 // | agg | n.a. | x | - | - | - | null |
2166 // | agg | n.a. | - | - | - | x | byref |
2167 // | agg | n.a. | - | - | - | x[] | byref |
2169 // | ptr | n.a. | | | - | | bycopy|
2170 // | ptr | n.a. | - | x | - | - | bycopy|
2171 // | ptr | n.a. | x | - | - | - | null |
2172 // | ptr | n.a. | - | - | - | x | byref |
2173 // | ptr | n.a. | - | - | - | x[] | bycopy|
2174 // | ptr | n.a. | - | - | x | | bycopy|
2175 // | ptr | n.a. | - | - | x | x | bycopy|
2176 // | ptr | n.a. | - | - | x | x[] | bycopy|
2179 // scl - scalar
2180 // ptr - pointer
2181 // agg - aggregate
2182 // x - applies
2183 // - - invalid in this combination
2184 // [] - mapped with an array section
2185 // byref - should be mapped by reference
2186 // byval - should be mapped by value
2187 // null - initialize a local variable to null on the device
2190 // - All scalar declarations that show up in a map clause have to be passed
2193 // - If the scalar value does not fit the size of uintptr, it has to be
2195 // - For pointers mapped by value that have either an implicit map or an
2199 if (Ty->isReferenceType())
2200 Ty = Ty->castAs<ReferenceType>()->getPointeeType();
2207 DSAStack->checkMappableExprComponentListsForDeclAtLevel(
2225 if (isa<DeclRefExpr>(EI->getAssociatedExpression()))
2226 IsVariableUsedInMapClause |= EI->getAssociatedDeclaration() == D;
2233 dyn_cast<UnaryOperator>(Last->getAssociatedExpression());
2234 if ((UO && UO->getOpcode() == UO_Deref) ||
2235 isa<ArraySubscriptExpr>(Last->getAssociatedExpression()) ||
2236 isa<ArraySectionExpr>(Last->getAssociatedExpression()) ||
2237 isa<MemberExpr>(EI->getAssociatedExpression()) ||
2238 isa<OMPArrayShapingExpr>(Last->getAssociatedExpression())) {
2251 IsByRef = !(Ty->isPointerType() && IsVariableAssociatedWithSection);
2256 IsByRef = (DSAStack->isForceCaptureByReferenceInTargetExecutable() &&
2257 !Ty->isAnyPointerType()) ||
2258 !Ty->isScalarType() ||
2259 DSAStack->isDefaultmapCapturedByRef(
2261 DSAStack->hasExplicitDSA(
2270 if (IsByRef && Ty.getNonReferenceType()->isScalarType()) {
2273 DSAStack->getCaptureRegion(Level, OpenMPCaptureLevel) ==
2275 !(DSAStack->hasExplicitDSA(
2277 [](OpenMPClauseKind K, bool AppliedToPointee) -> bool {
2282 DSAStack->isUsesAllocatorsDecl(Level, D))) &&
2283 // If the variable is artificial and must be captured by value - try to
2285 !(isa<OMPCapturedExprDecl>(D) && !D->hasAttr<OMPCaptureNoInitAttr>() &&
2286 !cast<OMPCapturedExprDecl>(D)->getInit()->isGLValue()) &&
2287 // If the variable is implicitly firstprivate and scalar - capture by
2289 !((DSAStack->getDefaultDSA() == DSA_firstprivate ||
2290 DSAStack->getDefaultDSA() == DSA_private) &&
2291 !DSAStack->hasExplicitDSA(
2294 !DSAStack->isLoopControlVariable(D, Level).first);
2313 return DSAStack->getNestingLevel();
2317 return isOpenMPTaskingDirective(DSAStack->getCurrentDirective()) &&
2318 DSAStack->isUntiedRegion();
2322 return (isOpenMPTargetExecutionDirective(DSAStack->getCurrentDirective()) &&
2323 !DSAStack->isClauseParsingMode()) ||
2324 DSAStack->hasDirective(
2326 SourceLocation) -> bool {
2336 DSAStackTy::DSAVarData DVarPrivate = DSAStack->hasDSA(
2344 DSAStack->isClauseParsingMode());
2362 if (VD && VD->isConstexpr())
2370 *DSAStack, CheckScopeInfo && DSAStack->isBodyComplete());
2375 if (VD && !VD->hasLocalStorage() &&
2380 DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode());
2391 CheckScopeInfo ? (SemaRef.FunctionScopes.size() - (StopAt + 1))
2396 if (RSI->CapRegionKind == CR_OpenMP) {
2404 DSAStack->getDirective(CSI->OpenMPLevel));
2405 if (Regions[CSI->OpenMPCaptureLevel] != OMPD_task)
2420 for (unsigned I = StopAt + 1; I > 0; --I) {
2421 FunctionScopeInfo *FSI = SemaRef.FunctionScopes[I - 1];
2425 if (RSI->CapRegionKind == CR_OpenMP) {
2434 if (DSAStack->getCurrentDirective() != OMPD_unknown &&
2435 (!DSAStack->isClauseParsingMode() ||
2436 DSAStack->getParentDirective() != OMPD_unknown)) {
2437 auto &&Info = DSAStack->isLoopControlVariable(D);
2439 (VD && VD->hasLocalStorage() &&
2440 isImplicitOrExplicitTaskingRegion(DSAStack->getCurrentDirective())) ||
2441 (VD && DSAStack->isForceVarCapturing()))
2444 DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode());
2446 (!VD || VD->hasLocalStorage() || !DVarTop.AppliedToPointee))
2447 return VD ? VD : cast<VarDecl>(DVarTop.PrivateCopy->getDecl());
2453 DSAStackTy::DSAVarData DVarPrivate = DSAStack->hasDSA(
2459 DSAStack->isClauseParsingMode());
2461 if (VD && !VD->hasLocalStorage() && DVarPrivate.CKind == OMPC_unknown &&
2462 ((DSAStack->getDefaultDSA() != DSA_none &&
2463 DSAStack->getDefaultDSA() != DSA_private &&
2464 DSAStack->getDefaultDSA() != DSA_firstprivate) ||
2470 DSAStackTy::DSAVarData DVarPrivate = DSAStack->hasDSA(
2479 DSAStack->isClauseParsingMode());
2483 VarDecl *VD = DSAStack->getImplicitFDCapExprDecl(FD);
2491 const CXXScopeSpec CS = CXXScopeSpec();
2495 DeclAccessPair::make(FD, FD->getAccess()),
2496 /*HadMultipleCandidates=*/false, DeclarationNameInfo(), FD->getType(),
2499 SemaRef, FD->getIdentifier(), ME, DVarPrivate.CKind != OMPC_private,
2500 SemaRef.CurContext->getParent(), /*AsExpression=*/false);
2502 SemaRef, CD, CD->getType().getNonReferenceType(), SourceLocation());
2503 VD = cast<VarDecl>(VDPrivateRefExpr->getDecl());
2504 DSAStack->addImplicitDefaultFirstprivateFD(FD, VD);
2508 (VD && (DSAStack->getDefaultDSA() == DSA_none ||
2509 DSAStack->getDefaultDSA() == DSA_private ||
2510 DSAStack->getDefaultDSA() == DSA_firstprivate)))
2511 return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl());
2518 FunctionScopesIndex -= getOpenMPCaptureLevels(DSAStack->getDirective(Level));
2523 if (isOpenMPLoopDirective(DSAStack->getCurrentDirective()))
2524 DSAStack->loopInit();
2529 if (isOpenMPLoopDirective(DSAStack->getCurrentDirective())) {
2530 DSAStack->resetPossibleLoopCounter();
2531 DSAStack->loopStart();
2538 if (DSAStack->getCurrentDirective() != OMPD_unknown &&
2539 (!DSAStack->isClauseParsingMode() ||
2540 DSAStack->getParentDirective() != OMPD_unknown)) {
2541 DSAStackTy::DSAVarData DVarPrivate = DSAStack->hasDSA(
2549 DSAStack->isClauseParsingMode());
2551 DSAStack->isImplicitDefaultFirstprivateFD(cast<VarDecl>(D)) &&
2552 !DSAStack->isLoopControlVariable(D).first)
2555 if (DSAStack->hasExplicitDirective(isOpenMPTaskingDirective, Level)) {
2557 D->getType().getNonReferenceType().isTriviallyCopyableType(
2559 !D->getType()
2562 ->getAsCXXRecordDecl();
2563 OpenMPDirectiveKind DKind = DSAStack->getDirective(Level);
2569 if (DSAStack->hasExplicitDSA(
2574 DSAStackTy::DSAVarData DVar = DSAStack->getImplicitDSA(D, Level);
2576 !DSAStack->isLoopControlVariable(D, Level).first && !DVar.RefExpr) {
2577 DSAStack->addImplicitTaskFirstprivate(Level, D);
2582 if (isOpenMPLoopDirective(DSAStack->getCurrentDirective()) &&
2583 !isOpenMPLoopTransformationDirective(DSAStack->getCurrentDirective())) {
2584 if (DSAStack->getAssociatedLoops() > 0 && !DSAStack->isLoopStarted()) {
2585 DSAStack->resetPossibleLoopCounter(D);
2586 DSAStack->loopStart();
2589 if ((DSAStack->getPossiblyLoopCounter() == D->getCanonicalDecl() ||
2590 DSAStack->isLoopControlVariable(D).first) &&
2591 !DSAStack->hasExplicitDSA(
2594 !isOpenMPSimdDirective(DSAStack->getCurrentDirective()))
2598 if (DSAStack->isThreadPrivate(const_cast<VarDecl *>(VD)) &&
2599 DSAStack->isForceVarCapturing() &&
2600 !DSAStack->hasExplicitDSA(
2605 // User-defined allocators are private since they must be defined in the
2607 if (DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, Level) &&
2608 DSAStack->isUsesAllocatorsDecl(Level, D).value_or(
2612 return (DSAStack->hasExplicitDSA(
2615 (DSAStack->isClauseParsingMode() &&
2616 DSAStack->getClauseParsingMode() == OMPC_private) ||
2619 (DSAStack->hasExplicitDirective(
2627 DSAStack->isTaskgroupReductionRef(D, Level)))
2637 for (unsigned I = DSAStack->getNestingLevel() + 1; I > Level; --I) {
2638 const unsigned NewLevel = I - 1;
2639 if (DSAStack->hasExplicitDSA(
2650 if (DSAStack->checkMappableExprComponentListsForDeclAtLevel(
2657 if (DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective,
2660 if (DSAStack->mustBeFirstprivateAtLevel(
2667 FD->addAttr(
2677 getOpenMPCaptureRegions(Regions, DSAStack->getDirective(Level));
2679 return VD && !VD->hasLocalStorage() &&
2680 DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective,
2691 if (!VD->hasLocalStorage()) {
2695 DSAStack->getTopDSA(D, /*FromParent=*/false);
2697 getOpenMPCaptureLevels(DSAStack->getDirective(Level));
2699 // non-file scope static variable with default(firstprivate)
2703 DSAStack->getDefaultDSA() == DSA_firstprivate));
2705 --Level;
2706 DSAStackTy::DSAVarData DVar = DSAStack->getImplicitDSA(D, Level);
2734 OMPDeclareTargetDeclAttr::getDeviceType(Caller->getMostRecentDecl());
2743 const FunctionDecl *FD = Callee->getMostRecentDecl();
2763 Callee->specific_attrs<OMPDeclareVariantAttr>()) {
2764 auto *DeclRefVariant = cast<DeclRefExpr>(A->getVariantFuncRef());
2765 auto *VariantFD = cast<FunctionDecl>(DeclRefVariant->getDecl());
2768 VariantFD->getMostRecentDecl());
2775 Callee->hasAttr<OMPDeclareVariantAttr>() && HasHostAttr(Callee))
2790 DSAStack->push(DKind, DirName, CurScope, Loc);
2796 DSAStack->setClauseParsingMode(K);
2800 DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown);
2815 // A reduction clause without the inscan reduction-modifier may not appear on
2816 // a construct on which a reduction clause with the inscan reduction-modifier
2819 if (C->getClauseKind() != OMPC_reduction)
2822 if (RC->getModifier() == OMPC_REDUCTION_inscan) {
2824 InscanLoc = RC->getModifierLoc();
2827 if (RC->getModifier() == OMPC_REDUCTION_task) {
2829 // A reduction clause with the task reduction-modifier may only appear on
2833 OpenMPDirectiveKind CurDir = Stack->getCurrentDirective();
2837 S.Diag(RC->getModifierLoc(),
2844 if (C->getClauseKind() != OMPC_reduction)
2847 if (RC->getModifier() != OMPC_REDUCTION_inscan) {
2848 S.Diag(RC->getModifier() == OMPC_REDUCTION_unknown
2849 ? RC->getBeginLoc()
2850 : RC->getModifierLoc(),
2855 for (Expr *Ref : RC->varlists()) {
2865 if (!Stack->isUsedInScanDirective(getCanonicalDecl(D))) {
2866 S.Diag(Ref->getExprLoc(),
2868 << Ref->getSourceRange();
2892 for (OMPClause *C : D->clauses()) {
2895 for (Expr *DE : Clause->varlists()) {
2896 if (DE->isValueDependent() || DE->isTypeDependent()) {
2900 auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens());
2901 auto *VD = cast<VarDecl>(DRE->getDecl());
2902 QualType Type = VD->getType().getNonReferenceType();
2904 DSAStack->getTopDSA(VD, /*FromParent=*/false);
2912 SemaRef, DE->getExprLoc(), Type.getUnqualifiedType(),
2913 VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr, DRE);
2915 if (VDPrivate->isInvalidDecl()) {
2920 SemaRef, VDPrivate, DE->getType(), DE->getExprLoc()));
2927 Clause->setPrivateCopies(PrivateCopies);
2933 for (Expr *RefExpr : Clause->varlists()) {
2947 DSAStack->getTopDSA(D, /*FromParent=*/false);
2951 Clause->setPrivateRefs(PrivateRefs);
2955 for (unsigned I = 0, E = Clause->getNumberOfAllocators(); I < E; ++I) {
2956 OMPUsesAllocatorsClause::Data D = Clause->getAllocatorData(I);
2957 auto *DRE = dyn_cast<DeclRefExpr>(D.Allocator->IgnoreParenImpCasts());
2960 ValueDecl *VD = DRE->getDecl();
2964 DSAStack->getTopDSA(VD, /*FromParent=*/false);
2967 // appear in other data-sharing attribute clauses or data-mapping
2971 DSAStack->checkMappableExprComponentListsForDecl(
2980 MI->getAssociatedDeclaration()->getCanonicalDecl() ==
2981 VD->getCanonicalDecl()) {
2982 MapExpr = MI->getAssociatedExpression();
2987 Diag(D.Allocator->getExprLoc(),
2989 << D.Allocator->getSourceRange();
2993 Diag(MapExpr->getExprLoc(), diag::note_used_here)
2994 << MapExpr->getSourceRange();
3001 if (!SemaRef.CurContext->isDependentContext())
3002 checkAllocateClauses(SemaRef, DSAStack, D->clauses());
3003 checkReductionClauses(SemaRef, DSAStack, D->clauses());
3006 DSAStack->pop();
3018 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
3021 if (SemaRef.CurContext->isDependentContext())
3024 // Finalize the clauses that need pre-built expressions for CodeGen.
3049 return VD->hasGlobalStorage() &&
3069 if (ND && ((isa<VarDecl>(ND) && ND->getKind() == Decl::Var) ||
3117 Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at);
3123 // Variables must be file-scope, namespace-scope, or static block-scope.
3124 if (Kind == OMPD_threadprivate && !VD->hasGlobalStorage()) {
3126 << getOpenMPDirectiveName(Kind) << !VD->isStaticLocal();
3128 VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
3129 Diag(VD->getLocation(),
3135 VarDecl *CanonicalVD = VD->getCanonicalDecl();
3138 // A threadprivate directive for file-scope variables must appear outside
3140 if (CanonicalVD->getDeclContext()->isTranslationUnit() &&
3141 !SemaRef.getCurLexicalContext()->isTranslationUnit()) {
3145 VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
3146 Diag(VD->getLocation(),
3155 if (CanonicalVD->isStaticDataMember() &&
3156 !CanonicalVD->getDeclContext()->Equals(SemaRef.getCurLexicalContext())) {
3160 VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
3161 Diag(VD->getLocation(),
3167 // A threadprivate directive for namespace-scope variables must appear
3170 if (CanonicalVD->getDeclContext()->isNamespace() &&
3171 (!SemaRef.getCurLexicalContext()->isFileContext() ||
3172 !SemaRef.getCurLexicalContext()->Encloses(
3173 CanonicalVD->getDeclContext()))) {
3177 VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
3178 Diag(VD->getLocation(),
3184 // A threadprivate directive for static block-scope variables must appear
3186 if (CanonicalVD->isLocalVarDecl() && CurScope &&
3191 VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
3192 Diag(VD->getLocation(),
3198 // OpenMP [2.9.2, Restrictions, C/C++, p.2-6]
3201 if (Kind == OMPD_threadprivate && VD->isUsed() &&
3202 !DSAStack->isThreadPrivate(VD)) {
3208 QualType ExprType = VD->getType().getNonReferenceType();
3219 SemaRef.CurContext->addDecl(D);
3232 if (const auto *VD = dyn_cast<VarDecl>(E->getDecl())) {
3233 if (VD->hasLocalStorage()) {
3234 SemaRef.Diag(E->getBeginLoc(),
3236 << E->getSourceRange();
3237 SemaRef.Diag(VD->getLocation(), diag::note_defined_here)
3238 << VD << VD->getSourceRange();
3245 for (const Stmt *Child : S->children()) {
3262 auto *VD = cast<VarDecl>(DE->getDecl());
3263 SourceLocation ILoc = DE->getExprLoc();
3266 VD->setReferenced();
3267 VD->markUsed(Context);
3269 QualType QType = VD->getType();
3270 if (QType->isDependentType() || QType->isInstantiationDependentType()) {
3279 ILoc, VD->getType(), diag::err_omp_threadprivate_incomplete_type)) {
3285 if (VD->getType()->isReferenceType()) {
3287 << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType();
3289 VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
3290 Diag(VD->getLocation(),
3298 if ((VD->getTLSKind() != VarDecl::TLS_None &&
3299 !(VD->hasAttr<OMPThreadPrivateDeclAttr>() &&
3302 (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() &&
3303 !VD->isLocalVarDecl())) {
3305 << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1);
3307 VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
3308 Diag(VD->getLocation(),
3316 if (const Expr *Init = VD->getAnyInitializer()) {
3323 DSAStack->addDSA(VD, DE, OMPC_threadprivate);
3324 VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit(
3327 ML->DeclarationMarkedOpenMPThreadPrivate(VD);
3333 D->setAccess(AS_public);
3342 if (Allocator->isTypeDependent() || Allocator->isValueDependent() ||
3343 Allocator->isInstantiationDependent() ||
3344 Allocator->containsUnexpandedParameterPack())
3348 const Expr *AE = Allocator->IgnoreParenImpCasts();
3349 AE->IgnoreImpCasts()->Profile(AEId, S.getASTContext(), /*Canonical=*/true);
3352 const Expr *DefAllocator = Stack->getAllocator(AllocatorKind);
3354 DefAllocator->IgnoreImpCasts()->Profile(DAEId, S.getASTContext(),
3367 if (!VD->hasAttr<OMPAllocateDeclAttr>())
3369 const auto *A = VD->getAttr<OMPAllocateDeclAttr>();
3370 Expr *PrevAllocator = A->getAllocator();
3377 const Expr *AE = Allocator->IgnoreParenImpCasts();
3378 const Expr *PAE = PrevAllocator->IgnoreParenImpCasts();
3380 AE->Profile(AEId, S.Context, /*Canonical=*/true);
3381 PAE->Profile(PAEId, S.Context, /*Canonical=*/true);
3388 Allocator->printPretty(AllocatorStream, nullptr, S.getPrintingPolicy());
3392 PrevAllocator->printPretty(PrevAllocatorStream, nullptr,
3396 Allocator ? Allocator->getExprLoc() : RefExpr->getExprLoc();
3398 Allocator ? Allocator->getSourceRange() : RefExpr->getSourceRange();
3400 PrevAllocator ? PrevAllocator->getExprLoc() : A->getLocation();
3402 PrevAllocator ? PrevAllocator->getSourceRange() : A->getRange();
3418 if (VD->hasAttr<OMPAllocateDeclAttr>())
3421 (Alignment->isTypeDependent() || Alignment->isValueDependent() ||
3422 Alignment->isInstantiationDependent() ||
3423 Alignment->containsUnexpandedParameterPack()))
3427 (Allocator->isTypeDependent() || Allocator->isValueDependent() ||
3428 Allocator->isInstantiationDependent() ||
3429 Allocator->containsUnexpandedParameterPack()))
3433 VD->addAttr(A);
3435 ML->DeclarationMarkedOpenMPAllocate(VD, A);
3450 !DSAStack->hasRequiresDeclWithClause<OMPDynamicAllocatorsClause>())
3455 Allocator = AC->getAllocator();
3457 Alignment = AC->getAlignment();
3466 auto *VD = cast<VarDecl>(DE->getDecl());
3469 if (VD->getTLSKind() != VarDecl::TLS_None ||
3470 VD->hasAttr<OMPThreadPrivateDeclAttr>() ||
3471 (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() &&
3472 !VD->isLocalVarDecl()))
3485 if (Allocator && VD->hasGlobalStorage()) {
3487 Diag(Allocator->getExprLoc(),
3489 << Allocator->getSourceRange();
3490 bool IsDecl = VD->isThisDeclarationADefinition(getASTContext()) ==
3492 Diag(VD->getLocation(),
3501 DE->getSourceRange());
3508 D->setAccess(AS_public);
3509 Owner->addDecl(D);
3517 if (!SemaRef.CurContext->isFileContext()) {
3522 SemaRef.CurContext->addDecl(D);
3523 DSAStack->addRequiresDecl(D);
3559 while (Ctx->getLexicalParent())
3560 Ctx = Ctx->getLexicalParent();
3564 for (auto *SubDC : DC->decls()) {
3565 if (SubDC->isInvalidDecl())
3568 DeclContexts.push_back(CTD->getTemplatedDecl());
3569 llvm::append_range(DeclContexts, CTD->specializations());
3575 F->addAttr(AA);
3594 DSAStack->getEncounteredTargetLocs();
3595 SourceLocation AtomicLoc = DSAStack->getAtomicDirectiveLoc();
3604 << "target" << getOpenMPClauseName(CNew->getClauseKind());
3612 << "atomic" << getOpenMPClauseName(CNew->getClauseKind());
3619 if (!DSAStack->hasDuplicateRequiresClause(ClauseList))
3630 SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa)
3647 auto ReportLoc = D->getLocation();
3660 } else if (VD && VD->isStaticLocal())
3662 else if (VD && VD->isStaticDataMember())
3664 else if (VD && VD->isFileVarDecl())
3666 else if (D->getType().isConstant(SemaRef.getASTContext()))
3668 else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) {
3675 << getOpenMPDirectiveName(Stack->getCurrentDirective());
3701 // If implicit-behavior is present, each variable referenced in the
3702 // construct in the category specified by variable-category is treated as if
3703 // it had been listed in a map clause with the map-type of alloc and
3704 // map-type-modifier of present.
3732 CapturedStmt *CS = nullptr;
3744 if (!S->hasAssociatedStmt() || !S->getAssociatedStmt())
3746 if (S->getDirectiveKind() == OMPD_atomic ||
3747 S->getDirectiveKind() == OMPD_critical ||
3748 S->getDirectiveKind() == OMPD_section ||
3749 S->getDirectiveKind() == OMPD_master ||
3750 S->getDirectiveKind() == OMPD_masked ||
3751 S->getDirectiveKind() == OMPD_scope ||
3752 isOpenMPLoopTransformationDirective(S->getDirectiveKind())) {
3753 Visit(S->getAssociatedStmt());
3756 visitSubCaptures(S->getInnermostCapturedStmt());
3757 // Try to capture inner this->member references to generate correct mappings
3760 (isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()) &&
3761 llvm::any_of(S->getInnermostCapturedStmt()->captures(),
3767 Visit(S->getInnermostCapturedStmt()->getCapturedStmt());
3772 if (isOpenMPTaskingDirective(S->getDirectiveKind()) &&
3773 !isOpenMPTaskLoopDirective(S->getDirectiveKind())) {
3774 for (OMPClause *C : S->clauses())
3776 for (Expr *Ref : FC->varlists())
3784 if (TryCaptureCXXThisMembers || E->isTypeDependent() ||
3785 E->isValueDependent() || E->containsUnexpandedParameterPack() ||
3786 E->isInstantiationDependent() ||
3787 E->isNonOdrUse() == clang::NOUR_Unevaluated)
3789 if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) {
3791 if (!CS || (isa<OMPCapturedExprDecl>(VD) && !CS->capturesVariable(VD) &&
3792 !Stack->getTopDSA(VD, /*FromParent=*/false).RefExpr &&
3793 !Stack->isImplicitDefaultFirstprivateFD(VD))) {
3795 if (!CED->hasAttr<OMPCaptureNoInitAttr>()) {
3796 Visit(CED->getInit());
3799 } else if (VD->isImplicit() || isa<OMPCapturedExprDecl>(VD))
3802 if (!Stack->isImplicitDefaultFirstprivateFD(VD))
3804 VD = VD->getCanonicalDecl();
3806 if (VD->hasLocalStorage() && CS && !CS->capturesVariable(VD) &&
3807 !Stack->isImplicitDefaultFirstprivateFD(VD) &&
3808 !Stack->isImplicitTaskFirstprivate(VD))
3811 if (Stack->isUsesAllocatorsDecl(VD))
3814 DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, /*FromParent=*/false);
3822 if (VD->hasGlobalStorage() && CS && !CS->capturesVariable(VD) &&
3823 (Stack->hasRequiresDeclWithClause<OMPUnifiedSharedMemoryClause>() ||
3825 !Stack->isImplicitDefaultFirstprivateFD(VD) &&
3826 !Stack->isImplicitTaskFirstprivate(VD))
3829 SourceLocation ELoc = E->getExprLoc();
3830 OpenMPDirectiveKind DKind = Stack->getCurrentDirective();
3832 // in the construct, and does not have a predetermined data-sharing
3833 // attribute, must have its data-sharing attribute explicitly determined
3834 // by being listed in a data-sharing attribute clause.
3836 (Stack->getDefaultDSA() == DSA_none ||
3837 Stack->getDefaultDSA() == DSA_private ||
3838 Stack->getDefaultDSA() == DSA_firstprivate) &&
3841 bool InheritedDSA = Stack->getDefaultDSA() == DSA_none;
3842 if (!InheritedDSA && (Stack->getDefaultDSA() == DSA_firstprivate ||
3843 Stack->getDefaultDSA() == DSA_private)) {
3845 Stack->getImplicitDSA(VD, /*FromParent=*/false);
3850 if (Stack->getDefaultDSA() == DSA_none)
3855 // If implicit-behavior is none, each variable referenced in the
3856 // construct that does not have a predetermined data-sharing attribute
3858 // directive must be listed in a data-mapping attribute clause, a
3859 // data-sharing attribute clause (including a data-sharing attribute
3865 bool IsModifierNone = Stack->getDefaultmapModifier(ClauseKind) ==
3869 // Only check for data-mapping attribute and is_device_ptr here
3871 // have a data-sharing attribute above
3872 if (!Stack->checkMappableExprComponentListsForDecl(
3879 return MI != ME && MI->getAssociatedDeclaration() == VD;
3887 bool IsModifierPresent = Stack->getDefaultmapModifier(ClauseKind) ==
3899 !Stack->isLoopControlVariable(VD).first) {
3900 if (!Stack->checkMappableExprComponentListsForDecl(
3927 VD->getType().getNonReferenceType()->getAsCXXRecordDecl())
3928 IsFirstprivate = RD->isLambda();
3930 IsFirstprivate || (Stack->mustBeFirstprivate(ClauseKind) && !Res);
3935 Stack->getDefaultmapModifier(ClauseKind);
3948 DVar = Stack->hasInnermostDSA(
3965 // Define implicit data-sharing attributes for task.
3966 DVar = Stack->getImplicitDSA(VD, /*FromParent=*/false);
3968 (((Stack->getDefaultDSA() == DSA_firstprivate &&
3970 (Stack->getDefaultDSA() == DSA_private &&
3973 !Stack->isLoopControlVariable(VD).first) {
3974 if (Stack->getDefaultDSA() == DSA_private)
3985 Stack->addToParentTargetRegionLinkGlobals(E);
3991 if (E->isTypeDependent() || E->isValueDependent() ||
3992 E->containsUnexpandedParameterPack() || E->isInstantiationDependent())
3994 auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl());
3995 OpenMPDirectiveKind DKind = Stack->getCurrentDirective();
3996 if (auto *TE = dyn_cast<CXXThisExpr>(E->getBase()->IgnoreParenCasts())) {
3999 DSAStackTy::DSAVarData DVar = Stack->getTopDSA(FD, /*FromParent=*/false);
4006 !Stack->isLoopControlVariable(FD).first &&
4007 !Stack->checkMappableExprComponentListsForDecl(
4015 ->getBase()
4016 ->IgnoreParens());
4019 // A bit-field cannot appear in a map clause.
4021 if (FD->isBitField())
4026 if (Stack->isClassPreviouslyMapped(TE->getType()))
4030 Stack->getDefaultmapModifier(OMPC_DEFAULTMAP_aggregate);
4039 SourceLocation ELoc = E->getExprLoc();
4044 DVar = Stack->hasInnermostDSA(
4061 // Define implicit data-sharing attributes for task.
4062 DVar = Stack->getImplicitDSA(FD, /*FromParent=*/false);
4064 !Stack->isLoopControlVariable(FD).first) {
4077 Stack->getCurrentDirective(),
4081 CurComponents.back().getAssociatedDeclaration()->getCanonicalDecl());
4082 if (!Stack->checkMappableExprComponentListsForDecl(
4092 if (CCI->getAssociatedExpression()->getStmtClass() !=
4093 SC.getAssociatedExpression()->getStmtClass())
4099 CCI->getAssociatedExpression())))
4102 const Decl *CCD = CCI->getAssociatedDeclaration();
4104 CCD = CCD ? CCD->getCanonicalDecl() : nullptr;
4105 SCD = SCD ? SCD->getCanonicalDecl() : nullptr;
4114 Visit(E->getBase());
4117 Visit(E->getBase());
4121 for (OMPClause *C : S->clauses()) {
4131 C->isImplicit() &&
4132 !isOpenMPTaskingDirective(Stack->getCurrentDirective()))) {
4133 for (Stmt *CC : C->children()) {
4149 for (Stmt *C : S->arguments()) {
4151 // Check implicitly captured variables in the task-based directives to
4156 if (Expr *Callee = S->getCallee()) {
4157 auto *CI = Callee->IgnoreParenImpCasts();
4159 Visit(CE->getBase());
4165 for (Stmt *C : S->children()) {
4167 // Check implicitly captured variables in the task-based directives to
4175 for (const CapturedStmt::Capture &Cap : S->captures()) {
4179 // Do not try to map the variable if it or its sub-component was mapped
4181 if (isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()) &&
4182 Stack->checkMappableExprComponentListsForDecl(
4188 SemaRef, VD, VD->getType().getNonLValueExprType(SemaRef.Context),
4210 DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS)
4211 : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {
4213 if (isOpenMPTargetExecutionDirective(S->getCurrentDirective())) {
4214 for (DeclRefExpr *E : Stack->getLinkGlobals())
4235 Stack->handleConstructTrait(Traits, ScopeEntry);
4352 CSI->TheCapturedDecl->addAttr(AlwaysInlineAttr::CreateImplicit(
4414 DSAStack->getConstructLoc());
4418 DSAStack->setContext(SemaRef.CurContext);
4423 return getOpenMPCaptureLevels(DSAStack->getDirective(Level));
4438 Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts();
4439 QualType Ty = Init->getType();
4440 if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) {
4446 S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init);
4454 CaptureExpr->getBeginLoc());
4456 CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C));
4457 CurContext->addHiddenDecl(CED);
4469 CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit,
4472 return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(),
4473 CaptureExpr->getExprLoc());
4483 Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(),
4484 CaptureExpr->getExprLoc());
4488 CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() &&
4489 Ref->getType()->isPointerType()) {
4490 Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref);
4519 while (--ThisCaptureLevel >= 0)
4527 // Capture variables captured by reference in lambdas for target-based
4529 if (!SemaRef.CurContext->isDependentContext() &&
4530 (isOpenMPTargetExecutionDirective(DSAStack->getCurrentDirective()) ||
4532 DSAStack->getCurrentDirective()))) {
4533 QualType Type = V->getType();
4536 ->getAsCXXRecordDecl()) {
4538 DSAStack->isForceCaptureByReferenceInTargetExecutable();
4539 DSAStack->setForceCaptureByReferenceInTargetExecutable(
4541 if (RD->isLambda()) {
4544 RD->getCaptureFields(Captures, ThisCapture);
4545 for (const LambdaCapture &LC : RD->captures()) {
4548 DeclContext *VDC = VD->getDeclContext();
4549 if (!VDC->Encloses(SemaRef.CurContext))
4555 ThisTy, ThisCapture->getType()))
4560 DSAStack->setForceCaptureByReferenceInTargetExecutable(
4572 if (Clause->getClauseKind() == OMPC_ordered)
4574 else if (Clause->getClauseKind() == OMPC_order) {
4576 if (Order->getKind() != OMPC_ORDER_concurrent)
4584 S.Diag(Order->getKindKwLoc(),
4588 << SourceRange(Order->getBeginLoc(), Order->getEndLoc());
4589 S.Diag(Ordered->getBeginLoc(), diag::note_omp_ordered_param)
4590 << 0 << SourceRange(Ordered->getBeginLoc(), Ordered->getEndLoc());
4598 handleDeclareVariantConstructTrait(DSAStack, DSAStack->getCurrentDirective(),
4600 if (!isOpenMPCapturingDirective(DSAStack->getCurrentDirective()))
4605 SemaRef, ErrorFound, DSAStack->getCurrentDirective());
4612 getOpenMPCaptureRegions(CaptureRegions, DSAStack->getCurrentDirective());
4620 (isOpenMPTaskingDirective(DSAStack->getCurrentDirective()) ||
4621 DSAStack->getCurrentDirective() == OMPD_target) &&
4622 Clause->getClauseKind() == OMPC_in_reduction) {
4626 for (Expr *E : IRC->taskgroup_descriptors())
4630 if (isOpenMPPrivate(Clause->getClauseKind()) ||
4631 Clause->getClauseKind() == OMPC_copyprivate ||
4634 Clause->getClauseKind() == OMPC_copyin)) {
4635 DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin);
4637 for (Stmt *VarRef : Clause->children()) {
4642 DSAStack->setForceVarCapturing(/*V=*/false);
4648 if (Expr *E = C->getPostUpdateExpr())
4652 if (Clause->getClauseKind() == OMPC_schedule)
4654 else if (Clause->getClauseKind() == OMPC_ordered)
4656 else if (Clause->getClauseKind() == OMPC_linear)
4660 for (Expr *E : DSAStack->getInnerAllocators())
4666 (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic ||
4667 SC->getSecondScheduleModifier() ==
4670 Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic
4671 ? SC->getFirstScheduleModifierLoc()
4672 : SC->getSecondScheduleModifierLoc(),
4677 << SourceRange(OC->getBeginLoc(), OC->getEndLoc());
4680 // OpenMP 5.0, 2.9.2 Worksharing-Loop Construct, Restrictions.
4685 if (!LCs.empty() && OC && OC->getNumForLoops()) {
4687 Diag(C->getBeginLoc(), diag::err_omp_linear_ordered)
4688 << SourceRange(OC->getBeginLoc(), OC->getEndLoc());
4692 if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) &&
4693 isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC &&
4694 OC->getNumForLoops()) {
4695 Diag(OC->getBeginLoc(), diag::err_omp_ordered_simd)
4696 << getOpenMPDirectiveName(DSAStack->getCurrentDirective());
4710 OpenMPDirectiveKind CaptureRegion = C->getCaptureRegion();
4718 if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) {
4719 for (Decl *D : DS->decls())
4720 SemaRef.MarkVariableReferenced(D->getLocation(),
4731 for (unsigned I = 0, End = UAC->getNumberOfAllocators(); I < End;
4733 OMPUsesAllocatorsClause::Data D = UAC->getAllocatorData(I);
4746 if (RC->getModifier() != OMPC_REDUCTION_inscan)
4748 for (Expr *E : RC->copy_array_temps())
4753 for (Expr *E : AC->varlists())
4759 DSAStack->setBodyComplete();
4787 if (!Stack->getCurScope())
4790 OpenMPDirectiveKind ParentRegion = Stack->getParentDirective();
4809 if (SemaRef.LangOpts.OpenMP >= 51 && Stack->isParentOrderConcurrent() &&
4882 // A cancellation point construct for which construct-type-clause is
4884 // point construct for which construct-type-clause is not taskgroup must
4886 // specified in construct-type-clause.
4887 // A cancel construct for which construct-type-clause is taskgroup must be
4889 // construct-type-clause is not taskgroup must be closely nested inside an
4891 // construct-type-clause.
4917 bool DeadLock = Stack->hasDirective(
4975 Stack->isParentOrderedRegion());
5005 // distribute, distribute simd, distribute parallel worksharing-loop,
5006 // distribute parallel worksharing-loop SIMD, loop, parallel regions,
5043 NestingProhibited = Stack->hasDirective(
5083 // At most one if clause without a directive-name-modifier can appear on
5085 OpenMPDirectiveKind CurNM = IC->getNameModifier();
5087 S.Diag(C->getBeginLoc(), diag::err_omp_more_one_clause)
5092 NameModifierLoc.push_back(IC->getNameModifierLoc());
5100 // At most one if clause with the particular directive-name-modifier can
5103 S.Diag(IC->getNameModifierLoc(),
5110 // If any if clause on the directive includes a directive-name-modifier then
5111 // all if clauses on the directive must include a directive-name-modifier.
5114 S.Diag(FoundNameModifiers[OMPD_unknown]->getBeginLoc(),
5121 AllowedNameModifiers.size() - NamedModifiersNumber;
5136 S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getBeginLoc(),
5153 if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() ||
5154 RefExpr->containsUnexpandedParameterPack())
5162 RefExpr = RefExpr->IgnoreParens();
5164 NoArrayExpr = -1,
5170 Expr *Base = ASE->getBase()->IgnoreParenImpCasts();
5172 Base = TempASE->getBase()->IgnoreParenImpCasts();
5176 Expr *Base = OASE->getBase()->IgnoreParenImpCasts();
5178 Base = TempOASE->getBase()->IgnoreParenImpCasts();
5180 Base = TempASE->getBase()->IgnoreParenImpCasts();
5185 ELoc = RefExpr->getExprLoc();
5186 ERange = RefExpr->getSourceRange();
5187 RefExpr = RefExpr->IgnoreParenImpCasts();
5190 if ((!DE || !isa<VarDecl>(DE->getDecl())) &&
5192 !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) ||
5193 !isa<FieldDecl>(ME->getMemberDecl()))) {
5213 getCanonicalDecl(DE ? DE->getDecl() : ME->getMemberDecl()), false);
5224 return S->isUsesAllocatorsDecl(E->getDecl())
5229 for (const Stmt *Child : S->children()) {
5241 assert(!S.CurContext->isDependentContext() &&
5242 "Expected non-dependent context.");
5247 return isOpenMPPrivate(C->getClauseKind());
5251 if (Cl->getClauseKind() == OMPC_private) {
5253 I = PC->private_copies().begin();
5254 It = PC->varlist_begin();
5255 Et = PC->varlist_end();
5256 } else if (Cl->getClauseKind() == OMPC_firstprivate) {
5258 I = PC->private_copies().begin();
5259 It = PC->varlist_begin();
5260 Et = PC->varlist_end();
5261 } else if (Cl->getClauseKind() == OMPC_lastprivate) {
5263 I = PC->private_copies().begin();
5264 It = PC->varlist_begin();
5265 Et = PC->varlist_end();
5266 } else if (Cl->getClauseKind() == OMPC_linear) {
5268 I = PC->privates().begin();
5269 It = PC->varlist_begin();
5270 Et = PC->varlist_end();
5271 } else if (Cl->getClauseKind() == OMPC_reduction) {
5273 I = PC->privates().begin();
5274 It = PC->varlist_begin();
5275 Et = PC->varlist_end();
5276 } else if (Cl->getClauseKind() == OMPC_task_reduction) {
5278 I = PC->privates().begin();
5279 It = PC->varlist_begin();
5280 Et = PC->varlist_end();
5281 } else if (Cl->getClauseKind() == OMPC_in_reduction) {
5283 I = PC->privates().begin();
5284 It = PC->varlist_begin();
5285 Et = PC->varlist_end();
5300 cast<VarDecl>(cast<DeclRefExpr>(*I)->getDecl()));
5307 !Stack->hasRequiresDeclWithClause<OMPDynamicAllocatorsClause>() &&
5308 isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()) &&
5309 AC->getAllocator()) {
5310 Expr *Allocator = AC->getAllocator();
5318 S.Diag(Allocator->getExprLoc(),
5320 << Allocator->getSourceRange();
5323 getAllocatorKind(S, Stack, AC->getAllocator());
5329 (isOpenMPTaskingDirective(Stack->getCurrentDirective()) ||
5330 isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()))) {
5331 S.Diag(AC->getAllocator()->getExprLoc(),
5333 << getOpenMPDirectiveName(Stack->getCurrentDirective());
5335 for (Expr *E : AC->varlists()) {
5341 DSAStackTy::DSAVarData Data = Stack->getTopDSA(VD, /*FromParent=*/false);
5343 S.Diag(E->getExprLoc(),
5349 AllocatorKind, AC->getAllocator()))
5353 applyOMPAllocateAttribute(S, PrivateVD, AllocatorKind, AC->getAllocator(),
5354 Alignment, E->getSourceRange());
5379 VarDecl *NewVar = buildVarDecl(Actions, {}, NewE->getType(), Name, nullptr,
5380 dyn_cast<DeclRefExpr>(E->IgnoreImplicit()));
5383 Actions.AddInitializerToDecl(NewDeclStmt->getSingleDecl(), NewE, false);
5406 // out-parameter instead. All inputs are implicit captures.
5417 CapturedDecl *CS = cast<CapturedDecl>(Actions.CurContext);
5420 ImplicitParamDecl *DistParam = CS->getParam(0);
5434 return buildDeclRefExpr(Actions, VD, VD->getType(), {});
5443 // When using a != comparison, the increment can be +1 or -1. This can be
5474 // non well-formed OpenMP if Step increments/decrements in the other
5500 // the step size, rounding-up the effective upper bound ensures that the
5502 // Note that the rounding-up may cause an overflow in a temporary that
5503 // could be avoided, but would have occurred in a C-style for-loop as
5522 // Assign the result to the out-parameter.
5552 // Pass the result as an out-parameter. Passing as return value would require
5564 VarDecl *StartVar = cast<VarDecl>(StartExpr->getDecl());
5568 assert(!Invalid && "Expecting capture-by-value to work.");
5573 auto *CS = cast<CapturedDecl>(Actions.CurContext);
5575 ImplicitParamDecl *TargetParam = CS->getParam(0);
5578 ImplicitParamDecl *IndvarParam = CS->getParam(1);
5595 // For range-based for-loops convert the loop counter value to a concrete
5617 Stmt *Init = For->getInit();
5620 LIVDecl = cast<VarDecl>(LCVarDeclStmt->getSingleDecl());
5623 assert(LCAssign->getOpcode() == BO_Assign &&
5625 auto *CounterRef = cast<DeclRefExpr>(LCAssign->getLHS());
5626 LIVDecl = cast<VarDecl>(CounterRef->getDecl());
5631 Cond = For->getCond();
5632 Inc = For->getInc();
5634 DeclStmt *BeginStmt = RangeFor->getBeginStmt();
5635 LIVDecl = cast<VarDecl>(BeginStmt->getSingleDecl());
5636 LUVDecl = RangeFor->getLoopVariable();
5638 Cond = RangeFor->getCond();
5639 Inc = RangeFor->getInc();
5643 QualType CounterTy = LIVDecl->getType();
5644 QualType LVTy = LUVDecl->getType();
5649 Cond = Cond->IgnoreImplicit();
5651 LHS = CondBinExpr->getLHS();
5652 RHS = CondBinExpr->getRHS();
5653 CondRel = CondBinExpr->getOpcode();
5655 assert(CondCXXOp->getNumArgs() == 2 && "Comparison should have 2 operands");
5656 LHS = CondCXXOp->getArg(0);
5657 RHS = CondCXXOp->getArg(1);
5658 switch (CondCXXOp->getOperator()) {
5681 if (!isa<DeclRefExpr>(LHS->IgnoreImplicit()) ||
5682 cast<DeclRefExpr>(LHS->IgnoreImplicit())->getDecl() != LIVDecl) {
5686 auto *CounterRef = cast<DeclRefExpr>(LHS->IgnoreImplicit());
5691 // std::iterator_traits<>::difference_type or decltype(it - end).
5693 if (CounterTy->isIntegerType()) {
5702 switch (IncUn->getOpcode()) {
5709 Direction = -1;
5717 if (IncBin->getOpcode() == BO_AddAssign) {
5718 Step = IncBin->getRHS();
5719 } else if (IncBin->getOpcode() == BO_SubAssign) {
5721 SemaRef.BuildUnaryOp(nullptr, {}, UO_Minus, IncBin->getRHS()));
5725 switch (CondCXXOp->getOperator()) {
5732 Ctx, llvm::APInt(Ctx.getIntWidth(LogicalTy), -1), LogicalTy, {});
5735 Step = CondCXXOp->getArg(1);
5739 SemaRef.BuildUnaryOp(nullptr, {}, UO_Minus, CondCXXOp->getArg(1)));
5752 SemaRef.BuildDeclRefExpr(LUVDecl, LUVDecl->getType(), VK_LValue, {},
5766 isOpenMPLoopTransformationDirective(LoopTransform->getDirectiveKind()) &&
5778 /// member(s) with user-defined 'default' mapper and generate implicit map
5792 auto *MI = C->mapperlist_begin();
5793 for (auto I = C->varlist_begin(), End = C->varlist_end(); I != End;
5795 // Expression is mapped using mapper - skip it.
5799 // Expression is dependent - skip it, build the mapper when it gets
5801 if (E->isTypeDependent() || E->isValueDependent() ||
5802 E->containsUnexpandedParameterPack())
5804 // Array section - need to check for the mapping of the array section
5806 QualType CanonType = E->getType().getCanonicalType();
5807 if (CanonType->isSpecificBuiltinType(BuiltinType::ArraySection)) {
5808 const auto *OASE = cast<ArraySectionExpr>(E->IgnoreParenImpCasts());
5810 ArraySectionExpr::getBaseOriginalType(OASE->getBase());
5812 if (const auto *ATy = BaseType->getAsArrayTypeUnsafe())
5813 ElemType = ATy->getElementType();
5815 ElemType = BaseType->getPointeeType();
5831 --ParentChain.back().second;
5835 const RecordDecl *RD = BaseType.getCanonicalType()->getAsRecordDecl();
5840 // Try to find the associated user-defined mapper.
5845 DefaultMapperId.setLoc(E->getExprLoc());
5847 S, Stack->getCurScope(), MapperIdScopeSpec, DefaultMapperId,
5854 if (It->second) {
5855 auto *OE = new (S.Context) OpaqueValueExpr(E->getExprLoc(), CanonType,
5857 OE->setIsUnique(/*V=*/true);
5862 BaseExpr, /*IsArrow=*/false, E->getExprLoc(),
5864 DeclAccessPair::make(P.first, P.first->getAccess()),
5866 P.first->getType(), VK_LValue, OK_Ordinary);
5872 BaseExpr, /*IsArrow=*/false, E->getExprLoc(),
5874 DeclAccessPair::make(CurFD, CurFD->getAccess()),
5876 CurFD->getType(), VK_LValue, OK_Ordinary);
5882 for (FieldDecl *FD : RD->fields()) {
5885 QualType FieldTy = FD->getType();
5887 !(FieldTy->isStructureOrClassType() || FieldTy->isUnionType()))
5904 nullptr, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
5905 MapperIdScopeSpec, MapperId, C->getMapType(),
5914 /// call in the associated loop-nest cannot be a 'parallel for'.
5923 if (D->getDirectiveKind() == llvm::omp::Directive::OMPD_loop) {
5924 if (const auto *C = D->getSingleClause<OMPBindClause>())
5925 if (C->getBindKind() == OMPC_BIND_parallel) {
5931 for (const Stmt *Child : D->children())
5938 // unless the assume-no-nested-parallelism flag has been specified.
5940 // translation, regardless of the assume-no-nested-parallelism.
5942 auto *FD = dyn_cast_or_null<FunctionDecl>(C->getCalleeDecl());
5944 std::string Name = FD->getNameInfo().getAsString();
5952 for (const Stmt *Child : C->children())
5960 Visit(S->getCapturedDecl()->getBody());
5966 for (const Stmt *Child : S->children())
5996 const OpenMPDirectiveKind ParentDirective = DSAStack->getParentDirective();
6001 // [5.0:129:25-28] If the bind clause is not present on the construct and
6011 Diag(DSAStack->getDefaultDSALocation(),
6029 C->getClauseKind() == llvm::omp::Clause::OMPC_reduction)
6030 Diag(DSAStack->getDefaultDSALocation(),
6035 if (C->getClauseKind() != llvm::omp::Clause::OMPC_bind)
6042 DSAStack->setCurrentDirective(OMPD_for);
6043 DSAStack->setMappedDirective(OMPD_loop);
6048 DSAStack->setCurrentDirective(OMPD_distribute);
6049 DSAStack->setMappedDirective(OMPD_loop);
6054 DSAStack->setCurrentDirective(OMPD_simd);
6055 DSAStack->setMappedDirective(OMPD_loop);
6070 DSAStack->setMappedDirective(OMPD_loop);
6090 BindKind = BC->getBindKind();
6109 // Report affected OpenMP target offloading behavior when in HIP lang-mode.
6123 if (AStmt && !SemaRef.CurContext->isDependentContext() &&
6131 while (--ThisCaptureLevel >= 0)
6132 S = cast<CapturedStmt>(S)->getCapturedStmt();
6137 auto *CS = cast<CapturedStmt>(AStmt);
6142 CS = cast<CapturedStmt>(CS->getCapturedStmt());
6143 DSAChecker.visitSubCaptures(CS);
6166 if (DMC->getDefaultmapModifier() == OMPC_DEFAULTMAP_MODIFIER_present)
6167 PresentModifierLocs[DMC->getDefaultmapKind()] =
6168 DMC->getDefaultmapModifierLoc();
6187 for (Expr *E : IRC->taskgroup_descriptors())
6192 // [detach clause]... The event-handle will be considered as if it was
6195 ImplicitFirstprivates.push_back(DC->getEventHandler());
6202 ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() !=
6213 ErrorFound = cast<OMPPrivateClause>(Implicit)->varlist_size() !=
6222 // if it also appears in a map clause with a map-type of tofrom
6228 for (Expr *E : RC->varlists())
6229 if (!isa<DeclRefExpr>(E->IgnoreParenImpCasts()))
6245 int ClauseKindCnt = -1;
6259 ErrorFound |= cast<OMPMapClause>(Implicit)->varlist_size() !=
6607 if (DSAStack->getDefaultDSA() == DSA_none ||
6608 DSAStack->getDefaultDSA() == DSA_private ||
6609 DSAStack->getDefaultDSA() == DSA_firstprivate) {
6612 switch (C->getClauseKind()) {
6621 cast<OMPIfClause>(C)->getNameModifier() != OMPD_target)
6625 cast<OMPIfClause>(C)->getNameModifier() != OMPD_parallel)
6719 for (Stmt *CC : C->children()) {
6728 if (P.getFirst()->isImplicit() || isa<OMPCapturedExprDecl>(P.getFirst()))
6731 if (DSAStack->getDefaultDSA() == DSA_none ||
6732 DSAStack->getDefaultDSA() == DSA_private ||
6733 DSAStack->getDefaultDSA() == DSA_firstprivate) {
6734 Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable)
6735 << P.first << P.second->getSourceRange();
6736 Diag(DSAStack->getDefaultDSALocation(), diag::note_omp_default_dsa_none);
6738 Diag(P.second->getExprLoc(),
6740 << P.first << P.second->getSourceRange();
6741 Diag(DSAStack->getDefaultDSALocation(),
6758 if (!SemaRef.CurContext->isDependentContext() &&
6760 !(DSAStack->hasRequiresDeclWithClause<OMPUnifiedSharedMemoryClause>() ||
6761 DSAStack->hasRequiresDeclWithClause<OMPUnifiedAddressClause>() ||
6762 DSAStack->hasRequiresDeclWithClause<OMPReverseOffloadClause>() ||
6763 DSAStack->hasRequiresDeclWithClause<OMPDynamicAllocatorsClause>())) {
6765 DSAStack->addTargetDirLocation(StartLoc);
6790 ADecl = FTD->getTemplatedDecl();
6794 Diag(ADecl->getLocation(), diag::err_omp_function_expected) << SimdId;
6813 E = E->IgnoreParenImpCasts();
6815 if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl()))
6816 if (FD->getNumParams() > PVD->getFunctionScopeIndex() &&
6817 FD->getParamDecl(PVD->getFunctionScopeIndex())
6818 ->getCanonicalDecl() == PVD->getCanonicalDecl()) {
6819 UniformedArgs.try_emplace(PVD->getCanonicalDecl(), E);
6826 Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause)
6827 << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0);
6840 E = E->IgnoreParenImpCasts();
6842 if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
6843 const VarDecl *CanonPVD = PVD->getCanonicalDecl();
6844 if (FD->getNumParams() > PVD->getFunctionScopeIndex() &&
6845 FD->getParamDecl(PVD->getFunctionScopeIndex())
6846 ->getCanonicalDecl() == CanonPVD) {
6848 // A list-item cannot appear in more than one aligned clause.
6850 Diag(E->getExprLoc(), diag::err_omp_used_in_clause_twice)
6852 << E->getSourceRange();
6853 Diag(AlignedArgs[CanonPVD]->getExprLoc(),
6859 QualType QTy = PVD->getType()
6864 if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) {
6865 Diag(E->getExprLoc(), diag::err_omp_aligned_expected_array_or_ptr)
6866 << QTy << getLangOpts().CPlusPlus << E->getSourceRange();
6867 Diag(PVD->getLocation(), diag::note_previous_decl) << PVD;
6874 Diag(E->getExprLoc(), diag::err_omp_used_in_clause_twice)
6875 << 2 << getOpenMPClauseName(OMPC_aligned) << E->getSourceRange();
6876 Diag(AlignedThis->getExprLoc(), diag::note_omp_explicit_dsa)
6882 Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause)
6883 << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0);
6887 // implementation-defined default alignments for SIMD instructions on the
6902 // When a linear-step expression is specified in a linear clause it must be
6903 // either a constant integer expression or an integer-typed parameter that is
6911 E = E->IgnoreParenImpCasts();
6913 if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
6914 const VarDecl *CanonPVD = PVD->getCanonicalDecl();
6915 if (FD->getNumParams() > PVD->getFunctionScopeIndex() &&
6916 FD->getParamDecl(PVD->getFunctionScopeIndex())
6917 ->getCanonicalDecl() == CanonPVD) {
6919 // A list-item cannot appear in more than one linear clause.
6921 Diag(E->getExprLoc(), diag::err_omp_wrong_dsa)
6923 << getOpenMPClauseName(OMPC_linear) << E->getSourceRange();
6924 Diag(LinearArgs[CanonPVD]->getExprLoc(),
6931 Diag(E->getExprLoc(), diag::err_omp_wrong_dsa)
6933 << getOpenMPClauseName(OMPC_uniform) << E->getSourceRange();
6934 Diag(UniformedArgs[CanonPVD]->getExprLoc(),
6940 if (E->isValueDependent() || E->isTypeDependent() ||
6941 E->isInstantiationDependent() ||
6942 E->containsUnexpandedParameterPack())
6944 (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind,
6945 PVD->getOriginalType(),
6952 Diag(E->getExprLoc(), diag::err_omp_wrong_dsa)
6955 << E->getSourceRange();
6956 Diag(UniformedLinearThis->getExprLoc(), diag::note_omp_explicit_dsa)
6962 if (E->isValueDependent() || E->isTypeDependent() ||
6963 E->isInstantiationDependent() || E->containsUnexpandedParameterPack())
6965 (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind,
6966 E->getType(), /*IsDeclareSimd=*/true);
6969 Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause)
6970 << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0);
6983 if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
6984 const VarDecl *CanonPVD = PVD->getCanonicalDecl();
6986 Diag(Step->getExprLoc(), diag::err_omp_expected_uniform_param)
6987 << Step->getSourceRange();
6988 } else if (E->isValueDependent() || E->isTypeDependent() ||
6989 E->isInstantiationDependent() ||
6990 E->containsUnexpandedParameterPack() ||
6991 CanonPVD->getType()->hasIntegerRepresentation()) {
6994 Diag(Step->getExprLoc(), diag::err_omp_expected_int_param)
6995 << Step->getSourceRange();
7000 if (Step && !Step->isValueDependent() && !Step->isTypeDependent() &&
7001 !Step->isInstantiationDependent() &&
7002 !Step->containsUnexpandedParameterPack()) {
7003 NewStep = PerformOpenMPImplicitIntegerConversion(Step->getExprLoc(), Step)
7020 ADecl->addAttr(NewAttr);
7026 assert(NewType->isFunctionProtoType() &&
7028 assert(FD->getType()->isFunctionNoProtoType() &&
7030 assert(FDWithProto->getType()->isFunctionProtoType() &&
7033 FD->setType(NewType);
7035 for (const ParmVarDecl *P : FDWithProto->parameters()) {
7037 SourceLocation(), nullptr, P->getType(),
7039 Param->setScopeInfo(0, Params.size());
7040 Param->setImplicit();
7044 FD->setParams(Params);
7048 if (D->isInvalidDecl())
7052 FD = UTemplDecl->getTemplatedDecl();
7062 FD->addAttr(AA);
7065 FD->addAttr(AA);
7082 !DVScope.TI->isExtensionActive(
7093 QualType FType = TInfo->getType();
7101 auto *CandidateDecl = Candidate->getUnderlyingDecl();
7105 if (FTD->getTemplateParameters()->size() == TemplateParamLists.size())
7106 UDecl = FTD->getTemplatedDecl();
7113 // non-constexpr/consteval functions.
7114 if (UDecl->isConstexpr() && !IsConstexpr)
7116 if (UDecl->isConsteval() && !IsConsteval)
7119 QualType UDeclTy = UDecl->getType();
7120 if (!UDeclTy->isDependentType()) {
7132 bool UseImplicitBase = !DVScope.TI->isExtensionActive(
7138 BaseD->setImplicit(true);
7140 Bases.push_back(BaseTemplD->getTemplatedDecl());
7146 MangledName += D.getIdentifier()->getName();
7164 FD = UTemplDecl->getTemplatedDecl();
7170 /* NameLoc */ FD->getLocation(), FD->getType(),
7180 BaseFD->addAttr(OMPDeclareVariantA);
7194 FunctionDecl *CalleeFnDecl = CE->getDirectCallee();
7198 if (getLangOpts().OpenMP >= 51 && CalleeFnDecl->getIdentifier() &&
7199 CalleeFnDecl->getName().starts_with_insensitive("omp_")) {
7201 if (Scope && Scope->isOpenMPOrderClauseScope())
7205 if (!CalleeFnDecl->hasAttr<OMPDeclareVariantAttr>())
7213 Diag(CE->getBeginLoc(), diag::warn_unknown_declare_variant_isa_trait)
7218 DSAStack->getConstructTraits());
7220 QualType CalleeFnType = CalleeFnDecl->getType();
7226 CalleeFnDecl->specific_attrs<OMPDeclareVariantAttr>()) {
7227 Expr *VariantRef = A->getVariantFuncRef();
7230 OMPTraitInfo &TI = A->getTraitInfo();
7240 CalleeFnDecl = CalleeFnDecl->getPreviousDecl();
7249 Decl *BestDecl = cast<DeclRefExpr>(BestExpr)->getDecl();
7268 Context, MemberCall->getImplicitObjectArgument(),
7270 MemberCall->getValueKind(), MemberCall->getObjectKind());
7276 FunctionDecl *NewCalleeFnDecl = NCE->getDirectCallee();
7278 CalleeFnType, NewCalleeFnDecl->getType(),
7317 ADecl = FTD->getTemplatedDecl();
7322 Diag(ADecl->getLocation(), diag::err_omp_function_expected)
7330 return FD->isMultiVersion() || FD->hasAttr<TargetAttr>();
7334 Diag(FD->getLocation(), diag::err_omp_declare_variant_incompat_attributes)
7340 if (FD->isUsed(false))
7342 << FD->getLocation();
7346 if (!FD->isThisDeclarationADefinition() && FD->isDefined(Definition) &&
7349 << FD->getLocation();
7358 return E && (E->isTypeDependent() || E->isValueDependent() ||
7359 E->containsUnexpandedParameterPack() ||
7360 E->isInstantiationDependent());
7363 if (FD->isDependentContext() || ShouldDelayChecks(VariantRef, false) ||
7367 // Deal with non-constant score and user condition expressions.
7369 bool IsScore) -> bool {
7370 if (!E || E->isIntegerConstantExpr(getASTContext()))
7374 // We warn on non-constant scores and pretend they were not present.
7375 Diag(E->getExprLoc(), diag::warn_omp_declare_variant_score_not_constant)
7379 // We could replace a non-constant user condition with "false" but we
7382 Diag(E->getExprLoc(),
7391 QualType AdjustedFnType = FD->getType();
7393 const auto *PTy = AdjustedFnType->getAsAdjusted<FunctionProtoType>();
7395 Diag(FD->getLocation(), diag::err_omp_declare_variant_prototype_required)
7399 // Adjust the function type to account for an extra omp_interop_t for each
7413 if (PTy->isVariadic()) {
7414 Diag(FD->getLocation(), diag::err_omp_append_args_with_varargs) << SR;
7418 Params.append(PTy->param_type_begin(), PTy->param_type_end());
7420 AdjustedFnType = Context.getFunctionType(PTy->getReturnType(), Params,
7421 PTy->getExtProtoInfo());
7430 if (Method && !Method->isStatic()) {
7432 Context.getTypeDeclType(Method->getParent()).getTypePtr();
7439 ER = SemaRef.CreateBuiltinUnaryOp(VariantRef->getBeginLoc(), UO_AddrOf,
7443 Diag(VariantRef->getExprLoc(), diag::err_omp_function_expected)
7444 << VariantId << VariantRef->getSourceRange();
7451 QualType VarianPtrType = Context.getPointerType(VariantRef->getType());
7460 Diag(VariantRef->getExprLoc(),
7462 << VariantRef->getType()
7463 << ((Method && !Method->isStatic()) ? FnPtrType : FD->getType())
7464 << (NumAppendArgs ? 1 : 0) << VariantRef->getSourceRange();
7473 if (Method && !Method->isStatic()) {
7476 PossibleAddrOfVariantRef->IgnoreImplicit()))
7477 VariantRefCast = UO->getSubExpr();
7483 !ER.get()->IgnoreParenImpCasts()->getType()->isFunctionType()) {
7484 Diag(VariantRef->getExprLoc(), diag::err_omp_function_expected)
7485 << VariantId << VariantRef->getSourceRange();
7490 auto *DRE = dyn_cast<DeclRefExpr>(ER.get()->IgnoreParenImpCasts());
7492 Diag(VariantRef->getExprLoc(), diag::err_omp_function_expected)
7493 << VariantId << VariantRef->getSourceRange();
7496 auto *NewFD = dyn_cast_or_null<FunctionDecl>(DRE->getDecl());
7498 Diag(VariantRef->getExprLoc(), diag::err_omp_function_expected)
7499 << VariantId << VariantRef->getSourceRange();
7503 if (FD->getCanonicalDecl() == NewFD->getCanonicalDecl()) {
7504 Diag(VariantRef->getExprLoc(),
7506 << VariantRef->getSourceRange();
7513 Context.mergeFunctionTypes(AdjustedFnType, NewFD->getType());
7515 Diag(VariantRef->getExprLoc(),
7517 << NewFD->getType() << FD->getType() << (NumAppendArgs ? 1 : 0)
7518 << VariantRef->getSourceRange();
7521 if (NewType->isFunctionProtoType()) {
7522 if (FD->getType()->isFunctionNoProtoType())
7524 else if (NewFD->getType()->isFunctionNoProtoType())
7530 if (NewFD->hasAttrs() && NewFD->hasAttr<OMPDeclareVariantAttr>()) {
7531 Diag(VariantRef->getExprLoc(),
7533 << VariantRef->getSourceRange();
7535 NewFD->specific_attr_begin<OMPDeclareVariantAttr>()->getRange();
7550 if (CXXFD->isVirtual()) {
7551 Diag(FD->getLocation(), diag::err_omp_declare_variant_doesnt_support)
7557 Diag(FD->getLocation(), diag::err_omp_declare_variant_doesnt_support)
7563 Diag(FD->getLocation(), diag::err_omp_declare_variant_doesnt_support)
7569 if (FD->isDeleted()) {
7570 Diag(FD->getLocation(), diag::err_omp_declare_variant_doesnt_support)
7575 if (FD->isDefaulted()) {
7576 Diag(FD->getLocation(), diag::err_omp_declare_variant_doesnt_support)
7581 if (FD->isConstexpr()) {
7582 Diag(FD->getLocation(), diag::err_omp_declare_variant_doesnt_support)
7583 << (NewFD->isConsteval() ? ConstevalFuncs : ConstexprFuncs);
7593 VariantRef->getExprLoc(),
7595 PartialDiagnosticAt(VariantRef->getExprLoc(),
7597 << FD->getLocation()),
7642 E = E->IgnoreParenImpCasts();
7644 if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
7645 const VarDecl *CanonPVD = PVD->getCanonicalDecl();
7646 if (FD->getNumParams() > PVD->getFunctionScopeIndex() &&
7647 FD->getParamDecl(PVD->getFunctionScopeIndex())
7648 ->getCanonicalDecl() == CanonPVD) {
7651 Diag(DRE->getLocation(), diag::err_omp_adjust_arg_multiple_clauses)
7660 Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) << FD << 0;
7670 FD->addAttr(NewAttr);
7675 auto *CS = dyn_cast<CapturedStmt>(AStmt);
7676 assert(CS && "Captured statement expected");
7678 // Structured block - An executable statement with a single entry at the
7682 CS->getCapturedDecl()->setNothrow();
7685 ThisCaptureLevel > 1; --ThisCaptureLevel) {
7686 CS = cast<CapturedStmt>(CS->getCapturedStmt());
7688 // Structured block - An executable statement with a single entry at the
7692 CS->getCapturedDecl()->setNothrow();
7695 return CS;
7709 DSAStack->getTaskgroupReductionRef(), DSAStack->isCancelRegion());
7741 /// non-rectangular loops. Applied only for LCV with the non-iterator types,
7742 /// since only such variables can be used in non-loop invariant expressions.
7745 /// non-rectangular loops. Applied only for LCV with the non-iterator type,
7746 /// since only such variables can be used in non-loop invariant expressions.
7752 /// Index of the loop this loop depends on and forms non-rectangular loop
7755 /// Final condition for the non-rectangular loop nest support. It is used to
7767 /// Does the loop associated directive support non-rectangular loops?
7769 /// Data-sharing stack.
7814 /// non-rectangular loop.
7822 /// Check init-expr for canonical loop form and save loop counter
7823 /// variable - #Var and its initialization value - #LB.
7825 /// Check test-expr for canonical form, save upper-bound (#UB), flags
7826 /// for less/greater and for strict/non-strict comparison.
7828 /// Check incr-expr for canonical loop form and return true if it
7874 /// Builds final condition for the non-rectangular loops.
7878 /// Returns true if the initializer forms non-rectangular loop.
7880 /// Returns true if the condition forms non-rectangular loop.
7888 /// Check the right-hand side of an assignment in the increment
7906 return LCDecl->getType()->isDependentType() ||
7907 (LB && LB->isValueDependent()) || (UB && UB->isValueDependent()) ||
7908 (Step && Step->isValueDependent());
7917 if (!NewLCDecl || !NewLB || NewLB->containsErrors())
7922 if (const CXXConstructorDecl *Ctor = CE->getConstructor())
7923 if ((Ctor->isCopyOrMoveConstructor() ||
7924 Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) &&
7925 CE->getNumArgs() > 0 && CE->getArg(0) != nullptr)
7926 NewLB = CE->getArg(0)->IgnoreParenImpCasts();
7939 if (!NewUB || NewUB->containsErrors())
7954 if (!NewStep || NewStep->containsErrors())
7956 if (!NewStep->isValueDependent()) {
7958 SourceLocation StepLoc = NewStep->getBeginLoc();
7966 // If test-expr is of form var relational-op b and relational-op is < or
7967 // <= then incr-expr must cause var to increase on each iteration of the
7968 // loop. If test-expr is of form var relational-op b and relational-op is
7969 // > or >= then incr-expr must cause var to decrease on each iteration of
7971 // If test-expr is of form b relational-op var and relational-op is < or
7972 // <= then incr-expr must cause var to decrease on each iteration of the
7973 // loop. If test-expr is of form b relational-op var and relational-op is
7974 // > or >= then incr-expr must cause var to increase on each iteration of
7977 NewStep->getIntegerConstantExpr(SemaRef.Context);
7978 bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation();
7980 Result && Result->isSigned() && (Subtract != Result->isNegative());
7982 Result && Result->isSigned() && (Subtract == Result->isNegative());
7983 bool IsConstZero = Result && !Result->getBoolValue();
7991 SemaRef.Diag(NewStep->getExprLoc(),
7993 << LCDecl << *TestIsLessOp << NewStep->getSourceRange();
8001 SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, NewStep)
8013 /// Checker for the non-rectangular loops. Checks if the initializer or
8027 SemaRef.Diag(E->getExprLoc(), diag::err_omp_stmt_depends_on_loop_counter)
8035 if (Data.first && VD->getType()->isRecordType()) {
8038 VD->getNameForDiagnostic(OS, SemaRef.getPrintingPolicy(),
8040 SemaRef.Diag(E->getExprLoc(),
8043 SemaRef.Diag(VD->getLocation(), diag::note_previous_decl) << VD;
8047 SemaRef.Diag(E->getExprLoc(), diag::err_omp_invariant_dependency);
8057 DepDecl->getNameForDiagnostic(OS, SemaRef.getPrintingPolicy(),
8059 SemaRef.Diag(E->getExprLoc(),
8073 const ValueDecl *VD = E->getDecl();
8079 if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) {
8080 const ValueDecl *VD = E->getMemberDecl();
8088 for (const Stmt *Child : S->children())
8113 // Check for the non-rectangular loops.
8124 // Check init-expr for canonical loop form and save loop counter
8125 // variable - #Var and its initialization value - #LB.
8126 // OpenMP [2.6] Canonical loop form. init-expr may be one of the following:
8128 // integer-type var = lb
8129 // random-access-iterator-type var = lb
8130 // pointer-type var = lb
8139 if (!ExprTemp->cleanupsHaveSideEffects())
8140 S = ExprTemp->getSubExpr();
8142 InitSrcRange = S->getSourceRange();
8144 S = E->IgnoreParens();
8146 if (BO->getOpcode() == BO_Assign) {
8147 Expr *LHS = BO->getLHS()->IgnoreParens();
8149 if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl()))
8150 if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit())))
8151 return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS(),
8153 return setLCDeclAndLB(DRE->getDecl(), DRE, BO->getRHS(), EmitDiags);
8156 if (ME->isArrow() &&
8157 isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()))
8158 return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS(),
8163 if (DS->isSingleDecl()) {
8164 if (auto *Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) {
8165 if (Var->hasInit() && !Var->getType()->isReferenceType()) {
8166 // Accept non-canonical init form here but emit ext. warning.
8167 if (Var->getInitStyle() != VarDecl::CInit && EmitDiags)
8168 SemaRef.Diag(S->getBeginLoc(),
8170 << S->getSourceRange();
8174 Var->getType().getNonReferenceType(),
8175 DS->getBeginLoc()),
8176 Var->getInit(), EmitDiags);
8181 if (CE->getOperator() == OO_Equal) {
8182 Expr *LHS = CE->getArg(0);
8184 if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl()))
8185 if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit())))
8186 return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS(),
8188 return setLCDeclAndLB(DRE->getDecl(), DRE, CE->getArg(1), EmitDiags);
8191 if (ME->isArrow() &&
8192 isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()))
8193 return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS(),
8199 if (dependent() || SemaRef.CurContext->isDependentContext())
8202 SemaRef.Diag(S->getBeginLoc(), diag::err_omp_loop_not_canonical_init)
8203 << S->getSourceRange();
8215 if (const CXXConstructorDecl *Ctor = CE->getConstructor())
8216 if ((Ctor->isCopyOrMoveConstructor() ||
8217 Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) &&
8218 CE->getNumArgs() > 0 && CE->getArg(0) != nullptr)
8219 E = CE->getArg(0)->IgnoreParenImpCasts();
8221 if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
8225 if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()))
8226 return getCanonicalDecl(ME->getMemberDecl());
8231 // Check test-expr for canonical form, save upper-bound UB, flags for
8232 // less/greater and for strict/non-strict comparison.
8233 // OpenMP [2.9] Canonical loop form. Test-expr may be one of the following:
8234 // var relational-op b
8235 // b relational-op var
8245 SourceLocation CondLoc = S->getBeginLoc();
8249 SourceLocation OpLoc) -> std::optional<bool> {
8268 CXXRewrittenBinaryOperator::DecomposedForm DF = RBO->getDecomposedForm();
8269 Res = CheckAndSetCond(DF.Opcode, DF.LHS, DF.RHS, RBO->getSourceRange(),
8270 RBO->getOperatorLoc());
8272 Res = CheckAndSetCond(BO->getOpcode(), BO->getLHS(), BO->getRHS(),
8273 BO->getSourceRange(), BO->getOperatorLoc());
8275 if (CE->getNumArgs() == 2) {
8277 BinaryOperator::getOverloadedOpcode(CE->getOperator()), CE->getArg(0),
8278 CE->getArg(1), CE->getSourceRange(), CE->getOperatorLoc());
8283 if (dependent() || SemaRef.CurContext->isDependentContext())
8286 << (IneqCondIsCanonical ? 1 : 0) << S->getSourceRange() << LCDecl;
8294 // var - incr
8296 RHS = RHS->IgnoreParenImpCasts();
8298 if (BO->isAdditiveOp()) {
8299 bool IsAdd = BO->getOpcode() == BO_Add;
8300 if (getInitLCDecl(BO->getLHS()) == LCDecl)
8301 return setStep(BO->getRHS(), !IsAdd);
8302 if (IsAdd && getInitLCDecl(BO->getRHS()) == LCDecl)
8303 return setStep(BO->getLHS(), /*Subtract=*/false);
8306 bool IsAdd = CE->getOperator() == OO_Plus;
8307 if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) {
8308 if (getInitLCDecl(CE->getArg(0)) == LCDecl)
8309 return setStep(CE->getArg(1), !IsAdd);
8310 if (IsAdd && getInitLCDecl(CE->getArg(1)) == LCDecl)
8311 return setStep(CE->getArg(0), /*Subtract=*/false);
8314 if (dependent() || SemaRef.CurContext->isDependentContext())
8316 SemaRef.Diag(RHS->getBeginLoc(), diag::err_omp_loop_not_canonical_incr)
8317 << RHS->getSourceRange() << LCDecl;
8322 // Check incr-expr for canonical loop form and return true if it
8324 // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following:
8327 // --var
8328 // var--
8330 // var -= incr
8333 // var = var - incr
8340 if (!ExprTemp->cleanupsHaveSideEffects())
8341 S = ExprTemp->getSubExpr();
8343 IncrementSrcRange = S->getSourceRange();
8344 S = S->IgnoreParens();
8346 if (UO->isIncrementDecrementOp() &&
8347 getInitLCDecl(UO->getSubExpr()) == LCDecl)
8349 .ActOnIntegerConstant(UO->getBeginLoc(),
8350 (UO->isDecrementOp() ? -1 : 1))
8354 switch (BO->getOpcode()) {
8357 if (getInitLCDecl(BO->getLHS()) == LCDecl)
8358 return setStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign);
8361 if (getInitLCDecl(BO->getLHS()) == LCDecl)
8362 return checkAndSetIncRHS(BO->getRHS());
8368 switch (CE->getOperator()) {
8371 if (getInitLCDecl(CE->getArg(0)) == LCDecl)
8374 CE->getBeginLoc(),
8375 ((CE->getOperator() == OO_MinusMinus) ? -1 : 1))
8381 if (getInitLCDecl(CE->getArg(0)) == LCDecl)
8382 return setStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual);
8385 if (getInitLCDecl(CE->getArg(0)) == LCDecl)
8386 return checkAndSetIncRHS(CE->getArg(1));
8392 if (dependent() || SemaRef.CurContext->isDependentContext())
8394 SemaRef.Diag(S->getBeginLoc(), diag::err_omp_loop_not_canonical_incr)
8395 << S->getSourceRange() << LCDecl;
8403 if (SemaRef.CurContext->isDependentContext() || Capture->containsErrors())
8405 if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects))
8407 Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting,
8411 return buildCapture(SemaRef, Capture, I->second, Name);
8431 Lower->getIntegerConstantExpr(SemaRef.Context)) {
8436 Step->getIntegerConstantExpr(SemaRef.Context)) {
8444 // Check if any subexpressions in Lower -Step [+ 1] lead to overflow.
8456 LRes -= SRes;
8475 Upper->getIntegerConstantExpr(SemaRef.Context)) {
8487 URes -= LRes;
8491 // If the boundaries are not constant or (Lower - Step [+ 1]) is not constant
8492 // or less than zero (Upper - (Lower - Step [+ 1]) may overflow) - promote to
8495 !LCTy->isDependentType() && LCTy->isIntegerType()) {
8496 QualType LowerTy = Lower->getType();
8497 QualType UpperTy = Upper->getType();
8500 if ((LowerSize <= UpperSize && UpperTy->hasSignedIntegerRepresentation()) ||
8501 (LowerSize > UpperSize && LowerTy->hasSignedIntegerRepresentation())) {
8518 // If need to reorganize, then calculate the form as Upper - (Lower - Step [+
8524 // Lower - Step
8531 // Lower - Step [+ 1]
8543 // Upper - (Lower - Step [+ 1]).
8550 if (!Diff.isUsable() && LCTy->getAsCXXRecordDecl()) {
8552 // and lower bound, and to tell what is passed to 'operator-'.
8553 SemaRef.Diag(Upper->getBeginLoc(), diag::err_omp_loop_diff_cxx)
8554 << Upper->getSourceRange() << Lower->getSourceRange();
8561 // Upper - Lower [- 1]
8570 // Upper - Lower [- 1] + Step
8583 // (Upper - Lower [- 1] + Step) / Step or (Upper - Lower) / Step
8595 QualType VarType = LCDecl->getType().getNonReferenceType();
8596 if (!VarType->isIntegerType() && !VarType->isPointerType() &&
8604 const LoopIterationSpace &IS = ResultIterSpaces[*InitDependOnLC - 1];
8664 // LB(MinVal) < LB(MaxVal) ? LB(MinVal) : LB(MaxVal) - min(LB(MinVal),
8672 // LB(MinVal) < LB(MaxVal) ? LB(MaxVal) : LB(MinVal) - max(LB(MinVal),
8690 const LoopIterationSpace &IS = ResultIterSpaces[*CondDependOnLC - 1];
8750 // UB(MinVal) > UB(MaxVal) ? UB(MinVal) : UB(MaxVal) - max(UB(MinVal),
8758 // UB(MinVal) > UB(MaxVal) ? UB(MaxVal) : UB(MinVal) - min(UB(MinVal),
8780 // OpenMP runtime requires 32-bit or 64-bit loop variables.
8781 QualType Type = Diff.get()->getType();
8783 bool UseVarType = VarType->hasIntegerRepresentation() &&
8785 if (!Type->isIntegerType() || UseVarType) {
8788 bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation()
8789 : Type->hasSignedIntegerRepresentation();
8791 if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) {
8807 NewSize, Type->hasSignedIntegerRepresentation() ||
8809 if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) {
8823 // Do not build for iterators, they cannot be used in non-rectangular loop
8825 if (LCDecl->getType()->isRecordType())
8850 QualType VarType = LCDecl->getType().getNonReferenceType();
8858 // ((Upper - Lower [- 1]) / Step) * Step
8877 if (VarType->isAnyPointerType() &&
8879 Diff.get()->getType(),
8890 // MaxExpr = Lower + (((Upper - Lower [- 1]) / Step) * Step)
8899 // MinExpr = Upper - (((Upper - Lower [- 1]) / Step) * Step)
8909 if (SemaRef.Context.hasSameType(Diff.get()->getType(), VarType))
8964 if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(),
8983 SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc);
8996 if (LCDecl && !LCDecl->isInvalidDecl()) {
8997 QualType Type = LCDecl->getType().getNonReferenceType();
8999 SemaRef, DefaultLoc, Type, LCDecl->getName(),
9000 LCDecl->hasAttrs() ? &LCDecl->getAttrs() : nullptr,
9004 if (PrivateVar->isInvalidDecl())
9026 "Expected only + or - operations for depend clauses.");
9032 QualType VarType = LCDecl->getType().getNonReferenceType();
9033 if (!VarType->isIntegerType() && !VarType->isPointerType() &&
9036 // Upper - Lower
9058 unsigned AssociatedLoops = DSAStack->getAssociatedLoops();
9059 OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
9063 DSAStack->loopStart();
9076 VD = cast<VarDecl>(PrivateRef->getDecl());
9079 DSAStack->addLoopControlVariable(D, VD);
9080 const Decl *LD = DSAStack->getPossiblyLoopCounter();
9081 if (LD != D->getCanonicalDecl()) {
9082 DSAStack->resetPossibleLoopCounter();
9086 Var->getType().getNonLValueExprType(getASTContext()), ForLoc,
9089 // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables
9091 // associated for-loop of a simd construct with just one associated
9092 // for-loop may be listed in a linear clause with a constant-linear-step
9093 // that is the increment of the associated for-loop. The loop iteration
9094 // variable(s) in the associated for-loop(s) of a for or parallel for
9097 DSAStack->getTopDSA(D, /*FromParent=*/false);
9103 ? (DSAStack->hasMutipleLoops() ? OMPC_lastprivate : OMPC_linear)
9118 Diag(Init->getBeginLoc(), diag::err_omp_loop_var_dsa)
9130 DSAStack->addDSA(D, LoopDeclRefExpr, PredeterminedCKind, PrivateRef);
9134 DSAStack->setAssociatedLoops(AssociatedLoops - 1);
9142 return C->getDependenceType() == OMPC_DOACROSS_source ||
9143 C->getDependenceType() == OMPC_DOACROSS_source_omp_cur_iteration;
9146 return C->getDependenceType() == OMPC_DOACROSS_sink;
9149 return C->getDependenceType() == OMPC_DOACROSS_sink_omp_cur_iteration;
9165 // for (init-expr; test-expr; incr-expr) structured-block
9166 // for (range-decl: range-expr) structured-block
9168 S = CanonLoop->getLoopStmt();
9177 SemaRef.Diag(S->getBeginLoc(), diag::err_omp_not_for)
9185 << 2 << CollapseLoopCountExpr->getSourceRange()
9186 << OrderedLoopCountExpr->getSourceRange();
9188 SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(),
9190 << 0 << CollapseLoopCountExpr->getSourceRange();
9192 SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(),
9194 << 1 << OrderedLoopCountExpr->getSourceRange();
9198 assert(((For && For->getBody()) || (CXXFor && CXXFor->getBody())) &&
9201 if (CXXFor && SemaRef.CurContext->isDependentContext())
9205 For ? For->getForLoc() : CXXFor->getForLoc());
9208 Stmt *Init = For ? For->getInit() : CXXFor->getBeginStmt();
9221 QualType VarType = LCDecl->getType().getNonReferenceType();
9222 if (!VarType->isDependentType() && !VarType->isIntegerType() &&
9223 !VarType->isPointerType() &&
9224 !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) {
9225 SemaRef.Diag(Init->getBeginLoc(), diag::err_omp_loop_variable_type)
9230 // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in
9232 // The loop iteration variable(s) in the associated for-loop(s) of a for or
9234 // The loop iteration variable in the associated for-loop of a simd
9235 // construct with just one associated for-loop is linear with a
9236 // constant-linear-step that is the increment of the associated for-loop.
9241 assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars");
9243 // Check test-expr.
9244 HasErrors |= ISC.checkAndSetCond(For ? For->getCond() : CXXFor->getCond());
9246 // Check incr-expr.
9247 HasErrors |= ISC.checkAndSetInc(For ? For->getInc() : CXXFor->getInc());
9250 if (ISC.dependent() || SemaRef.CurContext->isDependentContext() || HasErrors)
9255 DSA.getCurScope(), For ? For->getCond() : CXXFor->getCond(), Captures);
9298 if (DSA.getOrderedRegionParam().second->getNumForLoops()) {
9300 DSA.getOrderedRegionParam().second->getLoopNumIterations().size()) {
9301 DSA.getOrderedRegionParam().second->setLoopNumIterations(
9304 DSA.getOrderedRegionParam().second->setLoopCounter(
9313 DependC ? DependC->getNumLoops() : DoacrossC->getNumLoops();
9315 // Erroneous case - clause has some problems.
9318 if (DependC && DependC->getDependencyKind() == OMPC_DEPEND_sink &&
9320 // Erroneous case - clause has some problems.
9321 DependC->setLoopData(CurrentNestedLoopCount, nullptr);
9327 // Erroneous case - clause has some problems.
9328 DoacrossC->setLoopData(CurrentNestedLoopCount, nullptr);
9333 DependC ? DependC->getDependencyLoc() : DoacrossC->getDependenceLoc();
9334 if ((DependC && DependC->getDependencyKind() == OMPC_DEPEND_source) ||
9347 // build CounterVar - 1
9349 SemaRef.ActOnIntegerConstant(DoacrossC->getColonLoc(), /*Val=*/1)
9362 DependC->setLoopData(CurrentNestedLoopCount, CntValue);
9364 DoacrossC->setLoopData(CurrentNestedLoopCount, CntValue);
9382 if (!SemaRef.Context.hasSameType(NewStart.get()->getType(),
9383 VarRef.get()->getType())) {
9385 NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting,
9418 // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or
9419 // 'VarRef = Start (+|-) Iter * Step'.
9433 if (VarRef.get()->getType()->isOverloadableType() ||
9434 NewStart.get()->getType()->isOverloadableType() ||
9435 Update.get()->getType()->isOverloadableType()) {
9451 // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'.
9458 if (!SemaRef.Context.hasSameType(Update.get()->getType(),
9459 VarRef.get()->getType())) {
9461 Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true);
9477 QualType OldType = E->getType();
9493 E->getIntegerConstantExpr(SemaRef.Context))
9494 return Signed ? Result->isSignedIntN(Bits) : Result->isIntN(Bits);
9515 /// for OpenMP pre-init declarations/statements.
9522 if (auto *CS = dyn_cast<CompoundStmt>(Item))
9523 llvm::append_range(TargetList, CS->body());
9535 PreInits.push_back(Pair.second->getDecl());
9541 /// Build pre-init statement for the given statements.
9558 E->getExprLoc(),
9560 E->getExprLoc(), E)
9563 ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma,
9586 // Found 'collapse' clause - calculate collapse number.
9588 if (!CollapseLoopCountExpr->isValueDependent() &&
9589 CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) {
9598 // Found 'ordered' clause - calculate collapse number.
9600 if (!OrderedLoopCountExpr->isValueDependent() &&
9601 OrderedLoopCountExpr->EvaluateAsInt(EVResult,
9605 SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(),
9607 << OrderedLoopCountExpr->getSourceRange();
9608 SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(),
9610 << CollapseLoopCountExpr->getSourceRange();
9624 AStmt->IgnoreContainers(!isOpenMPLoopTransformationDirective(DKind)),
9638 if (isa<OMPCapturedExprDecl>(DRE->getDecl())) {
9645 Stmt *DependentPreInits = Transform->getPreInits();
9649 // Search for pre-init declared variables that need to be captured
9655 for (Decl *C : DC->decls()) {
9658 SemaRef, D, D->getType().getNonReferenceType(),
9659 Transform->getBeginLoc());
9669 if (SemaRef.CurContext->isDependentContext())
9683 // Note: some counters may be C++ classes, operator- is used to find number of
9688 // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2))
9690 // .local.i = IV / ((NJ - J0 - 1 + 2) / 2);
9691 // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2;
9699 // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are
9709 N0->IgnoreImpCasts(), N0->getType(),
9716 .PerformImplicitConversion(N0->IgnoreImpCasts(), N0->getType(),
9726 bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32;
9732 SemaRef.BuildBinOp(CurScope, PreCond.get()->getExprLoc(), BO_LAnd,
9736 SourceLocation Loc = N->getExprLoc();
9737 AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32;
9742 .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(),
9750 .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(),
9756 // Choose either the 32-bit or 64-bit version.
9760 C.getTypeSize(LastIteration32.get()->getType()) == 32 &&
9764 LastIteration32.get()->getType()->hasSignedIntegerRepresentation(),
9767 QualType VType = LastIteration.get()->getType();
9784 CurScope, LastIteration.get()->getExprLoc(), BO_Sub,
9792 // each iteration. Do not do this if the number of iterations may be kfold-ed.
9793 bool IsConstant = LastIteration.get()->isIntegerConstantExpr(SemaRef.Context);
9802 CurScope, SaveRef.get()->getExprLoc(), BO_Add, SaveRef.get(),
9829 // A 32-bit variable-flag where runtime returns 1 for the last iteration.
9851 LastIteration.get()->getExprLoc(), InitLoc, IsUBGreater.get(),
9887 const CapturedDecl *CD = cast<CapturedStmt>(AStmt)->getCapturedDecl();
9889 // directive does - the lower and upper bounds of the previous schedule.
9890 assert(CD->getNumParams() >= 4 &&
9895 ImplicitParamDecl *PrevLBDecl = CD->getParam(/*PrevLB=*/2);
9896 ImplicitParamDecl *PrevUBDecl = CD->getParam(/*PrevUB=*/3);
9901 buildDeclRefExpr(SemaRef, PrevLBDecl, PrevLBDecl->getType(), InitLoc);
9903 buildDeclRefExpr(SemaRef, PrevUBDecl, PrevUBDecl->getType(), InitLoc);
9939 RealVType->hasUnsignedIntegerRepresentation() &&
9945 SourceLocation CondLoc = AStmt->getBeginLoc();
9991 SourceLocation IncLoc = AStmt->getBeginLoc();
10062 // on PrevUB instead of NumIterations - used to implement 'for' when found
10064 SourceLocation DistIncLoc = AStmt->getBeginLoc();
10083 SourceLocation DistEUBLoc = AStmt->getBeginLoc();
10084 if (!SemaRef.Context.hasSameType(UB.get()->getType(),
10085 PrevUB.get()->getType())) {
10088 SemaRef.Context.getTrivialTypeSourceInfo(UB.get()->getType()),
10145 // Acc -= Ik * Prod;
10173 // Acc -= Iter * Prod
10184 auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl());
10186 SemaRef, VD, IS.CounterVar->getType(), IS.CounterVar->getExprLoc(),
10227 Built.DependentCounters[Cnt] = Built.Counters[IS.LoopDependentIdx - 1];
10228 Built.DependentInits[Cnt] = Built.Inits[IS.LoopDependentIdx - 1];
10278 return (*CollapseClauses.begin())->getNumForLoops();
10286 return (*OrderedClauses.begin())->getNumForLoops();
10296 if (Clause->getClauseKind() == OMPC_safelen)
10298 else if (Clause->getClauseKind() == OMPC_simdlen)
10305 const Expr *SimdlenLength = Simdlen->getSimdlen();
10306 const Expr *SafelenLength = Safelen->getSafelen();
10307 if (SimdlenLength->isValueDependent() || SimdlenLength->isTypeDependent() ||
10308 SimdlenLength->isInstantiationDependent() ||
10309 SimdlenLength->containsUnexpandedParameterPack())
10311 if (SafelenLength->isValueDependent() || SafelenLength->isTypeDependent() ||
10312 SafelenLength->isInstantiationDependent() ||
10313 SafelenLength->containsUnexpandedParameterPack())
10316 SimdlenLength->EvaluateAsInt(SimdlenResult, S.Context);
10317 SafelenLength->EvaluateAsInt(SafelenResult, S.Context);
10325 S.Diag(SimdlenLength->getExprLoc(),
10327 << SimdlenLength->getSourceRange() << SafelenLength->getSourceRange();
10346 DSAStack->getMappedDirective() == OMPD_loop &&
10381 DSAStack->getMappedDirective());
10409 DSAStack->getTaskgroupReductionRef(), DSAStack->isCancelRegion(),
10410 DSAStack->getMappedDirective());
10449 while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt))
10450 BaseStmt = CS->getCapturedStmt();
10452 auto S = C->children();
10460 SemaRef.Diag(SectionStmt->getBeginLoc(),
10466 ->setHasCancel(Stack->isCancelRegion());
10469 SemaRef.Diag(AStmt->getBeginLoc(), diag::err_omp_sections_not_compound_stmt)
10487 DSAStack->getTaskgroupReductionRef(), DSAStack->isCancelRegion());
10497 DSAStack->setParentCancelRegion(DSAStack->isCancelRegion());
10500 DSAStack->isCancelRegion());
10504 E = E->IgnoreParenCasts()->IgnoreImplicit();
10506 if (CE->getDirectCallee())
10518 Stmt *S = cast<CapturedStmt>(AStmt)->getCapturedStmt();
10521 // expression-stmt : an expression statement with one of the following forms:
10522 // expression = target-call ( [expression-list] );
10523 // target-call ( [expression-list] );
10527 if (!SemaRef.CurContext->isDependentContext()) {
10532 Diag(S->getBeginLoc(), diag::err_omp_dispatch_statement_call);
10536 E = E->IgnoreParenCasts()->IgnoreImplicit();
10539 if (BO->getOpcode() == BO_Assign)
10540 TargetCall = getDirectCallExpr(BO->getRHS());
10543 if (COCE->getOperator() == OO_Equal)
10544 TargetCall = getDirectCallExpr(COCE->getArg(1));
10549 Diag(E->getBeginLoc(), diag::err_omp_dispatch_statement_call);
10552 TargetCallLoc = TargetCall->getExprLoc();
10567 for (Expr *RefExpr : LPC->varlists()) {
10573 auto &&Info = Stack->isLoopControlVariable(D);
10608 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
10627 CapturedStmt *CS = setBranchProtectedScope(SemaRef, OMPD_teams_loop, AStmt);
10633 /*OrderedLoopCountExpr=*/nullptr, CS, SemaRef, *DSAStack,
10638 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
10641 DSAStack->setParentTeamsRegionLoc(StartLoc);
10660 CapturedStmt *CS =
10667 /*OrderedLoopCountExpr=*/nullptr, CS, SemaRef, *DSAStack,
10672 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
10693 CapturedStmt *CS =
10700 /*OrderedLoopCountExpr=*/nullptr, CS, SemaRef, *DSAStack,
10705 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
10725 CapturedStmt *CS =
10732 /*OrderedLoopCountExpr=*/nullptr, CS, SemaRef, *DSAStack,
10737 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
10760 if (Clause->getClauseKind() == OMPC_nowait)
10762 else if (Clause->getClauseKind() == OMPC_copyprivate)
10765 Diag(Copyprivate->getBeginLoc(),
10767 Diag(Nowait->getBeginLoc(), diag::note_omp_nowait_clause_here);
10811 if (C->getClauseKind() == OMPC_hint) {
10813 Diag(C->getBeginLoc(), diag::err_omp_hint_clause_no_name);
10816 Expr *E = cast<OMPHintClause>(C)->getHint();
10817 if (E->isTypeDependent() || E->isValueDependent() ||
10818 E->isInstantiationDependent()) {
10821 Hint = E->EvaluateKnownConstInt(getASTContext());
10822 HintLoc = C->getBeginLoc();
10828 const auto Pair = DSAStack->getCriticalWithHint(DirName);
10837 if (const auto *C = Pair.first->getSingleClause<OMPHintClause>()) {
10838 Diag(C->getBeginLoc(), diag::note_omp_critical_hint_here)
10840 << toString(C->getHint()->EvaluateKnownConstInt(getASTContext()),
10843 Diag(Pair.first->getBeginLoc(), diag::note_omp_critical_no_hint) << 1;
10853 DSAStack->addCriticalWithHint(Dir, Hint);
10880 DSAStack->getTaskgroupReductionRef(), DSAStack->isCancelRegion());
10921 DSAStack->getTaskgroupReductionRef());
10934 DSAStack->getTaskgroupReductionRef());
10947 DSAStack->getTaskgroupReductionRef(), DSAStack->isCancelRegion());
10957 if (llvm::is_contained(MutuallyExclusiveClauses, C->getClauseKind())) {
10960 } else if (PrevClause->getClauseKind() != C->getClauseKind()) {
10961 S.Diag(C->getBeginLoc(), diag::err_omp_clauses_mutually_exclusive)
10962 << getOpenMPClauseName(C->getClauseKind())
10963 << getOpenMPClauseName(PrevClause->getClauseKind());
10964 S.Diag(PrevClause->getBeginLoc(), diag::note_omp_previous_clause)
10965 << getOpenMPClauseName(PrevClause->getClauseKind());
10990 AStmt, DSAStack->isCancelRegion());
11010 if (AtC && !InExContext && AtC->getAtKind() == OMPC_AT_execution) {
11011 Diag(AtC->getAtKindKwLoc(), diag::err_omp_unexpected_execution_modifier);
11019 Expr *ME = MessageC ? MessageC->getMessageString() : nullptr;
11021 if (!AtC || AtC->getAtKind() == OMPC_AT_compilation) {
11022 if (SeverityC && SeverityC->getSeverityKind() == OMPC_SEVERITY_warning)
11023 Diag(SeverityC->getSeverityKindKwLoc(), diag::warn_diagnose_if_succeeded)
11024 << (ME ? cast<StringLiteral>(ME)->getString() : "WARNING");
11027 << (ME ? cast<StringLiteral>(ME)->getString() : "ERROR");
11028 if (!SeverityC || SeverityC->getSeverityKind() != OMPC_SEVERITY_warning)
11065 DSAStack->getTaskgroupReductionRef());
11074 if (C->getClauseKind() == OMPC_flush)
11082 if (C->getClauseKind() == OMPC_acq_rel ||
11083 C->getClauseKind() == OMPC_acquire ||
11084 C->getClauseKind() == OMPC_release) {
11086 Diag(C->getBeginLoc(), diag::err_omp_several_mem_order_clauses)
11088 << SourceRange(C->getBeginLoc(), C->getEndLoc());
11092 MemOrderKind = C->getClauseKind();
11093 MemOrderLoc = C->getBeginLoc();
11098 Diag(FC->getLParenLoc(), diag::err_omp_flush_order_clause_and_list)
11099 << getOpenMPClauseName(OrderClause->getClauseKind());
11100 Diag(OrderClause->getBeginLoc(), diag::note_omp_flush_order_clause_here)
11101 << getOpenMPClauseName(OrderClause->getClauseKind());
11113 } else if (Clauses[0]->getClauseKind() != OMPC_depobj) {
11114 Diag(Clauses[0]->getBeginLoc(), diag::err_omp_depobj_expected);
11119 Diag(Clauses[2]->getBeginLoc(),
11123 Diag(Clauses[0]->getEndLoc(), diag::err_omp_depobj_single_clause_expected);
11134 Diag(Clauses.empty() ? EndLoc : Clauses[1]->getBeginLoc(),
11139 if (Scope *S = DSAStack->getCurScope()) {
11140 Scope *ParentS = S->getParent();
11141 if (!ParentS || ParentS->getParent() != ParentS->getBreakParent() ||
11142 !ParentS->getBreakParent()->isOpenMPLoopScope())
11148 if (DSAStack->doesParentHasScanDirective()) {
11150 Diag(DSAStack->getParentScanDirectiveLoc(),
11155 DSAStack->setParentHasScanDirective(StartLoc);
11179 if ((DC && DC->getDependencyKind() == OMPC_DEPEND_source) ||
11182 Diag(C->getBeginLoc(), diag::err_omp_more_one_clause)
11193 Diag(C->getBeginLoc(), diag::err_omp_sink_and_source_not_allowed)
11197 } else if ((DC && DC->getDependencyKind() == OMPC_DEPEND_sink) ||
11200 Diag(C->getBeginLoc(), diag::err_omp_sink_and_source_not_allowed)
11209 } else if (C->getClauseKind() == OMPC_threads) {
11211 } else if (C->getClauseKind() == OMPC_simd) {
11216 isOpenMPSimdDirective(DSAStack->getParentDirective())) {
11225 DependFound ? DependFound->getBeginLoc() : DoacrossFound->getBeginLoc();
11228 << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind());
11231 !DSAStack->getParentOrderedRegionParam().first) {
11233 DependFound ? DependFound->getBeginLoc() : DoacrossFound->getBeginLoc();
11238 if (const Expr *Param = DSAStack->getParentOrderedRegionParam().first) {
11239 SourceLocation ErrLoc = TC ? TC->getBeginLoc() : StartLoc;
11242 Diag(Param->getBeginLoc(), diag::note_omp_ordered_param) << 1;
11250 // During execution of an iteration of a worksharing-loop or a loop nest
11251 // within a worksharing-loop, simd, or worksharing-loop SIMD region, a thread
11255 if (DSAStack->doesParentHasOrderedDirective()) {
11257 Diag(DSAStack->getParentOrderedDirectiveLoc(),
11262 DSAStack->setParentHasOrderedDirective(StartLoc);
11285 /// Unary operation is not post-/pre- increment/decrement operation.
11318 /// important for non-associative operations.
11367 if (AtomicBinOp->getOpcode() == BO_Assign) {
11368 X = AtomicBinOp->getLHS();
11370 AtomicBinOp->getRHS()->IgnoreParenImpCasts())) {
11371 if (AtomicInnerBinOp->isMultiplicativeOp() ||
11372 AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() ||
11373 AtomicInnerBinOp->isBitwiseOp()) {
11374 Op = AtomicInnerBinOp->getOpcode();
11375 OpLoc = AtomicInnerBinOp->getOperatorLoc();
11376 Expr *LHS = AtomicInnerBinOp->getLHS();
11377 Expr *RHS = AtomicInnerBinOp->getRHS();
11379 X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(),
11381 LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(),
11383 RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(),
11392 ErrorLoc = AtomicInnerBinOp->getExprLoc();
11393 ErrorRange = AtomicInnerBinOp->getSourceRange();
11394 NoteLoc = X->getExprLoc();
11395 NoteRange = X->getSourceRange();
11399 ErrorLoc = AtomicInnerBinOp->getExprLoc();
11400 ErrorRange = AtomicInnerBinOp->getSourceRange();
11401 NoteLoc = AtomicInnerBinOp->getOperatorLoc();
11406 NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc();
11407 NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange();
11411 ErrorLoc = AtomicBinOp->getExprLoc();
11412 ErrorRange = AtomicBinOp->getSourceRange();
11413 NoteLoc = AtomicBinOp->getOperatorLoc();
11422 if (SemaRef.CurContext->isDependentContext())
11434 // x--;
11436 // --x;
11441 AtomicBody = AtomicBody->IgnoreParenImpCasts();
11442 if (AtomicBody->getType()->isScalarType() ||
11443 AtomicBody->isInstantiationDependent()) {
11445 AtomicBody->IgnoreParenImpCasts())) {
11448 AtomicCompAssignOp->getOpcode());
11449 OpLoc = AtomicCompAssignOp->getOperatorLoc();
11450 E = AtomicCompAssignOp->getRHS();
11451 X = AtomicCompAssignOp->getLHS()->IgnoreParens();
11454 AtomicBody->IgnoreParenImpCasts())) {
11459 AtomicBody->IgnoreParenImpCasts())) {
11461 if (AtomicUnaryOp->isIncrementDecrementOp()) {
11462 IsPostfixUpdate = AtomicUnaryOp->isPostfix();
11463 Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub;
11464 OpLoc = AtomicUnaryOp->getOperatorLoc();
11465 X = AtomicUnaryOp->getSubExpr()->IgnoreParens();
11470 ErrorLoc = AtomicUnaryOp->getExprLoc();
11471 ErrorRange = AtomicUnaryOp->getSourceRange();
11472 NoteLoc = AtomicUnaryOp->getOperatorLoc();
11475 } else if (!AtomicBody->isInstantiationDependent()) {
11477 NoteLoc = ErrorLoc = AtomicBody->getExprLoc();
11478 NoteRange = ErrorRange = AtomicBody->getSourceRange();
11479 } else if (AtomicBody->containsErrors()) {
11481 NoteLoc = ErrorLoc = AtomicBody->getExprLoc();
11482 NoteRange = ErrorRange = AtomicBody->getSourceRange();
11486 NoteLoc = ErrorLoc = AtomicBody->getBeginLoc();
11491 NoteLoc = ErrorLoc = S->getBeginLoc();
11499 if (SemaRef.CurContext->isDependentContext())
11506 OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_PRValue);
11508 OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_PRValue);
11514 Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(),
11526 S->IgnoreParenImpCasts()->Profile(Id, Context, true);
11621 /// Check if it is a valid conditional update statement (cond-update-stmt).
11624 /// Check if it is a valid conditional expression statement (cond-expr-stmt).
11632 if (E->isInstantiationDependent())
11635 if (ShouldBeLValue && !E->isLValue()) {
11637 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
11638 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = E->getSourceRange();
11642 QualType QTy = E->getType();
11643 if (!QTy->isScalarType()) {
11645 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
11646 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = E->getSourceRange();
11649 if (ShouldBeInteger && !QTy->isIntegerType()) {
11651 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
11652 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = E->getSourceRange();
11662 auto *Then = S->getThen();
11663 if (auto *CS = dyn_cast<CompoundStmt>(Then)) {
11664 if (CS->body_empty()) {
11666 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = CS->getBeginLoc();
11667 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = CS->getSourceRange();
11670 if (CS->size() > 1) {
11672 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = CS->getBeginLoc();
11673 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = S->getSourceRange();
11676 Then = CS->body_front();
11682 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Then->getBeginLoc();
11683 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = Then->getSourceRange();
11686 if (BO->getOpcode() != BO_Assign) {
11688 ErrorInfo.ErrorLoc = BO->getExprLoc();
11689 ErrorInfo.NoteLoc = BO->getOperatorLoc();
11690 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = BO->getSourceRange();
11694 X = BO->getLHS();
11696 auto *Cond = dyn_cast<BinaryOperator>(S->getCond());
11699 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = S->getCond()->getExprLoc();
11700 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = S->getCond()->getSourceRange();
11704 switch (Cond->getOpcode()) {
11707 D = BO->getRHS();
11708 if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS())) {
11709 E = Cond->getRHS();
11710 } else if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getRHS())) {
11711 E = Cond->getLHS();
11714 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Cond->getExprLoc();
11715 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = Cond->getSourceRange();
11722 E = BO->getRHS();
11723 if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS()) &&
11724 checkIfTwoExprsAreSame(ContextRef, E, Cond->getRHS())) {
11726 } else if (checkIfTwoExprsAreSame(ContextRef, E, Cond->getLHS()) &&
11727 checkIfTwoExprsAreSame(ContextRef, X, Cond->getRHS())) {
11732 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Cond->getExprLoc();
11733 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = Cond->getSourceRange();
11740 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Cond->getExprLoc();
11741 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = Cond->getSourceRange();
11745 if (S->getElse()) {
11747 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = S->getElse()->getBeginLoc();
11748 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = S->getElse()->getSourceRange();
11760 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = S->getBeginLoc();
11761 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = S->getSourceRange();
11764 if (BO->getOpcode() != BO_Assign) {
11766 ErrorInfo.ErrorLoc = BO->getExprLoc();
11767 ErrorInfo.NoteLoc = BO->getOperatorLoc();
11768 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = BO->getSourceRange();
11772 X = BO->getLHS();
11774 auto *CO = dyn_cast<ConditionalOperator>(BO->getRHS()->IgnoreParenImpCasts());
11777 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = BO->getRHS()->getExprLoc();
11778 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = BO->getRHS()->getSourceRange();
11782 if (!checkIfTwoExprsAreSame(ContextRef, X, CO->getFalseExpr())) {
11784 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = CO->getFalseExpr()->getExprLoc();
11786 CO->getFalseExpr()->getSourceRange();
11790 auto *Cond = dyn_cast<BinaryOperator>(CO->getCond());
11793 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = CO->getCond()->getExprLoc();
11795 CO->getCond()->getSourceRange();
11799 switch (Cond->getOpcode()) {
11802 D = CO->getTrueExpr();
11803 if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS())) {
11804 E = Cond->getRHS();
11805 } else if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getRHS())) {
11806 E = Cond->getLHS();
11809 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Cond->getExprLoc();
11810 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = Cond->getSourceRange();
11817 E = CO->getTrueExpr();
11818 if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS()) &&
11819 checkIfTwoExprsAreSame(ContextRef, E, Cond->getRHS())) {
11821 } else if (checkIfTwoExprsAreSame(ContextRef, E, Cond->getLHS()) &&
11822 checkIfTwoExprsAreSame(ContextRef, X, Cond->getRHS())) {
11827 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Cond->getExprLoc();
11828 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = Cond->getSourceRange();
11835 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Cond->getExprLoc();
11836 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = Cond->getSourceRange();
11861 auto *CS = dyn_cast<CompoundStmt>(S);
11862 if (CS) {
11863 if (CS->body_empty()) {
11865 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = CS->getBeginLoc();
11866 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = CS->getSourceRange();
11870 if (CS->size() != 1) {
11872 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = CS->getBeginLoc();
11873 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = CS->getSourceRange();
11876 S = CS->body_front();
11883 // (cond-update-stmt):
11889 // Check if the statement is in one of the following forms (cond-expr-stmt):
11919 // form of 'conditional-update-capture-atomic' structured block on the v5.2
11921 // (1) { v = x; cond-update-stmt }
11922 // (2) { cond-update-stmt v = x; }
11961 auto *Then = S->getThen();
11962 if (auto *CS = dyn_cast<CompoundStmt>(Then)) {
11963 if (CS->body_empty()) {
11965 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = CS->getBeginLoc();
11966 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = CS->getSourceRange();
11969 if (CS->size() > 1) {
11971 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = CS->getBeginLoc();
11972 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = CS->getSourceRange();
11975 Then = CS->body_front();
11981 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Then->getBeginLoc();
11982 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = Then->getSourceRange();
11985 if (BO->getOpcode() != BO_Assign) {
11987 ErrorInfo.ErrorLoc = BO->getExprLoc();
11988 ErrorInfo.NoteLoc = BO->getOperatorLoc();
11989 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = BO->getSourceRange();
11993 X = BO->getLHS();
11994 D = BO->getRHS();
11996 auto *Cond = dyn_cast<BinaryOperator>(S->getCond());
11999 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = S->getCond()->getExprLoc();
12000 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = S->getCond()->getSourceRange();
12003 if (Cond->getOpcode() != BO_EQ) {
12005 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Cond->getExprLoc();
12006 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = Cond->getSourceRange();
12010 if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS())) {
12011 E = Cond->getRHS();
12012 } else if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getRHS())) {
12013 E = Cond->getLHS();
12016 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Cond->getExprLoc();
12017 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = Cond->getSourceRange();
12023 if (!S->getElse()) {
12025 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = S->getBeginLoc();
12026 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = S->getSourceRange();
12030 auto *Else = S->getElse();
12031 if (auto *CS = dyn_cast<CompoundStmt>(Else)) {
12032 if (CS->body_empty()) {
12034 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = CS->getBeginLoc();
12035 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = CS->getSourceRange();
12038 if (CS->size() > 1) {
12040 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = CS->getBeginLoc();
12041 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = S->getSourceRange();
12044 Else = CS->body_front();
12050 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Else->getBeginLoc();
12051 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = Else->getSourceRange();
12054 if (ElseBO->getOpcode() != BO_Assign) {
12056 ErrorInfo.ErrorLoc = ElseBO->getExprLoc();
12057 ErrorInfo.NoteLoc = ElseBO->getOperatorLoc();
12058 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = ElseBO->getSourceRange();
12062 if (!checkIfTwoExprsAreSame(ContextRef, X, ElseBO->getRHS())) {
12064 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = ElseBO->getRHS()->getExprLoc();
12066 ElseBO->getRHS()->getSourceRange();
12070 V = ElseBO->getLHS();
12079 auto *CS = cast<CompoundStmt>(S);
12080 assert(CS->size() == 2 && "CompoundStmt size is not expected");
12081 auto *S1 = cast<BinaryOperator>(CS->body_front());
12082 auto *S2 = cast<IfStmt>(CS->body_back());
12083 assert(S1->getOpcode() == BO_Assign && "unexpected binary operator");
12085 if (!checkIfTwoExprsAreSame(ContextRef, S1->getLHS(), S2->getCond())) {
12087 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = S2->getCond()->getExprLoc();
12088 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = S1->getLHS()->getSourceRange();
12092 R = S1->getLHS();
12094 auto *Then = S2->getThen();
12096 if (ThenCS->body_empty()) {
12098 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = ThenCS->getBeginLoc();
12099 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = ThenCS->getSourceRange();
12102 if (ThenCS->size() > 1) {
12104 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = ThenCS->getBeginLoc();
12105 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = ThenCS->getSourceRange();
12108 Then = ThenCS->body_front();
12114 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = S2->getBeginLoc();
12115 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = S2->getSourceRange();
12118 if (ThenBO->getOpcode() != BO_Assign) {
12120 ErrorInfo.ErrorLoc = ThenBO->getExprLoc();
12121 ErrorInfo.NoteLoc = ThenBO->getOperatorLoc();
12122 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = ThenBO->getSourceRange();
12126 X = ThenBO->getLHS();
12127 D = ThenBO->getRHS();
12129 auto *BO = cast<BinaryOperator>(S1->getRHS()->IgnoreImpCasts());
12130 if (BO->getOpcode() != BO_EQ) {
12132 ErrorInfo.ErrorLoc = BO->getExprLoc();
12133 ErrorInfo.NoteLoc = BO->getOperatorLoc();
12134 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = BO->getSourceRange();
12140 if (checkIfTwoExprsAreSame(ContextRef, X, BO->getLHS())) {
12141 E = BO->getRHS();
12142 } else if (checkIfTwoExprsAreSame(ContextRef, X, BO->getRHS())) {
12143 E = BO->getLHS();
12146 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = BO->getExprLoc();
12147 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = BO->getSourceRange();
12151 if (S2->getElse()) {
12154 auto *Else = S2->getElse();
12156 if (ElseCS->body_empty()) {
12158 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = ElseCS->getBeginLoc();
12159 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = ElseCS->getSourceRange();
12162 if (ElseCS->size() > 1) {
12164 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = ElseCS->getBeginLoc();
12165 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = ElseCS->getSourceRange();
12168 Else = ElseCS->body_front();
12174 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Else->getBeginLoc();
12175 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = Else->getSourceRange();
12178 if (ElseBO->getOpcode() != BO_Assign) {
12180 ErrorInfo.ErrorLoc = ElseBO->getExprLoc();
12181 ErrorInfo.NoteLoc = ElseBO->getOperatorLoc();
12182 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = ElseBO->getSourceRange();
12185 if (!checkIfTwoExprsAreSame(ContextRef, X, ElseBO->getRHS())) {
12187 ErrorInfo.ErrorLoc = ElseBO->getRHS()->getExprLoc();
12188 ErrorInfo.NoteLoc = X->getExprLoc();
12189 ErrorInfo.ErrorRange = ElseBO->getRHS()->getSourceRange();
12190 ErrorInfo.NoteRange = X->getSourceRange();
12194 V = ElseBO->getLHS();
12206 auto *CS = dyn_cast<CompoundStmt>(S);
12207 if (!CS) {
12209 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = S->getBeginLoc();
12210 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = S->getSourceRange();
12213 if (CS->body_empty()) {
12215 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = CS->getBeginLoc();
12216 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = CS->getSourceRange();
12221 if (CS->size() == 1) {
12222 auto *IS = dyn_cast<IfStmt>(CS->body_front());
12225 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = CS->body_front()->getBeginLoc();
12227 CS->body_front()->getSourceRange();
12232 } else if (CS->size() == 2) {
12233 auto *S1 = CS->body_front();
12234 auto *S2 = CS->body_back();
12242 // { v = x; cond-update-stmt }
12243 // { v = x; cond-expr-stmt }
12244 // { cond-expr-stmt; v = x; }
12246 if (isa<BinaryOperator>(BO->getRHS()->IgnoreImpCasts()) ||
12247 isa<ConditionalOperator>(BO->getRHS()->IgnoreImpCasts())) {
12250 return checkForm45(CS, ErrorInfo);
12251 // { cond-expr-stmt; v = x; }
12258 // { v = x; cond-update-stmt }
12261 // { v = x; cond-expr-stmt }
12266 // { cond-update-stmt v = x; }
12275 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = CUS->getBeginLoc();
12276 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = CUS->getSourceRange();
12288 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = US->getBeginLoc();
12289 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = US->getSourceRange();
12292 if (BO->getOpcode() != BO_Assign) {
12294 ErrorInfo.ErrorLoc = BO->getExprLoc();
12295 ErrorInfo.NoteLoc = BO->getOperatorLoc();
12296 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = BO->getSourceRange();
12299 if (!checkIfTwoExprsAreSame(ContextRef, this->X, BO->getRHS())) {
12301 ErrorInfo.ErrorLoc = BO->getRHS()->getExprLoc();
12302 ErrorInfo.NoteLoc = this->X->getExprLoc();
12303 ErrorInfo.ErrorRange = BO->getRHS()->getSourceRange();
12304 ErrorInfo.NoteRange = this->X->getSourceRange();
12308 this->V = BO->getLHS();
12321 ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = CS->getBeginLoc();
12322 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = CS->getSourceRange();
12336 DSAStack->addAtomicDirectiveLoc(StartLoc);
12341 // Structured block - An executable statement with a single entry at the
12352 switch (C->getClauseKind()) {
12361 Diag(C->getBeginLoc(), diag::err_omp_atomic_several_clauses)
12362 << SourceRange(C->getBeginLoc(), C->getEndLoc());
12366 AtomicKind = C->getClauseKind();
12367 AtomicKindLoc = C->getBeginLoc();
12368 if (!EncounteredAtomicKinds.insert(C->getClauseKind()).second) {
12369 Diag(C->getBeginLoc(), diag::err_omp_atomic_several_clauses)
12370 << SourceRange(C->getBeginLoc(), C->getEndLoc());
12380 Diag(C->getBeginLoc(), diag::err_omp_atomic_no_compare)
12381 << getOpenMPClauseName(C->getClauseKind())
12382 << SourceRange(C->getBeginLoc(), C->getEndLoc());
12393 Diag(C->getBeginLoc(), diag::err_omp_several_mem_order_clauses)
12395 << SourceRange(C->getBeginLoc(), C->getEndLoc());
12399 MemOrderKind = C->getClauseKind();
12400 MemOrderLoc = C->getBeginLoc();
12418 // If atomic-clause is read then memory-order-clause must not be acq_rel or
12420 // If atomic-clause is write then memory-order-clause must not be acq_rel or
12422 // If atomic-clause is update or not present then memory-order-clause must not
12442 Body = EWC->getSubExpr();
12456 // * x and v (as applicable) are both l-value expressions with scalar type.
12464 // * binop is one of +, *, -, /, &, ^, |, <<, or >>.
12465 // * binop, binop=, ++, and -- are not overloaded operators.
12490 dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts());
12491 if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) {
12492 X = AtomicBinOp->getRHS()->IgnoreParenImpCasts();
12493 V = AtomicBinOp->getLHS()->IgnoreParenImpCasts();
12494 if ((X->isInstantiationDependent() || X->getType()->isScalarType()) &&
12495 (V->isInstantiationDependent() || V->getType()->isScalarType())) {
12496 if (!X->isLValue() || !V->isLValue()) {
12497 const Expr *NotLValueExpr = X->isLValue() ? V : X;
12499 ErrorLoc = AtomicBinOp->getExprLoc();
12500 ErrorRange = AtomicBinOp->getSourceRange();
12501 NoteLoc = NotLValueExpr->getExprLoc();
12502 NoteRange = NotLValueExpr->getSourceRange();
12504 } else if (!X->isInstantiationDependent() ||
12505 !V->isInstantiationDependent()) {
12507 (X->isInstantiationDependent() || X->getType()->isScalarType())
12511 ErrorLoc = AtomicBinOp->getExprLoc();
12512 ErrorRange = AtomicBinOp->getSourceRange();
12513 NoteLoc = NotScalarExpr->getExprLoc();
12514 NoteRange = NotScalarExpr->getSourceRange();
12516 } else if (!AtomicBody->isInstantiationDependent()) {
12518 ErrorLoc = AtomicBody->getExprLoc();
12519 ErrorRange = AtomicBody->getSourceRange();
12520 NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc()
12521 : AtomicBody->getExprLoc();
12522 NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange()
12523 : AtomicBody->getSourceRange();
12527 NoteLoc = ErrorLoc = Body->getBeginLoc();
12537 if (SemaRef.CurContext->isDependentContext())
12553 dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts());
12554 if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) {
12555 X = AtomicBinOp->getLHS();
12556 E = AtomicBinOp->getRHS();
12557 if ((X->isInstantiationDependent() || X->getType()->isScalarType()) &&
12558 (E->isInstantiationDependent() || E->getType()->isScalarType())) {
12559 if (!X->isLValue()) {
12561 ErrorLoc = AtomicBinOp->getExprLoc();
12562 ErrorRange = AtomicBinOp->getSourceRange();
12563 NoteLoc = X->getExprLoc();
12564 NoteRange = X->getSourceRange();
12566 } else if (!X->isInstantiationDependent() ||
12567 !E->isInstantiationDependent()) {
12569 (X->isInstantiationDependent() || X->getType()->isScalarType())
12573 ErrorLoc = AtomicBinOp->getExprLoc();
12574 ErrorRange = AtomicBinOp->getSourceRange();
12575 NoteLoc = NotScalarExpr->getExprLoc();
12576 NoteRange = NotScalarExpr->getSourceRange();
12578 } else if (!AtomicBody->isInstantiationDependent()) {
12580 ErrorLoc = AtomicBody->getExprLoc();
12581 ErrorRange = AtomicBody->getSourceRange();
12582 NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc()
12583 : AtomicBody->getExprLoc();
12584 NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange()
12585 : AtomicBody->getSourceRange();
12589 NoteLoc = ErrorLoc = Body->getBeginLoc();
12599 if (SemaRef.CurContext->isDependentContext())
12604 // x--;
12606 // --x;
12618 if (!SemaRef.CurContext->isDependentContext()) {
12637 // v = x--;
12639 // v = --x;
12644 dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts());
12645 if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) {
12646 V = AtomicBinOp->getLHS();
12647 Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts();
12658 } else if (!AtomicBody->isInstantiationDependent()) {
12659 ErrorLoc = AtomicBody->getExprLoc();
12660 ErrorRange = AtomicBody->getSourceRange();
12661 NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc()
12662 : AtomicBody->getExprLoc();
12663 NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange()
12664 : AtomicBody->getSourceRange();
12673 if (SemaRef.CurContext->isDependentContext())
12679 // { v = x; x--; }
12681 // { v = x; --x; }
12686 // { x--; v = x; }
12688 // { --x; v = x; }
12692 if (auto *CS = dyn_cast<CompoundStmt>(Body)) {
12694 if (CS->size() == 2) {
12695 Stmt *First = CS->body_front();
12696 Stmt *Second = CS->body_back();
12698 First = EWC->getSubExpr()->IgnoreParenImpCasts();
12700 Second = EWC->getSubExpr()->IgnoreParenImpCasts();
12707 IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign;
12709 if (IsUpdateExprFound && !SemaRef.CurContext->isDependentContext()) {
12711 // { v = x; x--; }
12713 // { v = x; --x; }
12718 Expr *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts();
12720 Checker.getX()->Profile(XId, Context, /*Canonical=*/true);
12721 PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true);
12724 V = BinOp->getLHS();
12737 IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign;
12740 !SemaRef.CurContext->isDependentContext()) {
12742 // { x--; v = x; }
12744 // { --x; v = x; }
12749 Expr *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts();
12751 Checker.getX()->Profile(XId, Context, /*Canonical=*/true);
12752 PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true);
12755 V = BinOp->getLHS();
12769 !(FirstExpr->isInstantiationDependent() ||
12770 SecondExpr->isInstantiationDependent())) {
12772 if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) {
12774 NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc()
12775 : First->getBeginLoc();
12777 ? FirstBinOp->getSourceRange()
12781 if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) {
12784 ? SecondBinOp->getOperatorLoc()
12785 : Second->getBeginLoc();
12787 SecondBinOp ? SecondBinOp->getSourceRange()
12791 FirstBinOp->getRHS()->IgnoreParenImpCasts();
12793 SecondBinOp->getLHS()->IgnoreParenImpCasts();
12795 PossibleXRHSInFirst->Profile(X1Id, Context,
12797 PossibleXLHSInSecond->Profile(X2Id, Context,
12801 V = FirstBinOp->getLHS();
12802 X = SecondBinOp->getLHS();
12803 E = SecondBinOp->getRHS();
12809 ErrorLoc = FirstBinOp->getExprLoc();
12810 ErrorRange = FirstBinOp->getSourceRange();
12811 NoteLoc = SecondBinOp->getLHS()->getExprLoc();
12812 NoteRange = SecondBinOp->getRHS()->getSourceRange();
12819 NoteLoc = ErrorLoc = Body->getBeginLoc();
12821 SourceRange(Body->getBeginLoc(), Body->getBeginLoc());
12825 NoteLoc = ErrorLoc = Body->getBeginLoc();
12827 SourceRange(Body->getBeginLoc(), Body->getBeginLoc());
12837 if (SemaRef.CurContext->isDependentContext())
12880 return C->getClauseKind() == llvm::omp::Clause::OMPC_weak;
12884 if (Cond->getOpcode() != BO_EQ) {
12886 ErrorInfo.ErrorLoc = Cond->getExprLoc();
12887 ErrorInfo.NoteLoc = Cond->getOperatorLoc();
12888 ErrorInfo.ErrorRange = ErrorInfo.NoteRange = Cond->getSourceRange();
12914 CapturedStmt *CS = setBranchProtectedScope(SemaRef, OMPD_target, AStmt);
12920 if (DSAStack->hasInnerTeamsRegion()) {
12921 const Stmt *S = CS->IgnoreContainers(/*IgnoreCaptured=*/true);
12923 if (const auto *CS = dyn_cast<CompoundStmt>(S)) {
12924 auto I = CS->body_begin();
12925 while (I != CS->body_end()) {
12927 bool IsTeams = OED && isOpenMPTeamsDirective(OED->getDirectiveKind());
12928 if (!IsTeams || I != CS->body_begin()) {
12930 if (IsTeams && I != CS->body_begin()) {
12933 --I;
12939 assert(I != CS->body_end() && "Not found statement");
12943 OMPTeamsFound = OED && isOpenMPTeamsDirective(OED->getDirectiveKind());
12947 Diag(DSAStack->getInnerTeamsRegionLoc(),
12949 Diag(S->getBeginLoc(), diag::note_omp_nested_statement_here)
12969 DSAStack->getTaskgroupReductionRef(), DSAStack->isCancelRegion());
12978 CapturedStmt *CS =
12986 getOrderedNumberExpr(Clauses), CS, SemaRef, *DSAStack,
12996 DSAStack->getTaskgroupReductionRef(), DSAStack->isCancelRegion());
13003 Clauses, [K](const OMPClause *C) { return C->getClauseKind() == K; });
13016 return llvm::all_of(TC->all_decls(), [](ValueDecl *VD) {
13017 return !VD || !VD->hasAttr<OMPDeclareTargetDeclAttr>() ||
13018 (VD->isExternallyVisible() &&
13019 VD->getVisibility() != HiddenVisibility);
13022 return llvm::all_of(FC->all_decls(), [](ValueDecl *VD) {
13023 return !VD || !VD->hasAttr<OMPDeclareTargetDeclAttr>() ||
13024 (VD->isExternallyVisible() &&
13025 VD->getVisibility() != HiddenVisibility);
13132 // Report affected OpenMP target offloading behavior when in HIP lang-mode.
13133 if (getLangOpts().HIP && (DSAStack->getParentDirective() == OMPD_target))
13138 DSAStack->setParentTeamsRegionLoc(StartLoc);
13147 if (DSAStack->isParentNowaitRegion()) {
13151 if (DSAStack->isParentOrderedRegion()) {
13162 if (DSAStack->isParentNowaitRegion()) {
13166 if (DSAStack->isParentOrderedRegion()) {
13170 DSAStack->setParentCancelRegion(/*Cancel=*/true);
13180 if (C->getClauseKind() == OMPC_reduction) {
13186 if (C->getClauseKind() == OMPC_nogroup) {
13194 S.Diag(ReductionClause->getBeginLoc(), diag::err_omp_reduction_with_nogroup)
13195 << SourceRange(NogroupClause->getBeginLoc(),
13196 NogroupClause->getEndLoc());
13219 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
13237 DSAStack->isCancelRegion());
13296 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
13314 DSAStack->isCancelRegion());
13334 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
13352 DSAStack->isCancelRegion());
13439 CapturedStmt *CS =
13447 /*OrderedLoopCountExpr=*/nullptr, CS, SemaRef, *DSAStack,
13452 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
13469 DSAStack->isCancelRegion());
13478 CapturedStmt *CS =
13486 /*OrderedLoopCountExpr=*/nullptr, CS, SemaRef, *DSAStack,
13491 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
13508 DSAStack->isCancelRegion());
13517 CapturedStmt *CS = setBranchProtectedScope(
13525 /*OrderedLoopCountExpr=*/nullptr, CS, SemaRef, *DSAStack,
13557 CapturedStmt *CS = setBranchProtectedScope(
13565 /*OrderedLoopCountExpr=*/nullptr, CS, SemaRef, *DSAStack,
13611 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
13617 DSAStack->getMappedDirective());
13627 CapturedStmt *CS =
13635 nullptr /*ordered not a clause on distribute*/, CS, SemaRef, *DSAStack,
13640 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
13645 DSAStack->getTaskgroupReductionRef(), DSAStack->isCancelRegion());
13654 CapturedStmt *CS = setBranchProtectedScope(
13662 nullptr /*ordered not a clause on distribute*/, CS, SemaRef, *DSAStack,
13683 CapturedStmt *CS =
13691 nullptr /*ordered not a clause on distribute*/, CS,
13712 CapturedStmt *CS =
13720 getOrderedNumberExpr(Clauses), CS, SemaRef, *DSAStack,
13741 CapturedStmt *CS = setBranchProtectedScope(SemaRef, OMPD_target_simd, AStmt);
13748 getOrderedNumberExpr(Clauses), CS, SemaRef, *DSAStack,
13769 CapturedStmt *CS =
13777 nullptr /*ordered not a clause on distribute*/, CS,
13782 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
13785 DSAStack->setParentTeamsRegionLoc(StartLoc);
13797 CapturedStmt *CS =
13805 nullptr /*ordered not a clause on distribute*/, CS, SemaRef, *DSAStack,
13816 DSAStack->setParentTeamsRegionLoc(StartLoc);
13828 CapturedStmt *CS = setBranchProtectedScope(
13836 nullptr /*ordered not a clause on distribute*/, CS, SemaRef, *DSAStack,
13847 DSAStack->setParentTeamsRegionLoc(StartLoc);
13859 CapturedStmt *CS = setBranchProtectedScope(
13867 nullptr /*ordered not a clause on distribute*/, CS, SemaRef, *DSAStack,
13873 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
13876 DSAStack->setParentTeamsRegionLoc(StartLoc);
13880 DSAStack->getTaskgroupReductionRef(), DSAStack->isCancelRegion());
13896 return C->getClauseKind() == OMPC_ompx_bare;
13900 Diag(BareClause->getBeginLoc(), diag::err_ompx_bare_no_grid);
13914 CapturedStmt *CS =
13922 nullptr /*ordered not a clause on distribute*/, CS, SemaRef, *DSAStack,
13927 assert((SemaRef.CurContext->isDependentContext() || B.builtAll()) &&
13940 CapturedStmt *CS = setBranchProtectedScope(
13948 nullptr /*ordered not a clause on distribute*/, CS, SemaRef, *DSAStack,
13958 DSAStack->getTaskgroupReductionRef(), DSAStack->isCancelRegion());
13967 CapturedStmt *CS = setBranchProtectedScope(
13976 nullptr /*ordered not a clause on distribute*/, CS,
13997 CapturedStmt *CS = setBranchProtectedScope(
14005 nullptr /*ordered not a clause on distribute*/, CS, SemaRef, *DSAStack,
14026 AStmt->IgnoreContainers(), /*TryImperfectlyNestedLoops=*/false, NumLoops,
14037 OriginalInits.back().push_back(For->getInit());
14038 Body = For->getBody();
14041 "Expected canonical for or range-based for loops.");
14043 OriginalInits.back().push_back(CXXFor->getBeginStmt());
14044 Body = CXXFor->getBody();
14052 DependentPreInits = Dir->getPreInits();
14054 DependentPreInits = Dir->getPreInits();
14056 DependentPreInits = Dir->getPreInits();
14058 DependentPreInits = Dir->getPreInits();
14075 // For range-based for-statements, ensure that their syntactic sugar is
14076 // executed by adding them as pre-init statements.
14078 Stmt *RangeInit = CXXRangeFor->getInit();
14082 DeclStmt *RangeStmt = CXXRangeFor->getRangeStmt();
14083 PreInits.push_back(new (Context) DeclStmt(RangeStmt->getDeclGroup(),
14084 RangeStmt->getBeginLoc(),
14085 RangeStmt->getEndLoc()));
14087 DeclStmt *RangeEnd = CXXRangeFor->getEndStmt();
14088 PreInits.push_back(new (Context) DeclStmt(RangeEnd->getDeclGroup(),
14089 RangeEnd->getBeginLoc(),
14090 RangeEnd->getEndLoc()));
14098 PI->getDeclGroup(), PI->getBeginLoc(), PI->getEndLoc()));
14103 auto *CounterDecl = cast<DeclRefExpr>(CounterRef)->getDecl();
14135 llvm::any_of(SizesClause->getSizesRefs(), [](Expr *E) { return !E; }))
14137 unsigned NumLoops = SizesClause->getNumSizes();
14151 // Delay tiling to when template is completely instantiated.
14152 if (SemaRef.CurContext->isDependentContext())
14179 "Expect single-dimensional loop iteration space");
14181 std::string OrigVarName = OrigCntVar->getNameInfo().getAsString();
14183 QualType CntTy = IterVarRef->getType();
14202 auto *TileCntDecl = cast<VarDecl>(IterVarRef->getDecl());
14203 TileCntDecl->setDeclName(
14215 auto MakeDimTileSize = [&SemaRef = this->SemaRef, &CopyTransformer, &Context,
14216 SizesClause, CurScope](int I) -> Expr * {
14217 Expr *DimTileSizeExpr = SizesClause->getSizesRefs()[I];
14222 // pass non-positive numbers. For instance:
14237 QualType DimTy = DimTileSizeExpr->getType();
14254 for (int I = NumLoops - 1; I >= 0; --I) {
14258 QualType IVTy = NumIterations->getType();
14264 auto MakeTileIVRef = [&SemaRef = this->SemaRef, &TileIndVars, I, IVTy,
14267 OrigCntVar->getExprLoc());
14269 auto MakeFloorIVRef = [&SemaRef = this->SemaRef, &FloorIndVars, I, IVTy,
14272 OrigCntVar->getExprLoc());
14275 // For init-statement: auto .tile.iv = .floor.iv
14282 OrigCntVar->getBeginLoc(), OrigCntVar->getEndLoc());
14286 // For cond-expression:
14289 SemaRef.BuildBinOp(CurScope, LoopHelper.Cond->getExprLoc(), BO_Add,
14294 SemaRef.BuildBinOp(CurScope, LoopHelper.Cond->getExprLoc(), BO_LT,
14299 LoopHelper.Cond->getBeginLoc(), LoopHelper.Cond->getEndLoc(),
14304 SemaRef.BuildBinOp(CurScope, LoopHelper.Cond->getExprLoc(), BO_LT,
14309 // For incr-statement: ++.tile.iv
14311 CurScope, LoopHelper.Inc->getExprLoc(), UO_PreInc, MakeTileIVRef());
14334 BodyParts.push_back(SourceCXXFor->getLoopVarStmt());
14337 Inner->getBeginLoc(), Inner->getEndLoc());
14340 IncrStmt.get(), Inner, LoopHelper.Init->getBeginLoc(),
14341 LoopHelper.Init->getBeginLoc(), LoopHelper.Inc->getEndLoc());
14345 for (int I = NumLoops - 1; I >= 0; --I) {
14349 QualType IVTy = NumIterations->getType();
14354 auto MakeFloorIVRef = [&SemaRef = this->SemaRef, &FloorIndVars, I, IVTy,
14357 OrigCntVar->getExprLoc());
14360 // For init-statement: auto .floor.iv = 0
14363 SemaRef.ActOnIntegerConstant(LoopHelper.Init->getExprLoc(), 0).get(),
14368 OrigCntVar->getBeginLoc(), OrigCntVar->getEndLoc());
14372 // For cond-expression: .floor.iv < NumIterations
14374 SemaRef.BuildBinOp(CurScope, LoopHelper.Cond->getExprLoc(), BO_LT,
14379 // For incr-statement: .floor.iv += DimTileSize
14381 SemaRef.BuildBinOp(CurScope, LoopHelper.Inc->getExprLoc(), BO_AddAssign,
14388 IncrStmt.get(), Inner, LoopHelper.Init->getBeginLoc(),
14389 LoopHelper.Init->getBeginLoc(), LoopHelper.Inc->getEndLoc());
14429 // Delay unrolling to when template is completely instantiated.
14430 if (SemaRef.CurContext->isDependentContext())
14435 "Expecting a single-dimensional loop iteration space");
14437 "Expecting a single-dimensional loop iteration space");
14445 Diag(AStmt->getBeginLoc(), diag::err_omp_unroll_full_variable_trip_count);
14446 Diag(FullClause->getBeginLoc(), diag::note_omp_directive_here)
14452 // The generated loop may only be passed to other loop-associated directive
14454 // sufficient to generate loop unroll metadata at code-generation.
14459 // Otherwise, we need to provide a de-sugared/transformed AST that can be
14497 // CompoundStatement. This is to allow the loop to become a non-outermost loop
14510 QualType IVTy = IterationVarRef->getType();
14512 "Expecting a single-dimensional loop iteration space");
14518 if (Expr *FactorVal = PartialClause->getFactor()) {
14519 Factor = FactorVal->getIntegerConstantExpr(Context)->getZExtValue();
14520 FactorLoc = FactorVal->getExprLoc();
14533 SourceLocation OrigVarLoc = OrigVar->getExprLoc();
14534 SourceLocation OrigVarLocBegin = OrigVar->getBeginLoc();
14535 SourceLocation OrigVarLocEnd = OrigVar->getEndLoc();
14538 std::string OrigVarName = OrigVar->getNameInfo().getAsString();
14553 auto *InnerIVDecl = cast<VarDecl>(IterationVarRef->getDecl());
14554 InnerIVDecl->setDeclName(&SemaRef.PP.getIdentifierTable().get(InnerIVName));
14562 auto MakeNumIterations = [&CopyTransformer, &LoopHelper]() -> Expr * {
14567 // Inner For init-statement: auto .unroll_inner.iv = .unrolled.iv
14576 // Inner For cond-expression:
14584 SemaRef.BuildBinOp(CurScope, LoopHelper.Cond->getExprLoc(), BO_Add,
14589 SemaRef.BuildBinOp(CurScope, LoopHelper.Cond->getExprLoc(), BO_LT,
14594 SemaRef.BuildBinOp(CurScope, LoopHelper.Cond->getExprLoc(), BO_LT,
14599 SemaRef.BuildBinOp(CurScope, LoopHelper.Cond->getExprLoc(), BO_LAnd,
14604 // Inner For incr-statement: ++.unroll_inner.iv
14606 CurScope, LoopHelper.Inc->getExprLoc(), UO_PreInc, MakeInnerRef());
14614 InnerBodyStmts.push_back(CXXRangeFor->getLoopVarStmt());
14618 Body->getBeginLoc(), Body->getEndLoc());
14621 InnerIncr.get(), InnerBody, LoopHelper.Init->getBeginLoc(),
14622 LoopHelper.Init->getBeginLoc(), LoopHelper.Inc->getEndLoc());
14642 // Outer For init-statement: auto .unrolled.iv = 0
14645 SemaRef.ActOnIntegerConstant(LoopHelper.Init->getExprLoc(), 0).get(),
14652 // Outer For cond-expression: .unrolled.iv < NumIterations
14654 SemaRef.BuildBinOp(CurScope, LoopHelper.Cond->getExprLoc(), BO_LT,
14659 // Outer For incr-statement: .unrolled.iv += Factor
14661 SemaRef.BuildBinOp(CurScope, LoopHelper.Inc->getExprLoc(), BO_AddAssign,
14669 OuterIncr.get(), InnerUnrolled, LoopHelper.Init->getBeginLoc(),
14670 LoopHelper.Init->getBeginLoc(), LoopHelper.Inc->getEndLoc());
14696 // Delay applying the transformation to when template is completely
14698 if (SemaRef.CurContext->isDependentContext())
14703 "Expecting a single-dimensional loop iteration space");
14705 "Expecting a single-dimensional loop iteration space");
14717 QualType IVTy = IterationVarRef->getType();
14722 SourceLocation OrigVarLoc = OrigVar->getExprLoc();
14723 SourceLocation OrigVarLocBegin = OrigVar->getBeginLoc();
14724 SourceLocation OrigVarLocEnd = OrigVar->getEndLoc();
14732 std::string OrigVarName = OrigVar->getNameInfo().getAsString();
14750 // for (unsigned i = n-1; i >= 0; --i)
14760 // auto .reversed.iv = n - .forward.iv - 1;
14770 auto MakeNumIterations = [&CopyTransformer, &LoopHelper]() -> Expr * {
14775 // Create the iteration variable for the forward loop (from 0 to n-1).
14778 auto MakeForwardRef = [&SemaRef = this->SemaRef, ForwardIVDecl, IVTy,
14783 // Iteration variable for the reversed induction variable (from n-1 downto 0):
14785 auto *ReversedIVDecl = cast<VarDecl>(IterationVarRef->getDecl());
14786 ReversedIVDecl->setDeclName(
14789 // For init-statement:
14794 ForwardIVDecl->getType(), OrigVarLoc);
14801 // Forward iv cond-expression:
14806 SemaRef.BuildBinOp(CurScope, LoopHelper.Cond->getExprLoc(), BO_LT,
14811 // Forward incr-statement:
14815 ExprResult Incr = SemaRef.BuildUnaryOp(CurScope, LoopHelper.Inc->getExprLoc(),
14820 // Reverse the forward-iv:
14822 // auto .reversed.iv = MakeNumIterations() - 1 - .forward.iv
14848 BodyStmts.push_back(CXXRangeFor->getLoopVarStmt());
14852 Body->getBeginLoc(), Body->getEndLoc());
14854 // Finally create the reversed For-statement.
14857 ReversedBody, LoopHelper.Init->getBeginLoc(),
14858 LoopHelper.Init->getBeginLoc(), LoopHelper.Inc->getEndLoc());
14886 // Delay interchange to when template is completely instantiated.
14887 if (CurContext->isDependentContext())
14905 // Collect pre-init statements on the order before the permuation.
14911 "Single-dimensional loop iteration space expected");
14914 std::string OrigVarName = OrigCntVar->getNameInfo().getAsString();
14932 "Single-dimensional loop iteration space expected");
14935 // Normalized loop counter variable: From 0 to n-1, always an integer type.
14937 QualType IVTy = IterVarRef->getType();
14938 assert(IVTy->isIntegerType() &&
14941 std::string OrigVarName = OrigCntVar->getNameInfo().getAsString();
14942 SourceLocation OrigVarLoc = IterVarRef->getExprLoc();
14946 auto MakeNumIterations = [&CopyTransformer, &SourceHelper]() -> Expr * {
14956 auto *PermutedCntDecl = cast<VarDecl>(IterVarRef->getDecl());
14957 PermutedCntDecl->setDeclName(
14964 // For init-statement:
14974 DeclStmt(DeclGroupRef(PermutedCntDecl), OrigCntVar->getBeginLoc(),
14975 OrigCntVar->getEndLoc());
14979 // For cond-expression:
14984 SemaRef.BuildBinOp(CurScope, SourceHelper.Cond->getExprLoc(), BO_LT,
14989 // For incr-statement:
14994 CurScope, SourceHelper.Inc->getExprLoc(), UO_PreInc, MakePermutedRef());
15001 BodyParts.push_back(SourceCXXFor->getLoopVarStmt());
15004 Inner->getBeginLoc(), Inner->getEndLoc());
15007 SourceHelper.Init->getBeginLoc(), SourceHelper.Init->getBeginLoc(),
15008 SourceHelper.Inc->getEndLoc());
15165 "Invalid directive with CKind-clause");
15174 // [5.2:341:24-30]
15176 // the argument of the clause is an expression, or lower-bound, length, or
15178 // expressions in subscript-triplet for Fortran), or linear-step or alignment
15239 for (int I = EndIdx - 1; I >= 0; --I) {
15243 return -1;
15248 for (int I = InnermostIdx - 1; I >= 0; --I) {
15283 if (!Condition->isValueDependent() && !Condition->isTypeDependent() &&
15284 !Condition->isInstantiationDependent() &&
15285 !Condition->containsUnexpandedParameterPack()) {
15292 OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
15296 !SemaRef.CurContext->isDependentContext()) {
15316 if (!Condition->isValueDependent() && !Condition->isTypeDependent() &&
15317 !Condition->isInstantiationDependent() &&
15318 !Condition->containsUnexpandedParameterPack()) {
15325 OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
15329 !SemaRef.CurContext->isDependentContext()) {
15366 return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here)
15367 << ConvTy->isEnumeralType() << ConvTy;
15375 return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here)
15376 << ConvTy->isEnumeralType() << ConvTy;
15392 if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() &&
15393 !ValExpr->isInstantiationDependent()) {
15394 SourceLocation Loc = ValExpr->getExprLoc();
15401 // The expression must evaluate to a non-negative integer value.
15403 ValExpr->getIntegerConstantExpr(SemaRef.Context)) {
15404 if (Result->isSigned() &&
15405 !((!StrictlyPositive && Result->isNonNegative()) ||
15406 (StrictlyPositive && Result->isStrictlyPositive()))) {
15409 << ValExpr->getSourceRange();
15418 !SemaRef.CurContext->isDependentContext()) {
15441 OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
15445 !SemaRef.CurContext->isDependentContext()) {
15461 if (E->isValueDependent() || E->isTypeDependent() ||
15462 E->isInstantiationDependent() || E->containsUnexpandedParameterPack())
15488 Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause)
15490 << E->getSourceRange();
15494 Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two)
15495 << E->getSourceRange();
15498 if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1)
15499 DSAStack->setAssociatedLoops(Result.getExtValue());
15501 DSAStack->setAssociatedLoops(Result.getExtValue());
15536 if (!Stack->getOMPAllocatorHandleT().isNull())
15549 Stack->setOMPAllocatorHandleT(AllocatorHandleEnumTy);
15565 VD->getType().getNonLValueExprType(S.getASTContext());
15578 Stack->setAllocator(AllocatorKind, Res.get());
15595 if (!findOMPAllocatorHandleT(SemaRef, A->getExprLoc(), DSAStack))
15602 Allocator.get(), DSAStack->getOMPAllocatorHandleT(),
15648 NumForLoops ? DSAStack->getAssociatedLoops() : 0,
15650 DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops, Clause);
15783 --Skipped;
15810 DSAStack->setDefaultDSANone(KindKwLoc);
15813 DSAStack->setDefaultDSAShared(KindKwLoc);
15816 DSAStack->setDefaultDSAFirstPrivate(KindKwLoc);
15819 DSAStack->setDefaultDSAPrivate(KindKwLoc);
15910 Diag(ME->getBeginLoc(), diag::warn_clause_expected_string)
15944 DSAStack->setRegionHasOrderConcurrent(/*HasOrderConcurrent=*/true);
15945 if (DSAStack->getCurScope()) {
15947 unsigned existingFlags = DSAStack->getCurScope()->getFlags();
15948 DSAStack->getCurScope()->setFlags(existingFlags |
15993 // isNonNegativeIntegerValue returns true for non-integral types (but still
15995 QualType SizeTy = SizeExpr->getType();
15996 if (!SizeTy->isIntegerType())
16020 // Pass the invalid expression as-is, template instantiation may
16023 // contexts, but delay analysis until full instantiation.
16024 if (!SizeExpr->isInstantiationDependent() && !IsValid)
16285 if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() &&
16286 !ChunkSize->isInstantiationDependent() &&
16287 !ChunkSize->containsUnexpandedParameterPack()) {
16288 SourceLocation ChunkSizeLoc = ChunkSize->getBeginLoc();
16300 ValExpr->getIntegerConstantExpr(getASTContext())) {
16301 if (Result->isSigned() && !Result->isStrictlyPositive()) {
16303 << "schedule" << 1 << ChunkSize->getSourceRange();
16307 DSAStack->getCurrentDirective(), OMPC_schedule,
16309 !SemaRef.CurContext->isDependentContext()) {
16481 DSAStack->setNowaitRegion();
16487 DSAStack->setUntiedRegion();
16613 // At least one action-clause must appear on a directive.
16623 // interop-type is present or the interop-var was initialized with
16624 // the targetsync interop-type.
16627 // interop-type of 'targetsync'. Cases involving other directives cannot be
16637 if (InitClause->getIsTargetSync())
16644 Diag(DependClause->getBeginLoc(), diag::err_omp_interop_bad_depend_clause);
16649 // Each interop-var may be specified for at most one action-clause of each
16653 OpenMPClauseKind ClauseKind = C->getClauseKind();
16659 auto *E = cast<OMPInitClause>(C)->getInteropVar();
16662 auto *E = cast<OMPUseClause>(C)->getInteropVar();
16665 auto *E = cast<OMPDestroyClause>(C)->getInteropVar();
16708 InteropType = QualType(TD->getTypeForDecl(), 0);
16722 QualType VarType = InteropVarExpr->getType().getUnqualifiedType();
16729 // The interop-var passed to init or destroy must be non-const.
16731 isConstNotMutableType(SemaRef, InteropVarExpr->getType())) {
16733 << /*non-const*/ 1;
16746 // Check prefer_type values. These foreign-runtime-id values are either
16749 if (E->isValueDependent() || E->isTypeDependent() ||
16750 E->isInstantiationDependent() || E->containsUnexpandedParameterPack())
16752 if (E->isIntegerConstantExpr(getASTContext()))
16756 Diag(E->getExprLoc(), diag::err_omp_interop_prefer_type);
16783 DSAStack->getCurrentDirective() == OMPD_depobj) {
16804 if (!Condition->isValueDependent() && !Condition->isTypeDependent() &&
16805 !Condition->isInstantiationDependent() &&
16806 !Condition->containsUnexpandedParameterPack()) {
16813 OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
16817 !SemaRef.CurContext->isDependentContext()) {
16836 if (!Condition->isValueDependent() && !Condition->isTypeDependent() &&
16837 !Condition->isInstantiationDependent() &&
16838 !Condition->containsUnexpandedParameterPack()) {
16845 OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
16849 !SemaRef.CurContext->isDependentContext()) {
16868 OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
16872 !SemaRef.CurContext->isDependentContext()) {
17082 Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc);
17090 if (VK != VK_LValue && Res.get()->isGLValue()) {
17121 QualType Type = D->getType();
17133 // A variable that is privatized must not have a const-qualified type
17139 // const-qualified type unless it is of class type with a mutable member.
17143 // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
17145 // Variables with the predetermined data-sharing attributes may not be
17146 // listed in data-sharing attributes clauses, except for the cases
17148 // variable in a data-sharing attribute clause is allowed and overrides
17149 // the variable's predetermined data-sharing attributes.
17150 DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false);
17158 OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective();
17160 if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() &&
17165 bool IsDecl = !VD || VD->isThisDeclarationADefinition(getASTContext()) ==
17167 Diag(D->getLocation(),
17174 // A list item cannot appear in both a map clause and a data-sharing
17178 // A list item cannot appear in both a map clause and a data-sharing
17185 if (DSAStack->checkMappableExprComponentListsForDecl(
17188 OpenMPClauseKind WhereFoundClauseKind) -> bool {
17212 buildVarDecl(SemaRef, ELoc, Type, D->getName(),
17213 D->hasAttrs() ? &D->getAttrs() : nullptr,
17216 if (VDPrivate->isInvalidDecl())
17219 SemaRef, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc);
17222 if (!VD && !SemaRef.CurContext->isDependentContext()) {
17224 VarDecl *VD = FD ? DSAStack->getImplicitFDCapExprDecl(FD) : nullptr;
17226 Ref = buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(),
17227 RefExpr->getExprLoc());
17232 DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref);
17233 Vars.push_back((VD || SemaRef.CurContext->isDependentContext())
17234 ? RefExpr->IgnoreParens()
17256 SourceLocation ImplicitClauseLoc = DSAStack->getConstructLoc();
17275 QualType Type = D->getType();
17297 DSAStack->getTopDSA(D, /*FromParent=*/false);
17299 OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective();
17301 // OpenMP [2.4.13, Data-sharing Attribute Clauses]
17319 // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
17321 // Variables with the predetermined data-sharing attributes may not be
17322 // listed in data-sharing attributes clauses, except for the cases
17324 // variable in a data-sharing attribute clause is allowed and overrides
17325 // the variable's predetermined data-sharing attributes.
17326 // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
17328 // Variables with const-qualified type having no mutable member may be
17330 if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr &&
17358 DVar = DSAStack->getImplicitDSA(D, true);
17382 DVar = DSAStack->hasInnermostDSA(
17405 // A list item cannot appear in both a map clause and a data-sharing
17409 // A list item cannot appear in both a map clause and a data-sharing
17416 if (DSAStack->checkMappableExprComponentListsForDecl(
17427 << getOpenMPDirectiveName(DSAStack->getCurrentDirective());
17435 if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() &&
17436 isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) {
17439 << getOpenMPDirectiveName(DSAStack->getCurrentDirective());
17440 bool IsDecl = !VD || VD->isThisDeclarationADefinition(getASTContext()) ==
17442 Diag(D->getLocation(),
17450 buildVarDecl(SemaRef, ELoc, Type, D->getName(),
17451 D->hasAttrs() ? &D->getAttrs() : nullptr,
17461 if (Type->isArrayType()) {
17463 buildVarDecl(SemaRef, RefExpr->getExprLoc(), ElemType, D->getName());
17467 VarDecl *VDInitTemp = buildVarDecl(SemaRef, RefExpr->getExprLoc(),
17476 VDPrivate->setInvalidDecl();
17478 VDPrivate->setInit(Result.getAs<Expr>());
17482 VarDecl *VDInit = buildVarDecl(SemaRef, RefExpr->getExprLoc(), Type,
17484 VDInitRefExpr = buildDeclRefExpr(SemaRef, VDInit, RefExpr->getType(),
17485 RefExpr->getExprLoc());
17490 if (VDPrivate->isInvalidDecl()) {
17492 Diag(RefExpr->getExprLoc(),
17497 SemaRef.CurContext->addDecl(VDPrivate);
17499 SemaRef, VDPrivate, RefExpr->getType().getUnqualifiedType(),
17500 RefExpr->getExprLoc());
17502 if (!VD && !SemaRef.CurContext->isDependentContext()) {
17507 VarDecl *VD = FD ? DSAStack->getImplicitFDCapExprDecl(FD) : nullptr;
17510 buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(),
17511 RefExpr->getExprLoc());
17515 ExprCaptures.push_back(Ref->getDecl());
17519 DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref);
17520 Vars.push_back((VD || SemaRef.CurContext->isDependentContext())
17521 ? RefExpr->IgnoreParens()
17571 QualType Type = D->getType();
17583 // A variable that is privatized must not have a const-qualified type
17589 // const-qualified type unless it is of class type with a mutable member.
17596 if (LPKind == OMPC_LASTPRIVATE_conditional && !Type->isScalarType()) {
17598 bool IsDecl = !VD || VD->isThisDeclarationADefinition(getASTContext()) ==
17600 Diag(D->getLocation(),
17606 OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective();
17607 // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced
17609 // Variables with the predetermined data-sharing attributes may not be
17610 // listed in data-sharing attributes clauses, except for the cases
17615 DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false);
17637 DVar = DSAStack->getImplicitDSA(D, true);
17658 D->hasAttrs() ? &D->getAttrs() : nullptr);
17663 D->hasAttrs() ? &D->getAttrs() : nullptr);
17677 if (!VD && !SemaRef.CurContext->isDependentContext()) {
17683 ExprCaptures.push_back(Ref->getDecl());
17687 Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) {
17692 SemaRef.BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign,
17700 DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref);
17701 Vars.push_back((VD || SemaRef.CurContext->isDependentContext())
17702 ? RefExpr->IgnoreParens()
17739 // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
17741 // Variables with the predetermined data-sharing attributes may not be
17742 // listed in data-sharing attributes clauses, except for the cases
17744 // variable in a data-sharing attribute clause is allowed and overrides
17745 // the variable's predetermined data-sharing attributes.
17746 DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false);
17757 !SemaRef.CurContext->isDependentContext())
17759 DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref);
17760 Vars.push_back((VD || !Ref || SemaRef.CurContext->isDependentContext())
17761 ? RefExpr->IgnoreParens()
17778 if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) {
17779 DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, /*FromParent=*/false);
17784 DSAStackTy::DSAVarData DVarPrivate = Stack->hasDSA(
17796 for (Stmt *Child : S->children()) {
17819 if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) &&
17820 E->getMemberDecl() == Field) {
17845 for (auto *RD : D->redecls()) {
17846 // Don't bother with extra checks if we already know this one isn't visible.
17886 // -- Any using-directives in the associated namespace are
17889 // -- Any namespace-scope friend functions declared in
17893 DeclContext::lookup_result R = NS->lookup(Id.getName());
17897 Underlying = USD->getTargetDecl();
17908 Underlying = USD->getTargetDecl();
17931 S = S->getParent();
17932 } while (S && !S->isDeclScope(D));
17934 S = S->getParent();
17943 for (NamedDecl *D : ULE->decls()) {
17951 if (SemaRef.CurContext->isDependentContext() || Ty->isDependentType() ||
17952 Ty->isInstantiationDependentType() ||
17953 Ty->containsUnexpandedParameterPack() ||
17955 return !D->isInvalidDecl() &&
17956 (D->getType()->isDependentType() ||
17957 D->getType()->isInstantiationDependentType() ||
17958 D->getType()->containsUnexpandedParameterPack());
17966 ResSet.addDecl(Set[Set.size() - 1]);
17977 // cv-unqualified version is T1, and for a binary operator @ with
17978 // a left operand of a type whose cv-unqualified version is T1 and
17979 // a right operand of a type whose cv-unqualified version is T2,
17981 // candidates, non-member candidates and built-in candidates, are
17983 // -- If T1 is a complete class type or a class currently being
17989 if (const auto *TyRec = Ty->getAs<RecordType>()) {
17992 if (SemaRef.isCompleteType(Loc, Ty) || TyRec->isBeingDefined() ||
17993 TyRec->getDecl()->getDefinition()) {
17995 SemaRef.LookupQualifiedName(Lookup, TyRec->getDecl());
18006 Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * {
18007 if (!D->isInvalidDecl() &&
18008 SemaRef.Context.hasSameType(D->getType(), Ty))
18012 return SemaRef.BuildDeclRefExpr(VD, VD->getType().getNonReferenceType(),
18016 Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * {
18017 if (!D->isInvalidDecl() &&
18018 SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) &&
18019 !Ty.isMoreQualifiedThan(D->getType()))
18025 if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) {
18027 VD->getType().getUnqualifiedType()))) {
18029 Loc, VD->getType(), Ty, Paths.front(),
18033 VD, VD->getType().getNonReferenceType(), VK_LValue, Loc);
18048 /// Data for the reduction-based clauses.
18133 const Expr *Length = OASE->getLength();
18137 if (OASE->getColonLocFirst().isValid())
18145 if (!Length->EvaluateAsInt(Result, Context))
18154 const Expr *Base = OASE->getBase()->IgnoreParenImpCasts();
18156 // We require length = 1 for all array sections except the right-most to
18159 Length = TempOASE->getLength();
18163 if (OASE->getColonLocFirst().isValid())
18170 if (!Length->EvaluateAsInt(Result, Context))
18179 Base = TempOASE->getBase()->IgnoreParenImpCasts();
18187 Base = TempASE->getBase()->IgnoreParenImpCasts();
18224 // reduction-identifier is either an identifier or one of the following
18225 // operators: +, -, *, &, |, ^, && and ||
18227 // reduction-identifier is either an id-expression or one of the following
18228 // operators: +, -, *, &, |, ^, && and ||
18234 // Minus(-) operator is not supported in TR11 (OpenMP 6.0). Setting BOK to
18301 if (II->isStr("max"))
18303 else if (II->isStr("min"))
18310 // A reduction clause with the minus (-) operator was deprecated
18346 S, ELoc, ERange, Stack->getCurScope(), ReductionIdScopeSpec,
18349 if (S.CurContext->isDependentContext() &&
18362 auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens());
18363 auto *OASE = dyn_cast<ArraySectionExpr>(RefExpr->IgnoreParens());
18365 Type = ASE->getType().getNonReferenceType();
18368 ArraySectionExpr::getBaseOriginalType(OASE->getBase());
18369 if (const auto *ATy = BaseType->getAsArrayTypeUnsafe())
18370 Type = ATy->getElementType();
18372 Type = BaseType->getPointeeType();
18375 Type = Context.getBaseElementType(D->getType().getNonReferenceType());
18382 if (S.RequireCompleteType(ELoc, D->getType(),
18387 // const-qualified.
18392 OpenMPDirectiveKind CurrDir = Stack->getCurrentDirective();
18394 // If a list-item is a reference type then it must bind to the same object
18398 VarDecl *VDDef = VD->getDefinition();
18399 if (VD->getType()->isReferenceType() && VDDef && VDDef->hasInit()) {
18401 if (Check.Visit(VDDef->getInit())) {
18404 S.Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef;
18410 // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced
18412 // Variables with the predetermined data-sharing attributes may not be
18413 // listed in data-sharing attributes clauses, except for the cases
18415 // variable in a data-sharing attribute clause is allowed and overrides
18416 // the variable's predetermined data-sharing attributes.
18421 DSAStackTy::DSAVarData DVar = Stack->getTopDSA(D, /*FromParent=*/false);
18426 S.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced);
18444 DVar = Stack->getImplicitDSA(D, true);
18456 DSAStackTy::DSAVarData DVar = Stack->getTopDSA(D, /*FromParent=*/false);
18470 S, ELoc, ERange, Stack->getCurScope(), ReductionIdScopeSpec,
18474 if (S.CurContext->isDependentContext() &&
18495 // for the reduction-identifier. For a max or min reduction in C, the type
18503 !(Type->isScalarType() ||
18504 (S.getLangOpts().CPlusPlus && Type->isArithmeticType()))) {
18508 bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) ==
18510 S.Diag(D->getLocation(),
18517 !S.getLangOpts().CPlusPlus && Type->isFloatingType()) {
18521 bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) ==
18523 S.Diag(D->getLocation(),
18533 D->hasAttrs() ? &D->getAttrs() : nullptr);
18534 VarDecl *RHSVD = buildVarDecl(S, ELoc, Type, D->getName(),
18535 D->hasAttrs() ? &D->getAttrs() : nullptr);
18558 D->getType().getNonReferenceType()->isVariablyModifiedType())) {
18560 if (isOpenMPTargetExecutionDirective(Stack->getCurrentDirective())) {
18580 Context.getAsArrayType(D->getType().getNonReferenceType())) {
18581 PrivateTy = D->getType().getNonReferenceType();
18585 buildVarDecl(S, ELoc, PrivateTy, D->getName(),
18586 D->hasAttrs() ? &D->getAttrs() : nullptr,
18594 auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl());
18595 if (DRD->getInitializer()) {
18597 RHSVD->setInit(DRDRef);
18598 RHSVD->setInitStyle(VarDecl::CallInit);
18606 // '+', '-', '^', '|', '||' reduction ops - initializer is '0'.
18607 if (Type->isScalarType() || Type->isAnyComplexType())
18612 if (Type->isScalarType() || Type->isAnyComplexType()) {
18613 // '*' and '&&' reduction ops - initializer is '1'.
18618 // '&' reduction op - initializer is '~0'.
18620 if (auto *ComplexTy = OrigType->getAs<ComplexType>())
18621 Type = ComplexTy->getElementType();
18622 if (Type->isRealFloatingType()) {
18627 } else if (Type->isScalarType()) {
18633 if (Init && OrigType->isAnyComplexType()) {
18643 // 'min' reduction op - initializer is 'Largest representable number in
18645 // 'max' reduction op - initializer is 'Least representable number in
18647 if (Type->isIntegerType() || Type->isPointerType()) {
18648 bool IsSigned = Type->hasSignedIntegerRepresentation();
18658 if (Type->isPointerType()) {
18666 } else if (Type->isRealFloatingType()) {
18705 PrivateVD->setInit(RHSVD->getInit());
18706 PrivateVD->setInitStyle(RHSVD->getInitStyle());
18711 PrivateVD->setInit(RHSVD->getInit());
18712 PrivateVD->setInitStyle(RHSVD->getInitStyle());
18714 if (RHSVD->isInvalidDecl())
18716 if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) {
18719 bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) ==
18721 S.Diag(D->getLocation(),
18729 QualType RedTy = DeclareReductionRef.get()->getType();
18738 LHS.get()->getValueKind(), FPOptionsOverride());
18741 RHS.get()->getValueKind(), FPOptionsOverride());
18755 if (Type->isRecordType() && CombBOK != BOK) {
18758 S.BuildBinOp(Stack->getCurScope(), ReductionId.getBeginLoc(),
18763 S.BuildBinOp(Stack->getCurScope(), ReductionId.getBeginLoc(), BOK,
18768 S.BuildBinOp(Stack->getCurScope(), ReductionId.getBeginLoc(),
18775 S.BuildBinOp(Stack->getCurScope(), ReductionId.getBeginLoc(),
18793 CopyOpRes = S.BuildBinOp(Stack->getCurScope(), ELoc, BO_Assign, LHSDRE,
18801 // For simd directive and simd-based directives in simd mode no need to
18803 if (Stack->getCurrentDirective() == OMPD_simd ||
18805 isOpenMPSimdDirective(Stack->getCurrentDirective()))) {
18807 buildVarDecl(S, ELoc, PrivateTy, D->getName(),
18808 D->hasAttrs() ? &D->getAttrs() : nullptr);
18820 buildVarDecl(S, ELoc, ArrayTy, D->getName(),
18821 D->hasAttrs() ? &D->getAttrs() : nullptr);
18839 // condition must specify the same reduction-identifier as the in_reduction
18847 Stack->getTopMostTaskgroupReductionData(D, ParentSR, ParentBOK,
18850 Stack->getTopMostTaskgroupReductionData(
18860 ParentReductionOp->Profile(ParentRedId, Context, /*Canonical=*/true);
18861 DeclareReductionRef.get()->Profile(RedId, Context,
18868 << ReductionIdRange << RefExpr->getSourceRange();
18874 ->getSourceRange();
18882 Expr *VarsExpr = RefExpr->IgnoreParens();
18883 if (!VD && !S.CurContext->isDependentContext()) {
18887 RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get();
18893 RD.ExprCaptures.emplace_back(Ref->getDecl());
18894 if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) {
18899 S.BuildBinOp(Stack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr,
18903 if (isOpenMPTaskingDirective(Stack->getCurrentDirective()) ||
18904 Stack->getCurrentDirective() == OMPD_taskgroup) {
18905 S.Diag(RefExpr->getExprLoc(),
18907 << RefExpr->getSourceRange();
18922 Stack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref, Modifier,
18930 Stack->addTaskgroupReductionData(D, ReductionIdRange,
18933 Stack->addTaskgroupReductionData(D, ReductionIdRange, BOK);
18956 // A reduction clause with the inscan reduction-modifier may only appear on a
18957 // worksharing-loop construct, a worksharing-loop SIMD construct, a simd
18958 // construct, a parallel worksharing-loop construct or a parallel
18959 // worksharing-loop SIMD construct.
18961 (DSAStack->getCurrentDirective() != OMPD_for &&
18962 DSAStack->getCurrentDirective() != OMPD_for_simd &&
18963 DSAStack->getCurrentDirective() != OMPD_simd &&
18964 DSAStack->getCurrentDirective() != OMPD_parallel_for &&
18965 DSAStack->getCurrentDirective() != OMPD_parallel_for_simd)) {
19047 !Type->isReferenceType()) {
19055 // A variable that is privatized must not have a const-qualified type
19066 if (!Ty || (LinKind != OMPC_LINEAR_ref && !Ty->isDependentType() &&
19067 !Ty->isIntegralType(getASTContext()) && !Ty->isPointerType())) {
19070 bool IsDecl = !VD || VD->isThisDeclarationADefinition(getASTContext()) ==
19072 Diag(D->getLocation(),
19092 // step-simple-modifier is exclusive, can't be used with 'val', 'uval', or
19096 Diag(Step->getBeginLoc(), diag::err_omp_step_simple_modifier_exclusive);
19115 QualType Type = D->getType();
19119 // A list-item cannot appear in more than one linear clause.
19120 // A list-item that appears in a linear clause cannot appear in any
19121 // other data-sharing attribute clause.
19122 DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false);
19136 buildVarDecl(SemaRef, ELoc, Type, D->getName(),
19137 D->hasAttrs() ? &D->getAttrs() : nullptr,
19144 if (!VD && !SemaRef.CurContext->isDependentContext()) {
19147 ExprCaptures.push_back(Ref->getDecl());
19148 if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) {
19153 SemaRef.BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign,
19163 InitExpr = VD ? VD->getInit() : SimpleRefExpr;
19171 DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref);
19172 Vars.push_back((VD || SemaRef.CurContext->isDependentContext())
19173 ? RefExpr->IgnoreParens()
19184 if (Step && !Step->isValueDependent() && !Step->isTypeDependent() &&
19185 !Step->isInstantiationDependent() &&
19186 !Step->containsUnexpandedParameterPack()) {
19187 SourceLocation StepLoc = Step->getBeginLoc();
19195 buildVarDecl(SemaRef, StepLoc, StepExpr->getType(), ".linear.step");
19197 buildDeclRefExpr(SemaRef, SaveVar, StepExpr->getType(), StepLoc);
19206 StepExpr->getIntegerConstantExpr(getASTContext())) {
19207 if (!Result->isNegative() && !Result->isStrictlyPositive())
19212 // (This is not used if the number of iterations may be kfold-ed).
19234 // If linear-step is not specified it is assumed to be 1.
19238 Step = cast<BinaryOperator>(CalcStep)->getLHS();
19255 auto &&Info = Stack->isLoopControlVariable(D);
19259 if (isOpenMPDistributeDirective(Stack->getCurrentDirective()) &&
19260 isOpenMPSimdDirective(Stack->getCurrentDirective()) && !Info.first) {
19274 CapturedRef = cast<VarDecl>(DE->getDecl())->getInit();
19277 buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()),
19278 DE->getType().getUnqualifiedType(), DE->getExprLoc(),
19285 SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, InitExpr, IV, Step,
19289 Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getBeginLoc(),
19296 S, RefExpr->getExprLoc(), BO_Assign, CapturedRef,
19300 Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getBeginLoc(),
19320 UsedExprs.append(Clause.varlist_size() + 1 - UsedExprs.size(), nullptr);
19345 QualType QType = D->getType();
19353 if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) {
19356 bool IsDecl = !VD || VD->isThisDeclarationADefinition(getASTContext()) ==
19358 Diag(D->getLocation(),
19365 // A list-item cannot appear in more than one aligned clause.
19366 if (const Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) {
19369 Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa)
19379 (VD || !Ref) ? RefExpr->IgnoreParens() : Ref)
19386 // If no optional parameter is specified, implementation-defined default
19421 SourceLocation ELoc = RefExpr->getExprLoc();
19427 if (!DE || !isa<VarDecl>(DE->getDecl())) {
19429 << 0 << RefExpr->getSourceRange();
19433 Decl *D = DE->getDecl();
19436 QualType Type = VD->getType();
19437 if (Type->isDependentType() || Type->isInstantiationDependentType()) {
19448 if (!DSAStack->isThreadPrivate(VD)) {
19462 buildVarDecl(SemaRef, DE->getBeginLoc(), ElemType.getUnqualifiedType(),
19463 ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr);
19465 SemaRef, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc());
19467 buildVarDecl(SemaRef, DE->getBeginLoc(), ElemType, ".copyin.dst",
19468 VD->hasAttrs() ? &VD->getAttrs() : nullptr);
19470 buildDeclRefExpr(SemaRef, DstVD, ElemType, DE->getExprLoc());
19474 SemaRef.BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign,
19479 SemaRef.ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(),
19484 DSAStack->addDSA(VD, DE, OMPC_copyin);
19523 QualType Type = D->getType();
19529 if (!VD || !DSAStack->isThreadPrivate(VD)) {
19531 DSAStack->getTopDSA(D, /*FromParent=*/false);
19545 DVar = DSAStack->getImplicitDSA(D, false);
19557 if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) {
19560 << getOpenMPDirectiveName(DSAStack->getCurrentDirective());
19561 bool IsDecl = !VD || VD->isThisDeclarationADefinition(getASTContext()) ==
19563 Diag(D->getLocation(),
19577 buildVarDecl(SemaRef, RefExpr->getBeginLoc(), Type, ".copyprivate.src",
19578 D->hasAttrs() ? &D->getAttrs() : nullptr);
19581 buildVarDecl(SemaRef, RefExpr->getBeginLoc(), Type, ".copyprivate.dst",
19582 D->hasAttrs() ? &D->getAttrs() : nullptr);
19585 DSAStack->getCurScope(), ELoc, BO_Assign, PseudoDstExpr, PseudoSrcExpr);
19597 VD ? RefExpr->IgnoreParens()
19626 QualType OMPDependT = Stack->getOMPDependT();
19636 Stack->setOMPDependT(PT.get());
19651 if (!Depobj->isTypeDependent() && !Depobj->isValueDependent() &&
19652 !Depobj->isInstantiationDependent() &&
19653 !Depobj->containsUnexpandedParameterPack() &&
19655 DSAStack->getOMPDependT(), Depobj->getType(),
19657 Diag(Depobj->getExprLoc(), diag::err_omp_expected_omp_depend_t_lvalue)
19658 << 0 << Depobj->getType() << Depobj->getSourceRange();
19661 if (!Depobj->isLValue()) {
19662 Diag(Depobj->getExprLoc(), diag::err_omp_expected_omp_depend_t_lvalue)
19663 << 1 << Depobj->getSourceRange();
19692 Stack->getParentOrderedRegionParam().first) {
19693 TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(SemaRef.Context);
19705 SourceLocation ELoc = RefExpr->getExprLoc();
19706 Expr *SimpleExpr = RefExpr->IgnoreParenCasts();
19708 if (Stack->getParentOrderedRegionParam().first &&
19715 // depend(dependence-type : vec), where dependence-type is:
19717 // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn]
19719 // directive, xi denotes the loop iteration variable of the i-th nested
19721 // non-negative integer.
19722 if (SemaRef.CurContext->isDependentContext()) {
19727 SimpleExpr = SimpleExpr->IgnoreImplicit();
19733 OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode());
19734 OOLoc = BO->getOperatorLoc();
19735 LHS = BO->getLHS()->IgnoreParenImpCasts();
19736 RHS = BO->getRHS()->IgnoreParenImpCasts();
19738 OOK = OCE->getOperator();
19739 OOLoc = OCE->getOperatorLoc();
19740 LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts();
19741 RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts();
19743 OOK = MCE->getMethodDecl()
19744 ->getNameInfo()
19747 OOLoc = MCE->getCallee()->getExprLoc();
19748 LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts();
19749 RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts();
19773 if (!SemaRef.CurContext->isDependentContext() &&
19774 Stack->getParentOrderedRegionParam().first &&
19775 DepCounter != Stack->isParentLoopControlVariable(D).first) {
19777 Stack->getParentLoopControlVariable(DepCounter.getZExtValue());
19788 Vars.push_back(RefExpr->IgnoreParenImpCasts());
19790 if (!SemaRef.CurContext->isDependentContext() && !IsSource &&
19792 Stack->getParentOrderedRegionParam().first &&
19793 Stack->getParentLoopControlVariable(VarList.size() + 1)) {
19795 << 1 << Stack->getParentLoopControlVariable(VarList.size() + 1);
19806 if (DSAStack->getCurrentDirective() == OMPD_ordered &&
19812 if (DSAStack->getCurrentDirective() == OMPD_taskwait &&
19817 if ((DSAStack->getCurrentDirective() != OMPD_ordered ||
19818 DSAStack->getCurrentDirective() == OMPD_depobj) &&
19822 DSAStack->getCurrentDirective() == OMPD_depobj) &&
19828 DSAStack->getCurrentDirective() == OMPD_depobj)
19844 Diag(DepModifier->getExprLoc(),
19849 !DepModifier->getType()->isSpecificBuiltinType(BuiltinType::OMPIterator))
19850 Diag(DepModifier->getExprLoc(), diag::err_omp_depend_modifier_not_iterator);
19871 SourceLocation ELoc = RefExpr->getExprLoc();
19872 Expr *SimpleExpr = RefExpr->IgnoreParenCasts();
19882 if (!RefExpr->isValueDependent() && !RefExpr->isTypeDependent() &&
19883 !RefExpr->isInstantiationDependent() &&
19884 !RefExpr->containsUnexpandedParameterPack() &&
19887 DSAStack->getOMPDependT(), RefExpr->getType()))) {
19889 << 0 << RefExpr->getType() << RefExpr->getSourceRange();
19892 if (!RefExpr->isLValue()) {
19894 << 1 << RefExpr->getType() << RefExpr->getSourceRange();
19899 // List items used in depend clauses cannot be zero-length array
19901 QualType ExprTy = RefExpr->getType().getNonReferenceType();
19905 ArraySectionExpr::getBaseOriginalType(OASE->getBase());
19908 if (const auto *ATy = BaseType->getAsArrayTypeUnsafe())
19909 ExprTy = ATy->getElementType();
19911 ExprTy = BaseType->getPointeeType();
19915 const Expr *Length = OASE->getLength();
19917 if (Length && !Length->isValueDependent() &&
19918 Length->EvaluateAsInt(Result, getASTContext()) &&
19922 << SimpleExpr->getSourceRange();
19931 if (!RefExpr->isValueDependent() && !RefExpr->isTypeDependent() &&
19932 !RefExpr->isInstantiationDependent() &&
19933 !RefExpr->containsUnexpandedParameterPack() &&
19934 (!RefExpr->IgnoreParenImpCasts()->isLValue() ||
19935 (OMPDependTFound && DSAStack->getOMPDependT().getTypePtr() ==
19940 << RefExpr->getSourceRange();
19945 if (ASE && !ASE->getBase()->isTypeDependent() &&
19946 !ASE->getBase()
19947 ->getType()
19949 ->isPointerType() &&
19950 !ASE->getBase()->getType().getNonReferenceType()->isArrayType()) {
19954 << RefExpr->getSourceRange();
19962 RefExpr->IgnoreParenImpCasts());
19969 << RefExpr->getSourceRange();
19974 Vars.push_back(RefExpr->IgnoreParenImpCasts());
19988 DSAStack->isParentOrderedRegion())
19989 DSAStack->addDoacrossDependClause(C, OpsOffs);
20013 // The device expression must evaluate to a non-negative integer value.
20021 // In case of ancestor device-modifier, a requires directive with
20024 if (!DSAStack->hasRequiresDeclWithClause<OMPReverseOffloadClause>()) {
20032 OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
20036 !SemaRef.CurContext->isDependentContext()) {
20053 if (FullCheck && !SemaRef.CurContext->isDependentContext() &&
20071 (OASE && OASE->getColonLocFirst().isInvalid())) {
20073 return ATy->getSExtSize() != 1;
20079 const Expr *LowerBound = OASE->getLowerBound();
20080 const Expr *Length = OASE->getLength();
20086 if (!LowerBound->EvaluateAsInt(Result, SemaRef.getASTContext()))
20100 if (BaseQTy->isPointerType())
20110 if (!Length->EvaluateAsInt(Result, SemaRef.getASTContext()))
20114 return CATy->getSExtSize() != ConstLength.getSExtValue();
20128 (OASE && OASE->getColonLocFirst().isInvalid()))
20132 const Expr *Length = OASE->getLength();
20139 return ATy->getSExtSize() != 1;
20146 if (!Length->EvaluateAsInt(Result, SemaRef.getASTContext()))
20154 // - a reference to variable or field.
20155 // - a member expression.
20156 // - an array expression.
20170 // We want to retrieve the member expression 'this->S';
20217 if (!isa<VarDecl>(DRE->getDecl())) {
20224 Components.emplace_back(DRE, DRE->getDecl(), IsNonContiguous);
20230 Expr *BaseE = ME->getBase()->IgnoreParenCasts();
20234 // We found a base expression: this->Val.
20240 if (!isa<FieldDecl>(ME->getMemberDecl())) {
20243 << ME->getSourceRange();
20251 auto *FD = cast<FieldDecl>(ME->getMemberDecl());
20254 // A bit-field cannot appear in a map clause.
20256 if (FD->isBitField()) {
20259 << ME->getSourceRange() << getOpenMPClauseName(CKind);
20270 QualType CurType = BaseE->getType().getNonReferenceType();
20276 if (CurType->isUnionType()) {
20279 << ME->getSourceRange();
20301 Expr *E = AE->getBase()->IgnoreParenImpCasts();
20303 if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) {
20306 << 0 << AE->getSourceRange();
20314 // the dimension, we can only have unitary-size array expressions.
20315 if (checkArrayExpressionDoesNotReferToWholeSize(SemaRef, AE, E->getType()))
20318 if (const auto *TE = dyn_cast<CXXThisExpr>(E->IgnoreParenCasts())) {
20320 if (!AE->getIdx()->isValueDependent() &&
20321 AE->getIdx()->EvaluateAsInt(Result, SemaRef.getASTContext()) &&
20323 SemaRef.Diag(AE->getIdx()->getExprLoc(),
20325 SemaRef.Diag(AE->getIdx()->getExprLoc(),
20332 // Record the component - we don't have any declaration associated.
20343 Expr *E = OASE->getBase()->IgnoreParenImpCasts();
20350 if (CurType->isReferenceType())
20351 CurType = CurType->getPointeeType();
20353 bool IsPointer = CurType->isAnyPointerType();
20355 if (!IsPointer && !CurType->isArrayType()) {
20357 << 0 << OASE->getSourceRange();
20389 << OASE->getSourceRange();
20399 if (!OASE->getLength()->isValueDependent() &&
20400 OASE->getLength()->EvaluateAsInt(ResultR, SemaRef.getASTContext()) &&
20402 SemaRef.Diag(OASE->getLength()->getExprLoc(),
20404 SemaRef.Diag(OASE->getLength()->getExprLoc(),
20407 if (OASE->getLowerBound() && !OASE->getLowerBound()->isValueDependent() &&
20408 OASE->getLowerBound()->EvaluateAsInt(ResultL,
20411 SemaRef.Diag(OASE->getLowerBound()->getExprLoc(),
20413 SemaRef.Diag(OASE->getLowerBound()->getExprLoc(),
20420 // Record the component - we don't have any declaration associated.
20425 Expr *Base = E->getBase();
20427 // Record the component - we don't have any declaration associated.
20430 return Visit(Base->IgnoreParenImpCasts());
20434 if (SemaRef.getLangOpts().OpenMP < 50 || !UO->isLValue() ||
20435 UO->getOpcode() != UO_Deref) {
20443 return RelevantExpr || Visit(UO->getSubExpr()->IgnoreParenImpCasts());
20446 if (SemaRef.getLangOpts().OpenMP < 50 || !BO->getType()->isPointerType()) {
20455 Expr *LE = BO->getLHS()->IgnoreParenImpCasts();
20456 Expr *RE = BO->getRHS()->IgnoreParenImpCasts();
20458 assert((LE->getType().getTypePtr() == BO->getType().getTypePtr() ||
20459 RE->getType().getTypePtr() == BO->getType().getTypePtr()) &&
20461 if (BO->getType().getTypePtr() == LE->getType().getTypePtr())
20477 Expr *Source = E->getSourceExpr();
20506 SourceLocation ELoc = E->getExprLoc();
20507 SourceRange ERange = E->getSourceRange();
20510 if (Checker.Visit(E->IgnoreParens())) {
20518 dyn_cast<ArraySectionExpr>(CI->getAssociatedExpression());
20521 if (OASE && OASE->getLength())
20540 SourceLocation ELoc = E->getExprLoc();
20541 SourceRange ERange = E->getSourceRange();
20555 bool FoundError = DSAS->checkMappableExprComponentListsForDecl(
20587 (isa<ArraySubscriptExpr>(CI->getAssociatedExpression()) ||
20588 isa<ArraySectionExpr>(CI->getAssociatedExpression()) ||
20589 isa<OMPArrayShapingExpr>(CI->getAssociatedExpression())) &&
20590 (isa<ArraySubscriptExpr>(SI->getAssociatedExpression()) ||
20591 isa<ArraySectionExpr>(SI->getAssociatedExpression()) ||
20592 isa<OMPArrayShapingExpr>(SI->getAssociatedExpression()))) {
20593 SemaRef.Diag(CI->getAssociatedExpression()->getExprLoc(),
20595 << CI->getAssociatedExpression()->getSourceRange();
20596 SemaRef.Diag(SI->getAssociatedExpression()->getExprLoc(),
20598 << SI->getAssociatedExpression()->getSourceRange();
20603 if (CI->getAssociatedExpression()->getStmtClass() !=
20604 SI->getAssociatedExpression()->getStmtClass())
20608 if (CI->getAssociatedDeclaration() != SI->getAssociatedDeclaration())
20611 // Check if the extra components of the expressions in the enclosing
20617 dyn_cast<ArraySubscriptExpr>(SI->getAssociatedExpression())) {
20618 Type = ASE->getBase()->IgnoreParenImpCasts()->getType();
20620 SI->getAssociatedExpression())) {
20621 const Expr *E = OASE->getBase()->IgnoreParenImpCasts();
20624 SI->getAssociatedExpression())) {
20625 Type = OASE->getBase()->getType()->getPointeeType();
20627 if (Type.isNull() || Type->isAnyPointerType() ||
20629 SemaRef, SI->getAssociatedExpression(), Type))
20648 SemaRef.Diag(RE->getExprLoc(), diag::note_used_here)
20649 << RE->getSourceRange();
20659 std::prev(CI)->getAssociatedDeclaration()->getType();
20661 std::prev(CI)->getAssociatedExpression()->getExprLoc();
20679 if (DerivedType->isAnyPointerType()) {
20685 SemaRef.Diag(RE->getExprLoc(), diag::note_used_here)
20686 << RE->getSourceRange();
20689 if (CI->getAssociatedExpression()->getStmtClass() !=
20690 SI->getAssociatedExpression()->getStmtClass() ||
20691 CI->getAssociatedDeclaration()->getCanonicalDecl() ==
20692 SI->getAssociatedDeclaration()->getCanonicalDecl()) {
20696 SemaRef.Diag(RE->getExprLoc(), diag::note_used_here)
20697 << RE->getSourceRange();
20716 while (It != End && !It->getAssociatedDeclaration())
20720 if (It != Begin && It->getAssociatedDeclaration()
20721 ->getType()
20723 ->isAnyPointerType()) {
20735 SemaRef.Diag(RE->getExprLoc(), diag::note_used_here)
20736 << RE->getSourceRange();
20771 SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here)
20772 << EnclosingExpr->getSourceRange();
20779 // Look up the user-defined mapper given the mapper name and mapped type, and
20789 if (Type->isArrayType()) {
20790 assert(Type->getAsArrayTypeUnsafe() && "Expect to get a valid array type");
20791 Type = Type->getAsArrayTypeUnsafe()->getElementType().getCanonicalType();
20793 // Find all user-defined mappers with the given MapperId.
20801 while (S && !S->isDeclScope(D))
20802 S = S->getParent();
20804 S = S->getParent();
20810 // Extract the user-defined mappers with the given MapperId.
20812 for (NamedDecl *D : ULE->decls()) {
20820 if (SemaRef.CurContext->isDependentContext() || Type->isDependentType() ||
20821 Type->isInstantiationDependentType() ||
20822 Type->containsUnexpandedParameterPack() ||
20824 return !D->isInvalidDecl() &&
20825 (D->getType()->isDependentType() ||
20826 D->getType()->isInstantiationDependentType() ||
20827 D->getType()->containsUnexpandedParameterPack());
20844 if (!Type->isStructureOrClassType() && !Type->isUnionType() &&
20852 // Return the first user-defined mapper with the desired type.
20854 Lookups, [&SemaRef, Type](ValueDecl *D) -> ValueDecl * {
20855 if (!D->isInvalidDecl() &&
20856 SemaRef.Context.hasSameType(D->getType(), Type))
20861 // Find the first user-defined mapper with a type derived from the desired
20864 Lookups, [&SemaRef, Type, Loc](ValueDecl *D) -> ValueDecl * {
20865 if (!D->isInvalidDecl() &&
20866 SemaRef.IsDerivedFrom(Loc, Type, D->getType()) &&
20867 !Type.isMoreQualifiedThan(D->getType()))
20873 if (SemaRef.IsDerivedFrom(Loc, Type, VD->getType(), Paths)) {
20875 VD->getType().getUnqualifiedType()))) {
20877 Loc, VD->getType(), Type, Paths.front(),
20905 // The reference to the user-defined mapper associated with every expression.
20919 // components, variables, and user-defined mappers are extracted and used to
20935 // If the identifier of user-defined mapper is not specified, it is "default".
20962 SourceLocation ELoc = RE->getExprLoc();
20975 const Expr *VE = RE->IgnoreParenLValueCasts();
20977 if (VE->isValueDependent() || VE->isTypeDependent() ||
20978 VE->isInstantiationDependent() ||
20979 VE->containsUnexpandedParameterPack()) {
20980 // Try to find the associated user-defined mapper.
20982 SemaRef, DSAS->getCurScope(), MapperIdScopeSpec, MapperId,
20983 VE->getType().getCanonicalType(), UnresolvedMapper);
20993 Expr *SimpleExpr = RE->IgnoreParenCasts();
20995 if (!RE->isLValue()) {
20999 << RE->getSourceRange();
21002 << getOpenMPClauseName(CKind) << RE->getSourceRange();
21014 DSAS->getCurrentDirective(), NoDiagnose);
21023 DSAS->addMappedClassesQualTypes(TE->getType());
21024 // Try to find the associated user-defined mapper.
21026 SemaRef, DSAS->getCurScope(), MapperIdScopeSpec, MapperId,
21027 VE->getType().getCanonicalType(), UnresolvedMapper);
21046 CurDeclaration->isCanonicalDecl() &&
21059 if (VD && DSAS->isThreadPrivate(VD)) {
21062 DSAStackTy::DSAVarData DVar = DSAS->getTopDSA(VD, /*FromParent=*/false);
21070 // A list item cannot appear in both a map clause and a data-sharing
21098 auto *ASE = dyn_cast<ArraySubscriptExpr>(VE->IgnoreParens());
21099 auto *OASE = dyn_cast<ArraySectionExpr>(VE->IgnoreParens());
21100 auto *OAShE = dyn_cast<OMPArrayShapingExpr>(VE->IgnoreParens());
21102 Type = ASE->getType().getNonReferenceType();
21105 ArraySectionExpr::getBaseOriginalType(OASE->getBase());
21106 if (const auto *ATy = BaseType->getAsArrayTypeUnsafe())
21107 Type = ATy->getElementType();
21109 Type = BaseType->getPointeeType();
21112 Type = OAShE->getBase()->getType()->getPointeeType();
21114 Type = VE->getType();
21121 if (!checkTypeMappable(VE->getExprLoc(), VE->getSourceRange(), SemaRef,
21128 // A map-type must be specified in all map clauses and must be either
21131 OpenMPDirectiveKind DKind = DSAS->getCurrentDirective();
21144 // A map-type must be specified in all map clauses and must be either
21175 // A map-type in a map clause must be to, from, tofrom or alloc
21188 // A list item cannot appear in both a map clause and a data-sharing
21192 // A list item cannot appear in both a map clause and a data-sharing
21198 DSAStackTy::DSAVarData DVar = DSAS->getTopDSA(VD, /*FromParent=*/false);
21203 << getOpenMPDirectiveName(DSAS->getCurrentDirective());
21210 // Try to find the associated user-defined mapper.
21212 SemaRef, DSAS->getCurScope(), MapperIdScopeSpec, MapperId,
21223 DSAS->addMappableExpressionComponents(CurDeclaration, CurComponents,
21251 if (IteratorModifier && !IteratorModifier->getType()->isSpecificBuiltinType(
21253 Diag(IteratorModifier->getExprLoc(),
21256 // Process map-type-modifiers, flag errors for duplicate modifiers.
21278 // other diagnostics related with non-existing map clauses are accurate.
21303 if (ReductionType->isFunctionType()) {
21307 if (ReductionType->isReferenceType()) {
21311 if (ReductionType->isArrayType()) {
21330 // A reduction-identifier may not be re-declared in the current scope for the
21341 (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty();
21353 if (OMPDeclareReductionDecl *D = PrevDecl->getPrevDeclInScope())
21356 PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] =
21357 PrevDecl->getLocation();
21372 PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] =
21373 PrevDRDInScope->getLocation();
21374 PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope();
21383 Diag(I->second, diag::note_previous_definition);
21389 DC->addDecl(DRD);
21390 DRD->setAccess(AS);
21393 DRD->setInvalidDecl();
21408 SemaRef.getCurFunction()->setHasOMPDeclareReductionCombiner();
21418 QualType ReductionType = DRD->getType();
21426 buildVarDecl(SemaRef, D->getLocation(), ReductionType, "omp_in");
21434 buildVarDecl(SemaRef, D->getLocation(), ReductionType, "omp_out");
21439 DRD->addDecl(OmpInParm);
21440 DRD->addDecl(OmpOutParm);
21443 ::buildDeclRefExpr(SemaRef, OmpInParm, ReductionType, D->getLocation());
21445 ::buildDeclRefExpr(SemaRef, OmpOutParm, ReductionType, D->getLocation());
21446 DRD->setCombinerData(InE, OutE);
21459 DRD->setCombiner(Combiner);
21461 DRD->setInvalidDecl();
21480 QualType ReductionType = DRD->getType();
21488 buildVarDecl(SemaRef, D->getLocation(), ReductionType, "omp_priv");
21496 buildVarDecl(SemaRef, D->getLocation(), ReductionType, "omp_orig");
21501 DRD->addDecl(OmpPrivParm);
21502 DRD->addDecl(OmpOrigParm);
21505 ::buildDeclRefExpr(SemaRef, OmpOrigParm, ReductionType, D->getLocation());
21507 ::buildDeclRefExpr(SemaRef, OmpPrivParm, ReductionType, D->getLocation());
21508 DRD->setInitializerData(OrigE, PrivE);
21522 DRD->setInitializer(Initializer, OMPDeclareReductionInitKind::Call);
21523 } else if (OmpPrivParm->hasInit()) {
21524 DRD->setInitializer(OmpPrivParm->getInit(),
21525 OmpPrivParm->isDirectInit()
21529 DRD->setInvalidDecl();
21541 D->setInvalidDecl();
21550 QualType T = TInfo->getType();
21571 if (!MapperType->isStructureOrClassType() && !MapperType->isUnionType()) {
21586 // A mapper-identifier may not be redeclared in the current scope for the
21597 (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty();
21609 if (OMPDeclareMapperDecl *D = PrevDecl->getPrevDeclInScope())
21612 PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] =
21613 PrevDecl->getLocation();
21628 PreviousRedeclTypes[PrevDMDInScope->getType().getCanonicalType()] =
21629 PrevDMDInScope->getLocation();
21630 PrevDMDInScope = PrevDMDInScope->getPrevDeclInScope();
21638 Diag(I->second, diag::note_previous_definition);
21654 DC->addDecl(DMD);
21655 DMD->setAccess(AS);
21657 DMD->setInvalidDecl();
21659 auto *VD = cast<DeclRefExpr>(MapperVarRef)->getDecl();
21660 VD->setDeclContext(DMD);
21661 VD->setLexicalDeclContext(DMD);
21662 DMD->addDecl(VD);
21663 DMD->setMapperVarRef(MapperVarRef);
21679 DSAStack->addDeclareMapperVarRef(E);
21684 if (DSAStack->getDeclareMapperVarRef())
21685 DSAStack->addIteratorVarDecl(VD);
21690 const Expr *Ref = DSAStack->getDeclareMapperVarRef();
21692 if (VD->getCanonicalDecl() == DRE->getDecl()->getCanonicalDecl())
21694 if (VD->isUsableInConstantExpressions(getASTContext()))
21696 if (getLangOpts().OpenMP >= 52 && DSAStack->isIteratorVarDecl(VD))
21705 return cast<DeclRefExpr>(DSAStack->getDeclareMapperVarRef())->getDecl();
21721 OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
21725 !SemaRef.CurContext->isDependentContext()) {
21749 OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
21753 !SemaRef.CurContext->isDependentContext()) {
21773 // The priority-value is a non-negative numerical scalar expression.
21777 DSAStack->getCurrentDirective(), &CaptureRegion, &HelperValStmt))
21809 DSAStack->getCurrentDirective(),
21843 DSAStack->getCurrentDirective(), &CaptureRegion, &HelperValStmt))
21856 // ... where hint-expression is an integer constant expression that evaluates
21869 QualType OMPEventHandleT = Stack->getOMPEventHandleT();
21878 Stack->setOMPEventHandleT(PT.get());
21886 if (!Evt->isValueDependent() && !Evt->isTypeDependent() &&
21887 !Evt->isInstantiationDependent() &&
21888 !Evt->containsUnexpandedParameterPack()) {
21889 if (!findOMPEventHandleT(SemaRef, Evt->getExprLoc(), DSAStack))
21892 // event-handle is a variable of the omp_event_handle_t type.
21893 auto *Ref = dyn_cast<DeclRefExpr>(Evt->IgnoreParenImpCasts());
21895 Diag(Evt->getExprLoc(), diag::err_omp_var_expected)
21896 << "omp_event_handle_t" << 0 << Evt->getSourceRange();
21899 auto *VD = dyn_cast_or_null<VarDecl>(Ref->getDecl());
21901 Diag(Evt->getExprLoc(), diag::err_omp_var_expected)
21902 << "omp_event_handle_t" << 0 << Evt->getSourceRange();
21905 if (!getASTContext().hasSameUnqualifiedType(DSAStack->getOMPEventHandleT(),
21906 VD->getType()) ||
21907 VD->getType().isConstant(getASTContext())) {
21908 Diag(Evt->getExprLoc(), diag::err_omp_var_expected)
21909 << "omp_event_handle_t" << 1 << VD->getType()
21910 << Evt->getSourceRange();
21914 // [detach clause]... The event-handle will be considered as if it was
21916 DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, /*FromParent=*/false);
21919 Diag(Evt->getExprLoc(), diag::err_omp_wrong_dsa)
21947 if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() &&
21948 !ChunkSize->isInstantiationDependent() &&
21949 !ChunkSize->containsUnexpandedParameterPack()) {
21950 SourceLocation ChunkSizeLoc = ChunkSize->getBeginLoc();
21962 ValExpr->getIntegerConstantExpr(getASTContext())) {
21963 if (Result->isSigned() && !Result->isStrictlyPositive()) {
21965 << "dist_schedule" << ChunkSize->getSourceRange();
21969 DSAStack->getCurrentDirective(), OMPC_dist_schedule,
21971 !SemaRef.CurContext->isDependentContext()) {
22053 if (DSAStack->checkDefaultmapCategory(Kind)) {
22059 // Variable category is not specified - mark all categories.
22060 DSAStack->setDefaultDMAAttr(M, OMPC_DEFAULTMAP_aggregate, StartLoc);
22061 DSAStack->setDefaultDMAAttr(M, OMPC_DEFAULTMAP_scalar, StartLoc);
22062 DSAStack->setDefaultDMAAttr(M, OMPC_DEFAULTMAP_pointer, StartLoc);
22064 DSAStack->setDefaultDMAAttr(M, Kind, StartLoc);
22074 if (!CurLexicalContext->isFileContext() &&
22075 !CurLexicalContext->isExternCContext() &&
22076 !CurLexicalContext->isExternCXXContext() &&
22085 // Report affected OpenMP target offloading behavior when in HIP lang-mode.
22159 if (!VD->isFileVarDecl() && !VD->isStaticLocal() &&
22160 !VD->isStaticDataMember()) {
22162 << VD->getNameAsString();
22169 (ND->isUsed(/*CheckUsedAttr=*/false) || ND->isReferenced()))
22172 // Report affected OpenMP target offloading behavior when in HIP lang-mode.
22177 const unsigned Level = -1;
22182 if (ActiveAttr && (*ActiveAttr)->getDevType() != DTCI.DT &&
22183 (*ActiveAttr)->getLevel() == Level) {
22187 (*ActiveAttr)->getDevType());
22190 if (ActiveAttr && (*ActiveAttr)->getMapType() != MT &&
22191 (*ActiveAttr)->getLevel() == Level) {
22196 if (ActiveAttr && (*ActiveAttr)->getLevel() == Level)
22209 ND->addAttr(A);
22211 ML->DeclarationMarkedOpenMPDeclareTarget(ND, A);
22214 getLangOpts().OpenMP && VD && VD->hasAttr<OMPDeclareTargetDeclAttr>() &&
22215 VD->hasGlobalStorage())
22229 VD->hasGlobalStorage()) {
22237 SemaRef.Diag(VD->getLocation(),
22246 SemaRef.Diag(VD->getLocation(), diag::warn_omp_not_in_target_context);
22254 checkTypeMappable(SL, SR, SemaRef, Stack, VD->getType(),
22260 if (!D || D->isInvalidDecl())
22262 SourceRange SR = E ? E->getSourceRange() : D->getSourceRange();
22263 SourceLocation SL = E ? E->getBeginLoc() : D->getLocation();
22266 if (!VD->isFileVarDecl() && !VD->isStaticLocal() &&
22267 !VD->isStaticDataMember())
22271 if (DSAStack->isThreadPrivate(VD)) {
22273 reportOriginalDsa(SemaRef, DSAStack, VD, DSAStack->getTopDSA(VD, false));
22278 D = FTD->getTemplatedDecl();
22284 Diag(FD->getLocation(), diag::note_defined_here) << FD;
22291 if ((E || !VD->getType()->isIncompleteType()) &&
22301 if (ActiveAttr && (*ActiveAttr)->getLevel() >= Level)
22317 D->addAttr(A);
22319 ML->DeclarationMarkedOpenMPDeclareTarget(D, A);
22326 checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), SemaRef, D);
22339 if (auto *VD = dyn_cast<VarDecl>(Node->getDecl())) {
22340 VD->addAttr(A);
22346 for (auto *Child : Ex->children()) {
22355 A = TD->getAttr<OMPDeclareTargetDeclAttr>();
22359 if (TargetVarDecl->hasAttr<OMPDeclareTargetDeclAttr>() &&
22360 TargetVarDecl->hasInit() && TargetVarDecl->hasGlobalStorage()) {
22361 if (Expr *Ex = TargetVarDecl->getInit())
22387 // Process motion-modifiers, flag errors for duplicate modifiers.
22424 // Process motion-modifiers, flag errors for duplicate modifiers.
22474 QualType Type = D->getType();
22480 if (!Type->isPointerType()) {
22482 << 0 << RefExpr->getSourceRange();
22488 buildVarDecl(SemaRef, ELoc, Type, D->getName(),
22489 D->hasAttrs() ? &D->getAttrs() : nullptr,
22491 if (VDPrivate->isInvalidDecl())
22494 SemaRef.CurContext->addDecl(VDPrivate);
22496 SemaRef, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc);
22500 buildVarDecl(SemaRef, RefExpr->getExprLoc(), Type, ".devptr.temp");
22502 SemaRef, VDInit, RefExpr->getType(), RefExpr->getExprLoc());
22512 MVLI.ProcessedVarList.push_back(VD ? RefExpr->IgnoreParens() : Ref);
22519 DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref);
22563 MVLI.ProcessedVarList.push_back(VD ? RefExpr->IgnoreParens() : Ref);
22568 DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref);
22575 if (VD && (isa<ArraySectionExpr>(RefExpr->IgnoreParenImpCasts()) ||
22576 isa<ArraySubscriptExpr>(RefExpr->IgnoreParenImpCasts())))
22609 QualType Type = D->getType();
22611 if (!Type.getNonReferenceType()->isPointerType() &&
22612 !Type.getNonReferenceType()->isArrayType()) {
22614 << 0 << RefExpr->getSourceRange();
22620 DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false);
22625 << getOpenMPDirectiveName(DSAStack->getCurrentDirective());
22631 if (DSAStack->checkMappableExprComponentListsForDecl(
22635 OpenMPClauseKind) -> bool {
22639 Diag(ELoc, diag::err_omp_map_shared_storage) << RefExpr->getSourceRange();
22640 Diag(ConflictExpr->getExprLoc(), diag::note_used_here)
22641 << ConflictExpr->getSourceRange();
22649 DSAStack->addMappableExpressionComponents(
22659 isa<CXXThisExpr>(cast<MemberExpr>(SimpleRefExpr)->getBase())) &&
22696 DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false);
22701 << getOpenMPDirectiveName(DSAStack->getCurrentDirective());
22707 if (DSAStack->checkMappableExprComponentListsForDecl(
22711 OpenMPClauseKind) -> bool {
22715 Diag(ELoc, diag::err_omp_map_shared_storage) << RefExpr->getSourceRange();
22716 Diag(ConflictExpr->getExprLoc(), diag::note_used_here)
22717 << ConflictExpr->getSourceRange();
22725 if (VD && (isa<ArraySectionExpr>(RefExpr->IgnoreParenImpCasts()) ||
22726 isa<ArraySubscriptExpr>(RefExpr->IgnoreParenImpCasts())))
22731 DSAStack->addMappableExpressionComponents(
22735 if (!VD && !SemaRef.CurContext->isDependentContext()) {
22741 MVLI.ProcessedVarList.push_back(RefExpr->IgnoreParens());
22747 isa<CXXThisExpr>(cast<MemberExpr>(SimpleRefExpr)->getBase())) &&
22769 if (!findOMPAllocatorHandleT(SemaRef, Allocator->getExprLoc(), DSAStack))
22776 AllocatorRes.get(), DSAStack->getOMPAllocatorHandleT(),
22789 !DSAStack->hasRequiresDeclWithClause<OMPDynamicAllocatorsClause>())
22810 if (!VD && !SemaRef.CurContext->isDependentContext())
22812 Vars.push_back((VD || SemaRef.CurContext->isDependentContext())
22813 ? RefExpr->IgnoreParens()
22821 DSAStack->addInnerAllocatorExpr(Allocator);
22845 // A list-item cannot appear in more than one nontemporal clause.
22847 DSAStack->addUniqueNontemporal(D, SimpleRefExpr)) {
22850 Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa)
22898 DSAStack->getTopDSA(D, /*FromParent=*/true);
22902 // worksharing-loop, worksharing-loop SIMD, or simd construct.
22905 << RefExpr->getSourceRange();
22907 if (DSAStack->getParentDirective() != OMPD_unknown)
22908 DSAStack->markDeclAsUsedInScanDirective(D);
22938 OpenMPDirectiveKind ParentDirective = DSAStack->getParentDirective();
22941 DVar = DSAStack->getTopDSA(D, /*FromParent=*/true);
22945 // worksharing-loop, worksharing-loop SIMD, or simd construct.
22949 << RefExpr->getSourceRange();
22951 DSAStack->markDeclAsUsedInScanDirective(D);
22965 QualType OMPAlloctraitT = Stack->getOMPAlloctraitT();
22974 Stack->setOMPAlloctraitT(PT.get());
22987 // allocator-traits-array is an identifier of const omp_alloctrait_t * type.
23007 if (D.Allocator->isTypeDependent()) {
23010 // Traits were specified - need to assign new allocator to the specified
23012 AllocatorExpr = D.Allocator->IgnoreParenImpCasts();
23022 QualType OMPAllocatorHandleT = DSAStack->getOMPAllocatorHandleT();
23023 QualType AllocatorExprType = AllocatorExpr->getType();
23032 !AllocatorExprType.isConstant(Context) && AllocatorExpr->isLValue();
23035 Diag(D.Allocator->getExprLoc(), diag::err_omp_var_expected)
23037 << AllocatorExpr->getType() << D.Allocator->getSourceRange();
23044 Diag(D.AllocatorTraits->getExprLoc(),
23046 << D.AllocatorTraits->getSourceRange();
23047 Diag(D.Allocator->getExprLoc(), diag::note_omp_predefined_allocator)
23048 << cast<NamedDecl>(DRE->getDecl())->getName()
23049 << D.Allocator->getSourceRange();
23053 // Non-predefined allocators appearing in a uses_allocators clause must
23056 Diag(D.Allocator->getExprLoc(),
23060 // No allocator traits - just convert it to rvalue.
23063 DSAStack->addUsesAllocatorsDecl(
23064 DRE->getDecl(),
23071 if (D.AllocatorTraits->isTypeDependent()) {
23078 AllocatorTraitsExpr = D.AllocatorTraits->IgnoreParenImpCasts();
23082 AllocatorTraitsExpr->getType()->getAsArrayTypeUnsafe())
23084 TraitTy = ConstArrayTy->getElementType();
23087 DSAStack->getOMPAlloctraitT()) ||
23088 Context.typesAreCompatible(TraitTy, DSAStack->getOMPAlloctraitT(),
23090 Diag(D.AllocatorTraits->getExprLoc(),
23092 << AllocatorTraitsExpr->getType();
23098 DSAStack->addUsesAllocatorsDecl(
23099 DRE->getDecl(),
23119 if (isa<DependentScopeDeclRefExpr>(RefExpr) || RefExpr->isTypeDependent()) {
23125 SourceLocation ELoc = RefExpr->getExprLoc();
23126 Expr *SimpleExpr = RefExpr->IgnoreParenImpCasts();
23128 if (!SimpleExpr->isLValue()) {
23130 << 1 << 0 << RefExpr->getSourceRange();
23142 << 1 << 0 << RefExpr->getSourceRange();
23183 OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
23187 !SemaRef.CurContext->isDependentContext()) {
23203 if (DSAStack->getCurrentDirective() == OMPD_ordered &&
23228 if (DSAStack->isParentOrderedRegion())
23229 DSAStack->addDoacrossDependClause(C, OpsOffs);
23251 if (Base->hasPlaceholderType() &&
23252 !Base->hasPlaceholderType(BuiltinType::ArraySection)) {
23258 if (LowerBound && LowerBound->getType()->isNonOverloadPlaceholderType()) {
23267 if (Length && Length->getType()->isNonOverloadPlaceholderType()) {
23276 if (Stride && Stride->getType()->isNonOverloadPlaceholderType()) {
23286 // Build an unanalyzed expression if either operand is type-dependent.
23287 if (Base->isTypeDependent() ||
23289 (LowerBound->isTypeDependent() || LowerBound->isValueDependent())) ||
23290 (Length && (Length->isTypeDependent() || Length->isValueDependent())) ||
23291 (Stride && (Stride->isTypeDependent() || Stride->isValueDependent()))) {
23300 if (OriginalTy->isAnyPointerType()) {
23301 ResultTy = OriginalTy->getPointeeType();
23302 } else if (OriginalTy->isArrayType()) {
23303 ResultTy = OriginalTy->getAsArrayTypeUnsafe()->getElementType();
23306 Diag(Base->getExprLoc(), diag::err_omp_typecheck_section_value)
23307 << Base->getSourceRange());
23311 auto Res = PerformOpenMPImplicitIntegerConversion(LowerBound->getExprLoc(),
23314 return ExprError(Diag(LowerBound->getExprLoc(),
23316 << 0 << LowerBound->getSourceRange());
23319 if (LowerBound->getType()->isSpecificBuiltinType(BuiltinType::Char_S) ||
23320 LowerBound->getType()->isSpecificBuiltinType(BuiltinType::Char_U))
23321 Diag(LowerBound->getExprLoc(), diag::warn_omp_section_is_char)
23322 << 0 << LowerBound->getSourceRange();
23326 PerformOpenMPImplicitIntegerConversion(Length->getExprLoc(), Length);
23328 return ExprError(Diag(Length->getExprLoc(),
23330 << 1 << Length->getSourceRange());
23333 if (Length->getType()->isSpecificBuiltinType(BuiltinType::Char_S) ||
23334 Length->getType()->isSpecificBuiltinType(BuiltinType::Char_U))
23335 Diag(Length->getExprLoc(), diag::warn_omp_section_is_char)
23336 << 1 << Length->getSourceRange();
23340 PerformOpenMPImplicitIntegerConversion(Stride->getExprLoc(), Stride);
23342 return ExprError(Diag(Stride->getExprLoc(),
23344 << 1 << Stride->getSourceRange());
23347 if (Stride->getType()->isSpecificBuiltinType(BuiltinType::Char_S) ||
23348 Stride->getType()->isSpecificBuiltinType(BuiltinType::Char_U))
23349 Diag(Stride->getExprLoc(), diag::warn_omp_section_is_char)
23350 << 1 << Stride->getSourceRange();
23354 // C++ [expr.sub]p1: The type "T" shall be a completely-defined object
23357 if (ResultTy->isFunctionType()) {
23358 Diag(Base->getExprLoc(), diag::err_omp_section_function_type)
23359 << ResultTy << Base->getSourceRange();
23363 if (SemaRef.RequireCompleteType(Base->getExprLoc(), ResultTy,
23367 if (LowerBound && !OriginalTy->isAnyPointerType()) {
23369 if (LowerBound->EvaluateAsInt(Result, Context)) {
23374 Diag(LowerBound->getExprLoc(),
23376 << LowerBound->getSourceRange();
23384 if (Length->EvaluateAsInt(Result, Context)) {
23386 // The length must evaluate to non-negative integers.
23389 Diag(Length->getExprLoc(), diag::err_omp_section_length_negative)
23391 << Length->getSourceRange();
23396 (OriginalTy.isNull() || (!OriginalTy->isConstantArrayType() &&
23397 !OriginalTy->isVariableArrayType()))) {
23402 << (!OriginalTy.isNull() && OriginalTy->isArrayType());
23408 if (Stride->EvaluateAsInt(Result, Context)) {
23413 Diag(Stride->getExprLoc(), diag::err_omp_section_stride_non_positive)
23415 << Stride->getSourceRange();
23421 if (!Base->hasPlaceholderType(BuiltinType::ArraySection)) {
23436 if (Base->hasPlaceholderType()) {
23445 QualType BaseTy = Base->getType();
23446 // Delay analysis of the types/expressions if instantiation/specialization is
23448 if (!BaseTy->isPointerType() && Base->isTypeDependent())
23451 if (!BaseTy->isPointerType() ||
23452 (!Base->isTypeDependent() &&
23453 BaseTy->getPointeeType()->isIncompleteType()))
23454 return ExprError(Diag(Base->getExprLoc(),
23456 << Base->getSourceRange());
23461 if (Dim->hasPlaceholderType()) {
23474 if (!Dim->isTypeDependent()) {
23476 PerformOpenMPImplicitIntegerConversion(Dim->getExprLoc(), Dim);
23479 Diag(Dim->getExprLoc(), diag::err_omp_typecheck_shaping_not_integer)
23480 << Dim->getSourceRange();
23485 if (!Dim->isValueDependent() && Dim->EvaluateAsInt(EvResult, Context)) {
23491 Diag(Dim->getExprLoc(), diag::err_omp_shaping_dimension_not_positive)
23493 << Dim->getSourceRange();
23521 // In an iterator-specifier, if the iterator-type is not specified then
23527 StartLoc = TInfo->getTypeLoc().getBeginLoc();
23530 bool IsDeclTyDependent = DeclTy->isDependentType() ||
23531 DeclTy->containsUnexpandedParameterPack() ||
23532 DeclTy->isInstantiationDependentType();
23534 if (!DeclTy->isIntegralType(Context) && !DeclTy->isAnyPointerType()) {
23536 // The iterator-type must be an integral or pointer type.
23544 // The iterator-type must not be const qualified.
23554 // Always try to create iterator declarator to avoid extra error messages
23559 VD->setImplicit();
23562 DeclarationNameInfo NameInfo(VD->getDeclName(), D.DeclIdentLoc);
23573 Diag(D.DeclIdentLoc, diag::err_redefinition) << VD->getDeclName();
23574 Diag(Old->getLocation(), diag::note_previous_definition);
23579 SemaRef.CurContext->addDecl(VD);
23586 if (!IsDeclTyDependent && Begin && !Begin->isTypeDependent()) {
23592 if (!IsDeclTyDependent && End && !End->isTypeDependent()) {
23598 if (!IsDeclTyDependent && Step && !Step->isTypeDependent()) {
23599 if (!Step->getType()->isIntegralType(Context)) {
23600 Diag(Step->getExprLoc(), diag::err_omp_iterator_step_not_integral)
23601 << Step << Step->getSourceRange();
23606 Step->getIntegerConstantExpr(Context);
23608 // If the step expression of a range-specification equals zero, the
23610 if (Result && Result->isZero()) {
23611 Diag(Step->getExprLoc(), diag::err_omp_iterator_step_constant_zero)
23612 << Step << Step->getSourceRange();
23634 ID->setInvalidDecl();
23639 if (!SemaRef.CurContext->isDependentContext()) {
23641 // Ni = ((Stepi > 0) ? ((Endi + Stepi -1 - Begini)/Stepi) :
23642 // ((Begini-Stepi-1-Endi) / -Stepi);
23644 // (Endi - Begini)
23654 // (Endi - Begini) + Stepi
23661 // (Endi - Begini) + Stepi - 1
23669 // ((Endi - Begini) + Stepi - 1) / Stepi
23678 // (Begini - Endi)
23685 // (Begini - Endi) - Stepi
23692 // (Begini - Endi) - Stepi - 1
23700 // ((Begini - Endi) - Stepi - 1) / (-Stepi)
23731 D.IteratorDecl->getBeginLoc(),
23732 D.IteratorDecl->getBeginLoc(), nullptr,
23733 Res.get()->getType(), nullptr, SC_None);
23734 CounterVD->setImplicit();
23736 SemaRef.BuildDeclRefExpr(CounterVD, CounterVD->getType(), VK_LValue,
23737 D.IteratorDecl->getBeginLoc());
23760 cast<VarDecl>(D.IteratorDecl)->getType(),
23761 VK_LValue, D.IteratorDecl->getBeginLoc());
23799 ID->setInvalidDecl();
23841 D->addAttr(::new (getASTContext()) OMPAssumeAttr(getASTContext(), AL, Str));