Lines Matching +full:inter +full:- +full:ic

1 // SmartPtrModeling.cpp - Model behavior of C++ smart pointers - C++ ------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
105 if (!RD || !RD->getDeclContext()->isStdNamespace()) in REGISTER_MAP_WITH_PROGRAMSTATE()
107 if (RD->getDeclName().isIdentifier()) in REGISTER_MAP_WITH_PROGRAMSTATE()
108 return llvm::is_contained(Names, RD->getName()); in REGISTER_MAP_WITH_PROGRAMSTATE()
120 return isStdSmartPtr(E->getType()->getAsCXXRecordDecl()); in isStdSmartPtr()
123 // Define the inter-checker API.
129 if (!MethodDecl || !MethodDecl->getParent()) in isStdSmartPtrCall()
131 return isStdSmartPtr(MethodDecl->getParent()); in isStdSmartPtrCall()
135 if (!RD || !RD->getDeclContext()->isStdNamespace()) in isStdSmartPtr()
138 if (RD->getDeclName().isIdentifier()) { in isStdSmartPtr()
139 StringRef Name = RD->getName(); in isStdSmartPtr()
146 return isStdSmartPtr(E->getType()->getAsCXXRecordDecl()); in isStdSmartPtr()
150 const auto *InnerPointVal = State->get<TrackedRegionMap>(ThisRegion); in isNullSmartPtr()
152 !State->assume(InnerPointVal->castAs<DefinedOrUnknownSVal>(), true); in isNullSmartPtr()
166 if (E.first->isSubRegionOf(Region)) in removeTrackedSubregions()
176 State = State->set<TrackedRegionMap>(Region, *RegionInnerPointerVal); in updateSwappedRegion()
178 State = State->remove<TrackedRegionMap>(Region); in updateSwappedRegion()
184 if (!RD || !RD->isInStdNamespace()) in getInnerPointerType()
191 auto TemplateArgs = TSD->getTemplateArgs().asArray(); in getInnerPointerType()
198 // This is for use with standalone-functions like std::make_unique,
204 if (!FD || !FD->getPrimaryTemplate()) in getPointerTypeFromTemplateArg()
206 const auto &TemplateArgs = FD->getTemplateSpecializationArgs()->asArray(); in getPointerTypeFromTemplateArg()
217 if (!MethodDecl || !MethodDecl->getParent()) in getInnerPointerType()
220 const auto *RecordDecl = MethodDecl->getParent(); in getInnerPointerType()
227 if (Region->canPrintPretty()) { in checkAndPrettyPrintRegion()
229 Region->printPretty(OS); in checkAndPrettyPrintRegion()
239 return CD && CD->getConversionType()->isBooleanType(); in isBoolConversionMethod()
245 const auto *RD = E->getType()->getAsCXXRecordDecl(); in isStdBasicOstream()
250 return Call.getDecl() && Call.getDecl()->getDeclContext()->isStdNamespace(); in isStdFunctionCall()
259 const FunctionDecl *FD = FC->getDecl(); in isStdOstreamOperatorCall()
260 if (!FD->isOverloadedOperator()) in isStdOstreamOperatorCall()
262 const OverloadedOperatorKind OOK = FD->getOverloadedOperator(); in isStdOstreamOperatorCall()
294 if (!smartptr::isStdSmartPtr(FirstArg->getType()->getAsCXXRecordDecl())) in evalCall()
312 const MemRegion *ThisRegion = ThisRegionOpt->getAsRegion(); in evalCall()
313 State = State->set<TrackedRegionMap>(ThisRegion, PtrVal); in evalCall()
314 State = State->assume(PtrVal, true); in evalCall()
327 // pretend we don't need to know about this - ie, completely automatic work. in evalCall()
332 auto &Engine = State->getStateManager().getOwningEngine(); in evalCall()
338 // unique_ptr from this call is non-null (hence is safe to de-reference). in evalCall()
348 cast<CXXInstanceCall>(&Call)->getCXXThisVal().getAsRegion(); in evalCall()
365 C.addTransition(State->BindExpr( in evalCall()
377 if (CC->getDecl()->isCopyConstructor()) in evalCall()
380 const MemRegion *ThisRegion = CC->getCXXThisVal().getAsRegion(); in evalCall()
384 QualType ThisType = cast<CXXMethodDecl>(Call.getDecl())->getThisType(); in evalCall()
386 if (CC->getDecl()->isMoveConstructor()) in evalCall()
391 State = State->set<TrackedRegionMap>(ThisRegion, NullVal); in evalCall()
405 assert(TrackingExpr->getType()->isPointerType() && in evalCall()
408 State = State->set<TrackedRegionMap>(ThisRegion, ArgVal); in evalCall()
434 (this->**Handler)(Call, C); in evalCall()
442 const auto *Ptr = State->get<TrackedRegionMap>(ThisRegion); in retrieveOrConjureInnerPtrVal()
447 State = State->set<TrackedRegionMap>(ThisRegion, Val); in retrieveOrConjureInnerPtrVal()
456 const FunctionDecl *FD = FC->getDecl(); in handleComparisionOp()
457 if (!FD->isOverloadedOperator()) in handleComparisionOp()
459 const OverloadedOperatorKind OOK = FD->getOverloadedOperator(); in handleComparisionOp()
472 SVal S) -> std::pair<SVal, ProgramStateRef> { in handleComparisionOp()
479 QualType Type = getInnerPointerType(C, E->getType()->getAsCXXRecordDecl()); in handleComparisionOp()
504 State->assume(*RetVal.getAs<DefinedOrUnknownSVal>()); in handleComparisionOp()
507 TrueState->BindExpr(ResultExpr, LCtx, Bldr.makeTruthVal(true))); in handleComparisionOp()
510 FalseState->BindExpr(ResultExpr, LCtx, Bldr.makeTruthVal(false))); in handleComparisionOp()
512 C.addTransition(State->BindExpr(ResultExpr, LCtx, RetVal)); in handleComparisionOp()
522 // 1) Invalidating the mem-region of the ostream object at hand. in handleOstreamOperator()
533 State->invalidateRegions({StreamThisRegion}, Call.getOriginExpr(), in handleOstreamOperator()
536 State->BindExpr(Call.getOriginExpr(), C.getLocationContext(), StreamVal); in handleOstreamOperator()
545 TrackedRegionMapTy TrackedRegions = State->get<TrackedRegionMap>(); in checkDeadSymbols()
551 State = State->remove<TrackedRegionMap>(Region); in checkDeadSymbols()
558 TrackedRegionMapTy RS = State->get<TrackedRegionMap>(); in printState()
563 I.first->dumpToStream(Out); in printState()
578 TrackedRegionMapTy RegionMap = State->get<TrackedRegionMap>(); in checkRegionChanges()
580 State->get_context<TrackedRegionMap>(); in checkRegionChanges()
583 Region->getBaseRegion()); in checkRegionChanges()
584 return State->set<TrackedRegionMap>(RegionMap); in checkRegionChanges()
590 TrackedRegionMapTy TrackedRegions = State->get<TrackedRegionMap>(); in checkLiveSymbols()
601 const auto *IC = dyn_cast<CXXInstanceCall>(&Call); in handleReset() local
602 if (!IC) in handleReset()
605 const MemRegion *ThisRegion = IC->getCXXThisVal().getAsRegion(); in handleReset()
609 assert(Call.getArgExpr(0)->getType()->isPointerType() && in handleReset()
611 State = State->set<TrackedRegionMap>(ThisRegion, Call.getArgSVal(0)); in handleReset()
631 const auto *IC = dyn_cast<CXXInstanceCall>(&Call); in handleRelease() local
632 if (!IC) in handleRelease()
635 const MemRegion *ThisRegion = IC->getCXXThisVal().getAsRegion(); in handleRelease()
639 const auto *InnerPointVal = State->get<TrackedRegionMap>(ThisRegion); in handleRelease()
642 State = State->BindExpr(Call.getOriginExpr(), C.getLocationContext(), in handleRelease()
646 QualType ThisType = cast<CXXMethodDecl>(Call.getDecl())->getThisType(); in handleRelease()
648 State = State->set<TrackedRegionMap>(ThisRegion, ValueToUpdate); in handleRelease()
667 const auto *IC = dyn_cast<CXXInstanceCall>(&Call); in handleSwapMethod() local
668 if (!IC) in handleSwapMethod()
672 handleSwap(State, IC->getCXXThisVal(), Call.getArgSVal(0), C); in handleSwapMethod()
684 const auto *FirstInnerPtrVal = State->get<TrackedRegionMap>(FirstThisRegion); in handleSwap()
686 State->get<TrackedRegionMap>(SecondThisRegion); in handleSwap()
715 const auto *IC = dyn_cast<CXXInstanceCall>(&Call); in handleGet() local
716 if (!IC) in handleGet()
719 const MemRegion *ThisRegion = IC->getCXXThisVal().getAsRegion(); in handleGet()
726 State = State->BindExpr(Call.getOriginExpr(), C.getLocationContext(), in handleGet()
738 OverloadedOperatorKind OOK = OC->getOverloadedOperator(); in handleAssignOp()
741 const MemRegion *ThisRegion = OC->getCXXThisVal().getAsRegion(); in handleAssignOp()
745 QualType ThisType = cast<CXXMethodDecl>(Call.getDecl())->getThisType(); in handleAssignOp()
747 const MemRegion *OtherSmartPtrRegion = OC->getArgSVal(0).getAsRegion(); in handleAssignOp()
754 State = State->set<TrackedRegionMap>(ThisRegion, NullVal); in handleAssignOp()
783 QualType ThisType = cast<CXXMethodDecl>(Call.getDecl())->getThisType(); in updateMovedSmartPointers()
784 const auto *OtherInnerPtr = State->get<TrackedRegionMap>(OtherSmartPtrRegion); in updateMovedSmartPointers()
786 State = State->set<TrackedRegionMap>(ThisRegion, *OtherInnerPtr); in updateMovedSmartPointers()
789 State = State->set<TrackedRegionMap>(OtherSmartPtrRegion, NullVal); in updateMovedSmartPointers()
790 bool IsArgValNull = OtherInnerPtr->isZeroConstant(); in updateMovedSmartPointers()
816 State = State->remove<TrackedRegionMap>(ThisRegion); in updateMovedSmartPointers()
817 State = State->set<TrackedRegionMap>(OtherSmartPtrRegion, NullVal); in updateMovedSmartPointers()
840 cast<CXXInstanceCall>(&Call)->getCXXThisVal().getAsRegion(); in handleBoolConversion()
842 QualType ThisType = cast<CXXMethodDecl>(Call.getDecl())->getThisType(); in handleBoolConversion()
845 if (const auto *InnerValPtr = State->get<TrackedRegionMap>(ThisRegion)) { in handleBoolConversion()
857 State = State->set<TrackedRegionMap>(ThisRegion, InnerPointerVal); in handleBoolConversion()
860 if (State->isNull(InnerPointerVal).isConstrainedTrue()) { in handleBoolConversion()
861 State = State->BindExpr(CallExpr, C.getLocationContext(), in handleBoolConversion()
866 } else if (State->isNonNull(InnerPointerVal).isConstrainedTrue()) { in handleBoolConversion()
867 State = State->BindExpr(CallExpr, C.getLocationContext(), in handleBoolConversion()
874 State->BindExpr(CallExpr, C.getLocationContext(), in handleBoolConversion()
880 State->assume(InnerPointerVal.castAs<DefinedOrUnknownSVal>()); in handleBoolConversion()
884 NullState = NullState->set<TrackedRegionMap>(ThisRegion, NullVal); in handleBoolConversion()
886 NullState = NullState->BindExpr(CallExpr, C.getLocationContext(), in handleBoolConversion()
897 NotNullState->BindExpr(CallExpr, C.getLocationContext(), in handleBoolConversion()
905 OS << " is non-null"; in handleBoolConversion()
914 Checker->ModelSmartPtrDereference = in registerSmartPtrModeling()