Lines Matching +full:sys +full:- +full:mgr
1 //===-- NullabilityChecker.cpp - Nullability checker ----------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
25 //===----------------------------------------------------------------------===//
178 R->markInteresting(Region); in reportBug()
179 R->addVisitor<NullabilityBugVisitor>(Region); in reportBug()
182 R->addRange(ValueExpr->getSourceRange()); in reportBug()
276 // non-null type contains NULL or a function with a non-null return type returns
305 ConditionTruthVal Nullness = State->isNull(Val); in getNullConstraint()
314 return T->isAnyPointerType() || T->isBlockPointerType(); in isValidPointerType()
326 const MemRegion *Region = RegionSVal->getRegion(); in getTrackRegion()
329 if (const SubRegion *FieldReg = Region->getAs<FieldRegion>()) { in getTrackRegion()
330 if (const auto *ER = dyn_cast<ElementRegion>(FieldReg->getSuperRegion())) in getTrackRegion()
332 return dyn_cast<SymbolicRegion>(FieldReg->getSuperRegion()); in getTrackRegion()
334 if (auto ElementReg = Region->getAs<ElementRegion>()) in getTrackRegion()
335 return dyn_cast<SymbolicRegion>(ElementReg->getSuperRegion()); in getTrackRegion()
344 ProgramStateRef State = N->getState(); in VisitNode()
345 ProgramStateRef StatePrev = N->getFirstPred()->getState(); in VisitNode()
347 const NullabilityState *TrackedNullab = State->get<NullabilityMap>(Region); in VisitNode()
349 StatePrev->get<NullabilityMap>(Region); in VisitNode()
354 TrackedNullabPrev->getValue() == TrackedNullab->getValue()) in VisitNode()
358 const Stmt *S = TrackedNullab->getNullabilitySource(); in VisitNode()
359 if (!S || S->getBeginLoc().isInvalid()) { in VisitNode()
360 S = N->getStmtForDiagnostics(); in VisitNode()
368 getNullabilityString(TrackedNullab->getValue()) + "' is inferred") in VisitNode()
373 N->getLocationContext()); in VisitNode()
393 // null or non-null depending on the value of their respective symbol. in checkValueAtLValForInvariantViolation()
394 auto StoredVal = State->getSVal(*RegionVal).getAs<loc::MemRegionVal>(); in checkValueAtLValForInvariantViolation()
395 if (!StoredVal || !isa<SymbolicRegion>(StoredVal->getRegion())) in checkValueAtLValForInvariantViolation()
409 if (ParamDecl->isParameterPack()) in checkParamsForPreconditionViolation()
412 SVal LV = State->getLValue(ParamDecl, LocCtxt); in checkParamsForPreconditionViolation()
414 ParamDecl->getType())) { in checkParamsForPreconditionViolation()
424 auto *MD = dyn_cast<ObjCMethodDecl>(LocCtxt->getDecl()); in checkSelfIvarsForInvariantViolation()
425 if (!MD || !MD->isInstanceMethod()) in checkSelfIvarsForInvariantViolation()
428 const ImplicitParamDecl *SelfDecl = LocCtxt->getSelfDecl(); in checkSelfIvarsForInvariantViolation()
432 SVal SelfVal = State->getSVal(State->getRegion(SelfDecl, LocCtxt)); in checkSelfIvarsForInvariantViolation()
435 dyn_cast<ObjCObjectPointerType>(SelfDecl->getType()); in checkSelfIvarsForInvariantViolation()
439 const ObjCInterfaceDecl *ID = SelfType->getInterfaceDecl(); in checkSelfIvarsForInvariantViolation()
443 for (const auto *IvarDecl : ID->ivars()) { in checkSelfIvarsForInvariantViolation()
444 SVal LV = State->getLValue(IvarDecl, SelfVal); in checkSelfIvarsForInvariantViolation()
445 if (checkValueAtLValForInvariantViolation(State, LV, IvarDecl->getType())) { in checkSelfIvarsForInvariantViolation()
454 if (State->get<InvariantViolated>()) in checkInvariantViolation()
458 const Decl *D = LocCtxt->getDecl(); in checkInvariantViolation()
464 Params = BD->parameters(); in checkInvariantViolation()
466 Params = FD->parameters(); in checkInvariantViolation()
468 Params = MD->parameters(); in checkInvariantViolation()
474 if (!N->isSink()) in checkInvariantViolation()
475 C.addTransition(State->set<InvariantViolated>(true), N); in checkInvariantViolation()
485 ProgramStateRef OriginalState = N->getState(); in reportBugIfInvariantHolds()
490 OriginalState = OriginalState->set<InvariantViolated>(true); in reportBugIfInvariantHolds()
501 NullabilityMapTy Nullabilities = State->get<NullabilityMap>(); in checkDeadSymbols()
503 const auto *Region = Reg->getAs<SymbolicRegion>(); in checkDeadSymbols()
504 assert(Region && "Non-symbolic region is tracked."); in checkDeadSymbols()
505 if (SR.isDead(Region->getSymbol())) { in checkDeadSymbols()
506 State = State->remove<NullabilityMap>(Reg); in checkDeadSymbols()
512 PropertyAccessesMapTy PropertyAccesses = State->get<PropertyAccessesMap>(); in checkDeadSymbols()
516 State = State->remove<PropertyAccessesMap>(PropKey); in checkDeadSymbols()
533 if (Event.SinkNode->getState()->get<InvariantViolated>()) in checkEvent()
541 ProgramStateRef State = Event.SinkNode->getState(); in checkEvent()
543 State->get<NullabilityMap>(Region); in checkEvent()
549 TrackedNullability->getValue() == Nullability::Nullable) { in checkEvent()
559 "non-null", in checkEvent()
571 auto AbstractCall = AnyCall::forDecl(LCtx->getDecl()); in checkBeginFunction()
572 if (!AbstractCall || AbstractCall->parameters().empty()) in checkBeginFunction()
576 for (const ParmVarDecl *Param : AbstractCall->parameters()) { in checkBeginFunction()
577 if (!isValidPointerType(Param->getType())) in checkBeginFunction()
581 getNullabilityAnnotation(Param->getType()); in checkBeginFunction()
585 const VarRegion *ParamRegion = State->getRegion(Param, LCtx); in checkBeginFunction()
587 State->getSVal(ParamRegion).getAsRegion(); in checkBeginFunction()
591 State = State->set<NullabilityMap>(ParamPointeeRegion, in checkBeginFunction()
599 // non-null.
602 // The user should be warned on assigning the null value to a non-null pointer
627 auto StoredVal = State->getSVal(Region).getAs<loc::MemRegionVal>(); in checkLocation()
632 getNullabilityAnnotation(Region->getValueType()); in checkLocation()
636 // be considered non-null as annotated by the developer. in checkLocation()
637 if (ProgramStateRef NewState = State->assume(*StoredVal, true)) { in checkLocation()
646 /// method is non-null but the express is not.
648 return E->IgnoreImpCasts(); in lookThroughImplicitCasts()
655 auto RetExpr = S->getRetValue(); in checkPreStmt()
659 if (!isValidPointerType(RetExpr->getType())) in checkPreStmt()
663 if (State->get<InvariantViolated>()) in checkPreStmt()
674 C.getLocationContext()->getAnalysisDeclContext(); in checkPreStmt()
675 const Decl *D = DeclCtxt->getDecl(); in checkPreStmt()
678 // nil checks in -init and -copy methods. We should add more sophisticated in checkPreStmt()
681 ObjCMethodFamily Family = MD->getMethodFamily(); in checkPreStmt()
685 RequiredRetType = MD->getReturnType(); in checkPreStmt()
687 RequiredRetType = FD->getReturnType(); in checkPreStmt()
702 getNullabilityAnnotation(lookThroughImplicitCasts(RetExpr)->getType()); in checkPreStmt()
708 !InSuppressedMethodFamily && C.getLocationContext()->inTopFrame()) { in checkPreStmt()
716 OS << (RetExpr->getType()->isObjCObjectPointerType() ? "nil" : "Null"); in checkPreStmt()
718 " that is expected to return a non-null value"; in checkPreStmt()
725 // If null was returned from a non-null function, mark the nullability in checkPreStmt()
728 State = State->set<InvariantViolated>(true); in checkPreStmt()
738 State->get<NullabilityMap>(Region); in checkPreStmt()
740 Nullability TrackedNullabValue = TrackedNullability->getValue(); in checkPreStmt()
751 " that is expected to return a non-null value"; in checkPreStmt()
759 State = State->set<NullabilityMap>(Region, in checkPreStmt()
774 if (State->get<InvariantViolated>()) in checkPreCall()
781 if (Param->isParameterPack()) in checkPreCall()
792 if (!isValidPointerType(Param->getType()) && in checkPreCall()
793 !Param->getType()->isReferenceType()) in checkPreCall()
799 getNullabilityAnnotation(Param->getType()); in checkPreCall()
801 getNullabilityAnnotation(lookThroughImplicitCasts(ArgExpr)->getType()); in checkPreCall()
803 unsigned ParamIdx = Param->getFunctionScopeIndex() + 1; in checkPreCall()
816 OS << (Param->getType()->isObjCObjectPointerType() ? "nil" : "Null"); in checkPreCall()
817 OS << " passed to a callee that requires a non-null " << ParamIdx in checkPreCall()
830 State->get<NullabilityMap>(Region); in checkPreCall()
834 TrackedNullability->getValue() != Nullability::Nullable) in checkPreCall()
843 OS << "Nullable pointer is passed to a callee that requires a non-null " in checkPreCall()
851 Param->getType()->isReferenceType()) { in checkPreCall()
875 const FunctionType *FuncType = Decl->getFunctionType(); in checkPostCall()
878 QualType ReturnType = FuncType->getReturnType(); in checkPostCall()
882 if (State->get<InvariantViolated>()) in checkPostCall()
892 StringRef FilePath = SM.getFilename(SM.getSpellingLoc(Decl->getBeginLoc())); in checkPostCall()
893 if (llvm::sys::path::filename(FilePath).starts_with("CG")) { in checkPostCall()
894 State = State->set<NullabilityMap>(Region, Nullability::Contradicted); in checkPostCall()
900 State->get<NullabilityMap>(Region); in checkPostCall()
908 ReturnType = E->getType(); in checkPostCall()
912 State = State->set<NullabilityMap>(Region, Nullability::Nullable); in checkPostCall()
935 const MemRegion *SelfRegion = ValueRegionSVal->getRegion(); in getReceiverNullability()
939 State->get<NullabilityMap>(SelfRegion); in getReceiverNullability()
941 return TrackedSelfNullability->getValue(); in getReceiverNullability()
949 // at the time they are imposed (e.g. by a nil-check conditional).
952 PropertyAccessesMapTy PropertyAccesses = State->get<PropertyAccessesMap>(); in evalAssume()
955 ConditionTruthVal IsNonNull = State->isNonNull(PropVal.Value); in evalAssume()
959 State = State->set<PropertyAccessesMap>(PropKey, Replacement); in evalAssume()
961 // Space optimization: no point in tracking constrained-null cases in evalAssume()
962 State = State->remove<PropertyAccessesMap>(PropKey); in evalAssume()
978 QualType RetType = Decl->getReturnType(); in checkPostObjCMessage()
983 if (State->get<InvariantViolated>()) in checkPostObjCMessage()
990 auto Interface = Decl->getClassInterface(); in checkPostObjCMessage()
991 auto Name = Interface ? Interface->getName() : ""; in checkPostObjCMessage()
1006 State->set<NullabilityMap>(ReturnRegion, Nullability::Contradicted); in checkPostObjCMessage()
1016 State->set<NullabilityMap>(ReturnRegion, Nullability::Contradicted); in checkPostObjCMessage()
1027 if (Param->getName() == "encoding") { in checkPostObjCMessage()
1028 State = State->set<NullabilityMap>(ReturnRegion, in checkPostObjCMessage()
1041 State->get<NullabilityMap>(ReturnRegion); in checkPostObjCMessage()
1047 Nullability RetValTracked = NullabilityOfReturn->getValue(); in checkPostObjCMessage()
1054 ? NullabilityOfReturn->getNullabilitySource() in checkPostObjCMessage()
1055 : Message->getInstanceReceiver(); in checkPostObjCMessage()
1056 State = State->set<NullabilityMap>( in checkPostObjCMessage()
1064 Nullability RetNullability = getNullabilityAnnotation(Message->getType()); in checkPostObjCMessage()
1067 // theoretically change between calls even in commonly-observed cases like in checkPostObjCMessage()
1075 // If the property is nullable-annotated, a naive analysis would lead to many in checkPostObjCMessage()
1076 // false positives despite the presence of probably-correct nil-checks. To in checkPostObjCMessage()
1090 State->get<PropertyAccessesMap>(Key); in checkPostObjCMessage()
1091 if (PrevPropVal && PrevPropVal->isConstrainedNonnull) { in checkPostObjCMessage()
1102 State = State->set<PropertyAccessesMap>( in checkPostObjCMessage()
1119 : Message->getInstanceReceiver(); in checkPostObjCMessage()
1120 State = State->set<NullabilityMap>( in checkPostObjCMessage()
1132 QualType OriginType = CE->getSubExpr()->getType(); in checkPostStmt()
1133 QualType DestType = CE->getType(); in checkPostStmt()
1140 if (State->get<InvariantViolated>()) in checkPostStmt()
1159 State = State->set<NullabilityMap>(Region, Nullability::Contradicted); in checkPostStmt()
1166 State->get<NullabilityMap>(Region); in checkPostStmt()
1171 State = State->set<NullabilityMap>(Region, in checkPostStmt()
1177 if (TrackedNullability->getValue() != DestNullability && in checkPostStmt()
1178 TrackedNullability->getValue() != Nullability::Contradicted) { in checkPostStmt()
1179 State = State->set<NullabilityMap>(Region, Nullability::Contradicted); in checkPostStmt()
1187 // For `x = e` the value expression is the right-hand side. in matchValueExprForBind()
1189 if (BinOp->getOpcode() == BO_Assign) in matchValueExprForBind()
1190 return BinOp->getRHS(); in matchValueExprForBind()
1195 if (DS->isSingleDecl()) { in matchValueExprForBind()
1196 auto *VD = dyn_cast<VarDecl>(DS->getSingleDecl()); in matchValueExprForBind()
1200 if (const Expr *Init = VD->getInit()) in matchValueExprForBind()
1211 // We suppress diagnostics for ARC zero-initialized _Nonnull locals. This in isARCNilInitializedLocal()
1214 // NSString * _Nonnull s; // no-warning in isARCNilInitializedLocal()
1219 // FIXME: We should treat implicitly zero-initialized _Nonnull locals as in isARCNilInitializedLocal()
1221 // the zero-initialized definition will unexpectedly yield nil. in isARCNilInitializedLocal()
1223 // Locals are only zero-initialized when automated reference counting in isARCNilInitializedLocal()
1229 if (!DS || !DS->isSingleDecl()) in isARCNilInitializedLocal()
1232 auto *VD = dyn_cast<VarDecl>(DS->getSingleDecl()); in isARCNilInitializedLocal()
1236 // Sema only zero-initializes locals with ObjCLifetimes. in isARCNilInitializedLocal()
1237 if(!VD->getType().getQualifiers().hasObjCLifetime()) in isARCNilInitializedLocal()
1240 const Expr *Init = VD->getInit(); in isARCNilInitializedLocal()
1259 QualType LocType = TVR->getValueType(); in checkBind()
1264 if (State->get<InvariantViolated>()) in checkBind()
1274 if (SymbolRef Sym = ValDefOrUnknown->getAsSymbol()) in checkBind()
1275 ValNullability = getNullabilityAnnotation(Sym->getType()); in checkBind()
1285 getNullabilityAnnotation(lookThroughImplicitCasts(ValueExpr)->getType()); in checkBind()
1306 OS << (LocType->isObjCObjectPointerType() ? "nil" : "Null"); in checkBind()
1307 OS << " assigned to a pointer which is expected to have non-null value"; in checkBind()
1313 // If null was returned from a non-null function, mark the nullability in checkBind()
1316 State = State->set<InvariantViolated>(true); in checkBind()
1329 State->get<NullabilityMap>(ValueRegion); in checkBind()
1333 TrackedNullability->getValue() != Nullability::Nullable) in checkBind()
1340 "which is expected to have non-null value", in checkBind()
1352 const Stmt *NullabilitySource = BinOp ? BinOp->getRHS() : S; in checkBind()
1353 State = State->set<NullabilityMap>( in checkBind()
1360 const Stmt *NullabilitySource = BinOp ? BinOp->getLHS() : S; in checkBind()
1361 State = State->set<NullabilityMap>( in checkBind()
1370 NullabilityMapTy B = State->get<NullabilityMap>(); in printState()
1372 if (State->get<InvariantViolated>()) in printState()
1379 if (!State->get<InvariantViolated>()) in printState()
1389 void ento::registerNullabilityBase(CheckerManager &mgr) { in registerNullabilityBase() argument
1390 mgr.registerChecker<NullabilityChecker>(); in registerNullabilityBase()
1393 bool ento::shouldRegisterNullabilityBase(const CheckerManager &mgr) { in shouldRegisterNullabilityBase() argument
1398 void ento::register##name##Checker(CheckerManager &mgr) { \
1399 NullabilityChecker *checker = mgr.getChecker<NullabilityChecker>(); \
1400 checker->ChecksEnabled[NullabilityChecker::CK_##name] = true; \
1401 checker->CheckNames[NullabilityChecker::CK_##name] = \
1402 mgr.getCurrentCheckerName(); \
1403 checker->NeedTracking = checker->NeedTracking || trackingRequired; \
1404 checker->NoDiagnoseCallsToSystemHeaders = \
1405 checker->NoDiagnoseCallsToSystemHeaders || \
1406 mgr.getAnalyzerOptions().getCheckerBooleanOption( \
1410 bool ento::shouldRegister##name##Checker(const CheckerManager &mgr) { \