1 //===-- NullabilityChecker.cpp - Nullability checker ----------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This checker tries to find nullability violations. There are several kinds of 10 // possible violations: 11 // * Null pointer is passed to a pointer which has a _Nonnull type. 12 // * Null pointer is returned from a function which has a _Nonnull return type. 13 // * Nullable pointer is passed to a pointer which has a _Nonnull type. 14 // * Nullable pointer is returned from a function which has a _Nonnull return 15 // type. 16 // * Nullable pointer is dereferenced. 17 // 18 // This checker propagates the nullability information of the pointers and looks 19 // for the patterns that are described above. Explicit casts are trusted and are 20 // considered a way to suppress false positives for this checker. The other way 21 // to suppress warnings would be to add asserts or guarding if statements to the 22 // code. In addition to the nullability propagation this checker also uses some 23 // heuristics to suppress potential false positives. 24 // 25 //===----------------------------------------------------------------------===// 26 27 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" 28 29 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" 30 #include "clang/StaticAnalyzer/Core/Checker.h" 31 #include "clang/StaticAnalyzer/Core/CheckerManager.h" 32 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h" 33 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" 34 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" 35 36 #include "llvm/ADT/StringExtras.h" 37 #include "llvm/Support/Path.h" 38 39 using namespace clang; 40 using namespace ento; 41 42 namespace { 43 44 /// Returns the most nullable nullability. This is used for message expressions 45 /// like [receiver method], where the nullability of this expression is either 46 /// the nullability of the receiver or the nullability of the return type of the 47 /// method, depending on which is more nullable. Contradicted is considered to 48 /// be the most nullable, to avoid false positive results. 49 Nullability getMostNullable(Nullability Lhs, Nullability Rhs) { 50 return static_cast<Nullability>( 51 std::min(static_cast<char>(Lhs), static_cast<char>(Rhs))); 52 } 53 54 const char *getNullabilityString(Nullability Nullab) { 55 switch (Nullab) { 56 case Nullability::Contradicted: 57 return "contradicted"; 58 case Nullability::Nullable: 59 return "nullable"; 60 case Nullability::Unspecified: 61 return "unspecified"; 62 case Nullability::Nonnull: 63 return "nonnull"; 64 } 65 llvm_unreachable("Unexpected enumeration."); 66 return ""; 67 } 68 69 // These enums are used as an index to ErrorMessages array. 70 enum class ErrorKind : int { 71 NilAssignedToNonnull, 72 NilPassedToNonnull, 73 NilReturnedToNonnull, 74 NullableAssignedToNonnull, 75 NullableReturnedToNonnull, 76 NullableDereferenced, 77 NullablePassedToNonnull 78 }; 79 80 class NullabilityChecker 81 : public Checker<check::Bind, check::PreCall, check::PreStmt<ReturnStmt>, 82 check::PostCall, check::PostStmt<ExplicitCastExpr>, 83 check::PostObjCMessage, check::DeadSymbols, 84 check::Event<ImplicitNullDerefEvent>> { 85 mutable std::unique_ptr<BugType> BT; 86 87 public: 88 // If true, the checker will not diagnose nullabilility issues for calls 89 // to system headers. This option is motivated by the observation that large 90 // projects may have many nullability warnings. These projects may 91 // find warnings about nullability annotations that they have explicitly 92 // added themselves higher priority to fix than warnings on calls to system 93 // libraries. 94 DefaultBool NoDiagnoseCallsToSystemHeaders; 95 96 void checkBind(SVal L, SVal V, const Stmt *S, CheckerContext &C) const; 97 void checkPostStmt(const ExplicitCastExpr *CE, CheckerContext &C) const; 98 void checkPreStmt(const ReturnStmt *S, CheckerContext &C) const; 99 void checkPostObjCMessage(const ObjCMethodCall &M, CheckerContext &C) const; 100 void checkPostCall(const CallEvent &Call, CheckerContext &C) const; 101 void checkPreCall(const CallEvent &Call, CheckerContext &C) const; 102 void checkDeadSymbols(SymbolReaper &SR, CheckerContext &C) const; 103 void checkEvent(ImplicitNullDerefEvent Event) const; 104 105 void printState(raw_ostream &Out, ProgramStateRef State, const char *NL, 106 const char *Sep) const override; 107 108 struct NullabilityChecksFilter { 109 DefaultBool CheckNullPassedToNonnull; 110 DefaultBool CheckNullReturnedFromNonnull; 111 DefaultBool CheckNullableDereferenced; 112 DefaultBool CheckNullablePassedToNonnull; 113 DefaultBool CheckNullableReturnedFromNonnull; 114 115 CheckerNameRef CheckNameNullPassedToNonnull; 116 CheckerNameRef CheckNameNullReturnedFromNonnull; 117 CheckerNameRef CheckNameNullableDereferenced; 118 CheckerNameRef CheckNameNullablePassedToNonnull; 119 CheckerNameRef CheckNameNullableReturnedFromNonnull; 120 }; 121 122 NullabilityChecksFilter Filter; 123 // When set to false no nullability information will be tracked in 124 // NullabilityMap. It is possible to catch errors like passing a null pointer 125 // to a callee that expects nonnull argument without the information that is 126 // stroed in the NullabilityMap. This is an optimization. 127 DefaultBool NeedTracking; 128 129 private: 130 class NullabilityBugVisitor : public BugReporterVisitor { 131 public: 132 NullabilityBugVisitor(const MemRegion *M) : Region(M) {} 133 134 void Profile(llvm::FoldingSetNodeID &ID) const override { 135 static int X = 0; 136 ID.AddPointer(&X); 137 ID.AddPointer(Region); 138 } 139 140 PathDiagnosticPieceRef VisitNode(const ExplodedNode *N, 141 BugReporterContext &BRC, 142 PathSensitiveBugReport &BR) override; 143 144 private: 145 // The tracked region. 146 const MemRegion *Region; 147 }; 148 149 /// When any of the nonnull arguments of the analyzed function is null, do not 150 /// report anything and turn off the check. 151 /// 152 /// When \p SuppressPath is set to true, no more bugs will be reported on this 153 /// path by this checker. 154 void reportBugIfInvariantHolds(StringRef Msg, ErrorKind Error, 155 ExplodedNode *N, const MemRegion *Region, 156 CheckerContext &C, 157 const Stmt *ValueExpr = nullptr, 158 bool SuppressPath = false) const; 159 160 void reportBug(StringRef Msg, ErrorKind Error, ExplodedNode *N, 161 const MemRegion *Region, BugReporter &BR, 162 const Stmt *ValueExpr = nullptr) const { 163 if (!BT) 164 BT.reset(new BugType(this, "Nullability", categories::MemoryError)); 165 166 auto R = std::make_unique<PathSensitiveBugReport>(*BT, Msg, N); 167 if (Region) { 168 R->markInteresting(Region); 169 R->addVisitor(std::make_unique<NullabilityBugVisitor>(Region)); 170 } 171 if (ValueExpr) { 172 R->addRange(ValueExpr->getSourceRange()); 173 if (Error == ErrorKind::NilAssignedToNonnull || 174 Error == ErrorKind::NilPassedToNonnull || 175 Error == ErrorKind::NilReturnedToNonnull) 176 if (const auto *Ex = dyn_cast<Expr>(ValueExpr)) 177 bugreporter::trackExpressionValue(N, Ex, *R); 178 } 179 BR.emitReport(std::move(R)); 180 } 181 182 /// If an SVal wraps a region that should be tracked, it will return a pointer 183 /// to the wrapped region. Otherwise it will return a nullptr. 184 const SymbolicRegion *getTrackRegion(SVal Val, 185 bool CheckSuperRegion = false) const; 186 187 /// Returns true if the call is diagnosable in the current analyzer 188 /// configuration. 189 bool isDiagnosableCall(const CallEvent &Call) const { 190 if (NoDiagnoseCallsToSystemHeaders && Call.isInSystemHeader()) 191 return false; 192 193 return true; 194 } 195 }; 196 197 class NullabilityState { 198 public: 199 NullabilityState(Nullability Nullab, const Stmt *Source = nullptr) 200 : Nullab(Nullab), Source(Source) {} 201 202 const Stmt *getNullabilitySource() const { return Source; } 203 204 Nullability getValue() const { return Nullab; } 205 206 void Profile(llvm::FoldingSetNodeID &ID) const { 207 ID.AddInteger(static_cast<char>(Nullab)); 208 ID.AddPointer(Source); 209 } 210 211 void print(raw_ostream &Out) const { 212 Out << getNullabilityString(Nullab) << "\n"; 213 } 214 215 private: 216 Nullability Nullab; 217 // Source is the expression which determined the nullability. For example in a 218 // message like [nullable nonnull_returning] has nullable nullability, because 219 // the receiver is nullable. Here the receiver will be the source of the 220 // nullability. This is useful information when the diagnostics are generated. 221 const Stmt *Source; 222 }; 223 224 bool operator==(NullabilityState Lhs, NullabilityState Rhs) { 225 return Lhs.getValue() == Rhs.getValue() && 226 Lhs.getNullabilitySource() == Rhs.getNullabilitySource(); 227 } 228 229 } // end anonymous namespace 230 231 REGISTER_MAP_WITH_PROGRAMSTATE(NullabilityMap, const MemRegion *, 232 NullabilityState) 233 234 // We say "the nullability type invariant is violated" when a location with a 235 // non-null type contains NULL or a function with a non-null return type returns 236 // NULL. Violations of the nullability type invariant can be detected either 237 // directly (for example, when NULL is passed as an argument to a nonnull 238 // parameter) or indirectly (for example, when, inside a function, the 239 // programmer defensively checks whether a nonnull parameter contains NULL and 240 // finds that it does). 241 // 242 // As a matter of policy, the nullability checker typically warns on direct 243 // violations of the nullability invariant (although it uses various 244 // heuristics to suppress warnings in some cases) but will not warn if the 245 // invariant has already been violated along the path (either directly or 246 // indirectly). As a practical matter, this prevents the analyzer from 247 // (1) warning on defensive code paths where a nullability precondition is 248 // determined to have been violated, (2) warning additional times after an 249 // initial direct violation has been discovered, and (3) warning after a direct 250 // violation that has been implicitly or explicitly suppressed (for 251 // example, with a cast of NULL to _Nonnull). In essence, once an invariant 252 // violation is detected on a path, this checker will be essentially turned off 253 // for the rest of the analysis 254 // 255 // The analyzer takes this approach (rather than generating a sink node) to 256 // ensure coverage of defensive paths, which may be important for backwards 257 // compatibility in codebases that were developed without nullability in mind. 258 REGISTER_TRAIT_WITH_PROGRAMSTATE(InvariantViolated, bool) 259 260 enum class NullConstraint { IsNull, IsNotNull, Unknown }; 261 262 static NullConstraint getNullConstraint(DefinedOrUnknownSVal Val, 263 ProgramStateRef State) { 264 ConditionTruthVal Nullness = State->isNull(Val); 265 if (Nullness.isConstrainedFalse()) 266 return NullConstraint::IsNotNull; 267 if (Nullness.isConstrainedTrue()) 268 return NullConstraint::IsNull; 269 return NullConstraint::Unknown; 270 } 271 272 const SymbolicRegion * 273 NullabilityChecker::getTrackRegion(SVal Val, bool CheckSuperRegion) const { 274 if (!NeedTracking) 275 return nullptr; 276 277 auto RegionSVal = Val.getAs<loc::MemRegionVal>(); 278 if (!RegionSVal) 279 return nullptr; 280 281 const MemRegion *Region = RegionSVal->getRegion(); 282 283 if (CheckSuperRegion) { 284 if (auto FieldReg = Region->getAs<FieldRegion>()) 285 return dyn_cast<SymbolicRegion>(FieldReg->getSuperRegion()); 286 if (auto ElementReg = Region->getAs<ElementRegion>()) 287 return dyn_cast<SymbolicRegion>(ElementReg->getSuperRegion()); 288 } 289 290 return dyn_cast<SymbolicRegion>(Region); 291 } 292 293 PathDiagnosticPieceRef NullabilityChecker::NullabilityBugVisitor::VisitNode( 294 const ExplodedNode *N, BugReporterContext &BRC, 295 PathSensitiveBugReport &BR) { 296 ProgramStateRef State = N->getState(); 297 ProgramStateRef StatePrev = N->getFirstPred()->getState(); 298 299 const NullabilityState *TrackedNullab = State->get<NullabilityMap>(Region); 300 const NullabilityState *TrackedNullabPrev = 301 StatePrev->get<NullabilityMap>(Region); 302 if (!TrackedNullab) 303 return nullptr; 304 305 if (TrackedNullabPrev && 306 TrackedNullabPrev->getValue() == TrackedNullab->getValue()) 307 return nullptr; 308 309 // Retrieve the associated statement. 310 const Stmt *S = TrackedNullab->getNullabilitySource(); 311 if (!S || S->getBeginLoc().isInvalid()) { 312 S = N->getStmtForDiagnostics(); 313 } 314 315 if (!S) 316 return nullptr; 317 318 std::string InfoText = 319 (llvm::Twine("Nullability '") + 320 getNullabilityString(TrackedNullab->getValue()) + "' is inferred") 321 .str(); 322 323 // Generate the extra diagnostic. 324 PathDiagnosticLocation Pos(S, BRC.getSourceManager(), 325 N->getLocationContext()); 326 return std::make_shared<PathDiagnosticEventPiece>(Pos, InfoText, true); 327 } 328 329 /// Returns true when the value stored at the given location has been 330 /// constrained to null after being passed through an object of nonnnull type. 331 static bool checkValueAtLValForInvariantViolation(ProgramStateRef State, 332 SVal LV, QualType T) { 333 if (getNullabilityAnnotation(T) != Nullability::Nonnull) 334 return false; 335 336 auto RegionVal = LV.getAs<loc::MemRegionVal>(); 337 if (!RegionVal) 338 return false; 339 340 // If the value was constrained to null *after* it was passed through that 341 // location, it could not have been a concrete pointer *when* it was passed. 342 // In that case we would have handled the situation when the value was 343 // bound to that location, by emitting (or not emitting) a report. 344 // Therefore we are only interested in symbolic regions that can be either 345 // null or non-null depending on the value of their respective symbol. 346 auto StoredVal = State->getSVal(*RegionVal).getAs<loc::MemRegionVal>(); 347 if (!StoredVal || !isa<SymbolicRegion>(StoredVal->getRegion())) 348 return false; 349 350 if (getNullConstraint(*StoredVal, State) == NullConstraint::IsNull) 351 return true; 352 353 return false; 354 } 355 356 static bool 357 checkParamsForPreconditionViolation(ArrayRef<ParmVarDecl *> Params, 358 ProgramStateRef State, 359 const LocationContext *LocCtxt) { 360 for (const auto *ParamDecl : Params) { 361 if (ParamDecl->isParameterPack()) 362 break; 363 364 SVal LV = State->getLValue(ParamDecl, LocCtxt); 365 if (checkValueAtLValForInvariantViolation(State, LV, 366 ParamDecl->getType())) { 367 return true; 368 } 369 } 370 return false; 371 } 372 373 static bool 374 checkSelfIvarsForInvariantViolation(ProgramStateRef State, 375 const LocationContext *LocCtxt) { 376 auto *MD = dyn_cast<ObjCMethodDecl>(LocCtxt->getDecl()); 377 if (!MD || !MD->isInstanceMethod()) 378 return false; 379 380 const ImplicitParamDecl *SelfDecl = LocCtxt->getSelfDecl(); 381 if (!SelfDecl) 382 return false; 383 384 SVal SelfVal = State->getSVal(State->getRegion(SelfDecl, LocCtxt)); 385 386 const ObjCObjectPointerType *SelfType = 387 dyn_cast<ObjCObjectPointerType>(SelfDecl->getType()); 388 if (!SelfType) 389 return false; 390 391 const ObjCInterfaceDecl *ID = SelfType->getInterfaceDecl(); 392 if (!ID) 393 return false; 394 395 for (const auto *IvarDecl : ID->ivars()) { 396 SVal LV = State->getLValue(IvarDecl, SelfVal); 397 if (checkValueAtLValForInvariantViolation(State, LV, IvarDecl->getType())) { 398 return true; 399 } 400 } 401 return false; 402 } 403 404 static bool checkInvariantViolation(ProgramStateRef State, ExplodedNode *N, 405 CheckerContext &C) { 406 if (State->get<InvariantViolated>()) 407 return true; 408 409 const LocationContext *LocCtxt = C.getLocationContext(); 410 const Decl *D = LocCtxt->getDecl(); 411 if (!D) 412 return false; 413 414 ArrayRef<ParmVarDecl*> Params; 415 if (const auto *BD = dyn_cast<BlockDecl>(D)) 416 Params = BD->parameters(); 417 else if (const auto *FD = dyn_cast<FunctionDecl>(D)) 418 Params = FD->parameters(); 419 else if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) 420 Params = MD->parameters(); 421 else 422 return false; 423 424 if (checkParamsForPreconditionViolation(Params, State, LocCtxt) || 425 checkSelfIvarsForInvariantViolation(State, LocCtxt)) { 426 if (!N->isSink()) 427 C.addTransition(State->set<InvariantViolated>(true), N); 428 return true; 429 } 430 return false; 431 } 432 433 void NullabilityChecker::reportBugIfInvariantHolds(StringRef Msg, 434 ErrorKind Error, ExplodedNode *N, const MemRegion *Region, 435 CheckerContext &C, const Stmt *ValueExpr, bool SuppressPath) const { 436 ProgramStateRef OriginalState = N->getState(); 437 438 if (checkInvariantViolation(OriginalState, N, C)) 439 return; 440 if (SuppressPath) { 441 OriginalState = OriginalState->set<InvariantViolated>(true); 442 N = C.addTransition(OriginalState, N); 443 } 444 445 reportBug(Msg, Error, N, Region, C.getBugReporter(), ValueExpr); 446 } 447 448 /// Cleaning up the program state. 449 void NullabilityChecker::checkDeadSymbols(SymbolReaper &SR, 450 CheckerContext &C) const { 451 ProgramStateRef State = C.getState(); 452 NullabilityMapTy Nullabilities = State->get<NullabilityMap>(); 453 for (NullabilityMapTy::iterator I = Nullabilities.begin(), 454 E = Nullabilities.end(); 455 I != E; ++I) { 456 const auto *Region = I->first->getAs<SymbolicRegion>(); 457 assert(Region && "Non-symbolic region is tracked."); 458 if (SR.isDead(Region->getSymbol())) { 459 State = State->remove<NullabilityMap>(I->first); 460 } 461 } 462 // When one of the nonnull arguments are constrained to be null, nullability 463 // preconditions are violated. It is not enough to check this only when we 464 // actually report an error, because at that time interesting symbols might be 465 // reaped. 466 if (checkInvariantViolation(State, C.getPredecessor(), C)) 467 return; 468 C.addTransition(State); 469 } 470 471 /// This callback triggers when a pointer is dereferenced and the analyzer does 472 /// not know anything about the value of that pointer. When that pointer is 473 /// nullable, this code emits a warning. 474 void NullabilityChecker::checkEvent(ImplicitNullDerefEvent Event) const { 475 if (Event.SinkNode->getState()->get<InvariantViolated>()) 476 return; 477 478 const MemRegion *Region = 479 getTrackRegion(Event.Location, /*CheckSuperRegion=*/true); 480 if (!Region) 481 return; 482 483 ProgramStateRef State = Event.SinkNode->getState(); 484 const NullabilityState *TrackedNullability = 485 State->get<NullabilityMap>(Region); 486 487 if (!TrackedNullability) 488 return; 489 490 if (Filter.CheckNullableDereferenced && 491 TrackedNullability->getValue() == Nullability::Nullable) { 492 BugReporter &BR = *Event.BR; 493 // Do not suppress errors on defensive code paths, because dereferencing 494 // a nullable pointer is always an error. 495 if (Event.IsDirectDereference) 496 reportBug("Nullable pointer is dereferenced", 497 ErrorKind::NullableDereferenced, Event.SinkNode, Region, BR); 498 else { 499 reportBug("Nullable pointer is passed to a callee that requires a " 500 "non-null", ErrorKind::NullablePassedToNonnull, 501 Event.SinkNode, Region, BR); 502 } 503 } 504 } 505 506 /// Find the outermost subexpression of E that is not an implicit cast. 507 /// This looks through the implicit casts to _Nonnull that ARC adds to 508 /// return expressions of ObjC types when the return type of the function or 509 /// method is non-null but the express is not. 510 static const Expr *lookThroughImplicitCasts(const Expr *E) { 511 return E->IgnoreImpCasts(); 512 } 513 514 /// This method check when nullable pointer or null value is returned from a 515 /// function that has nonnull return type. 516 void NullabilityChecker::checkPreStmt(const ReturnStmt *S, 517 CheckerContext &C) const { 518 auto RetExpr = S->getRetValue(); 519 if (!RetExpr) 520 return; 521 522 if (!RetExpr->getType()->isAnyPointerType()) 523 return; 524 525 ProgramStateRef State = C.getState(); 526 if (State->get<InvariantViolated>()) 527 return; 528 529 auto RetSVal = C.getSVal(S).getAs<DefinedOrUnknownSVal>(); 530 if (!RetSVal) 531 return; 532 533 bool InSuppressedMethodFamily = false; 534 535 QualType RequiredRetType; 536 AnalysisDeclContext *DeclCtxt = 537 C.getLocationContext()->getAnalysisDeclContext(); 538 const Decl *D = DeclCtxt->getDecl(); 539 if (auto *MD = dyn_cast<ObjCMethodDecl>(D)) { 540 // HACK: This is a big hammer to avoid warning when there are defensive 541 // nil checks in -init and -copy methods. We should add more sophisticated 542 // logic here to suppress on common defensive idioms but still 543 // warn when there is a likely problem. 544 ObjCMethodFamily Family = MD->getMethodFamily(); 545 if (OMF_init == Family || OMF_copy == Family || OMF_mutableCopy == Family) 546 InSuppressedMethodFamily = true; 547 548 RequiredRetType = MD->getReturnType(); 549 } else if (auto *FD = dyn_cast<FunctionDecl>(D)) { 550 RequiredRetType = FD->getReturnType(); 551 } else { 552 return; 553 } 554 555 NullConstraint Nullness = getNullConstraint(*RetSVal, State); 556 557 Nullability RequiredNullability = getNullabilityAnnotation(RequiredRetType); 558 559 // If the returned value is null but the type of the expression 560 // generating it is nonnull then we will suppress the diagnostic. 561 // This enables explicit suppression when returning a nil literal in a 562 // function with a _Nonnull return type: 563 // return (NSString * _Nonnull)0; 564 Nullability RetExprTypeLevelNullability = 565 getNullabilityAnnotation(lookThroughImplicitCasts(RetExpr)->getType()); 566 567 bool NullReturnedFromNonNull = (RequiredNullability == Nullability::Nonnull && 568 Nullness == NullConstraint::IsNull); 569 if (Filter.CheckNullReturnedFromNonnull && 570 NullReturnedFromNonNull && 571 RetExprTypeLevelNullability != Nullability::Nonnull && 572 !InSuppressedMethodFamily && 573 C.getLocationContext()->inTopFrame()) { 574 static CheckerProgramPointTag Tag(this, "NullReturnedFromNonnull"); 575 ExplodedNode *N = C.generateErrorNode(State, &Tag); 576 if (!N) 577 return; 578 579 SmallString<256> SBuf; 580 llvm::raw_svector_ostream OS(SBuf); 581 OS << (RetExpr->getType()->isObjCObjectPointerType() ? "nil" : "Null"); 582 OS << " returned from a " << C.getDeclDescription(D) << 583 " that is expected to return a non-null value"; 584 reportBugIfInvariantHolds(OS.str(), 585 ErrorKind::NilReturnedToNonnull, N, nullptr, C, 586 RetExpr); 587 return; 588 } 589 590 // If null was returned from a non-null function, mark the nullability 591 // invariant as violated even if the diagnostic was suppressed. 592 if (NullReturnedFromNonNull) { 593 State = State->set<InvariantViolated>(true); 594 C.addTransition(State); 595 return; 596 } 597 598 const MemRegion *Region = getTrackRegion(*RetSVal); 599 if (!Region) 600 return; 601 602 const NullabilityState *TrackedNullability = 603 State->get<NullabilityMap>(Region); 604 if (TrackedNullability) { 605 Nullability TrackedNullabValue = TrackedNullability->getValue(); 606 if (Filter.CheckNullableReturnedFromNonnull && 607 Nullness != NullConstraint::IsNotNull && 608 TrackedNullabValue == Nullability::Nullable && 609 RequiredNullability == Nullability::Nonnull) { 610 static CheckerProgramPointTag Tag(this, "NullableReturnedFromNonnull"); 611 ExplodedNode *N = C.addTransition(State, C.getPredecessor(), &Tag); 612 613 SmallString<256> SBuf; 614 llvm::raw_svector_ostream OS(SBuf); 615 OS << "Nullable pointer is returned from a " << C.getDeclDescription(D) << 616 " that is expected to return a non-null value"; 617 618 reportBugIfInvariantHolds(OS.str(), 619 ErrorKind::NullableReturnedToNonnull, N, 620 Region, C); 621 } 622 return; 623 } 624 if (RequiredNullability == Nullability::Nullable) { 625 State = State->set<NullabilityMap>(Region, 626 NullabilityState(RequiredNullability, 627 S)); 628 C.addTransition(State); 629 } 630 } 631 632 /// This callback warns when a nullable pointer or a null value is passed to a 633 /// function that expects its argument to be nonnull. 634 void NullabilityChecker::checkPreCall(const CallEvent &Call, 635 CheckerContext &C) const { 636 if (!Call.getDecl()) 637 return; 638 639 ProgramStateRef State = C.getState(); 640 if (State->get<InvariantViolated>()) 641 return; 642 643 ProgramStateRef OrigState = State; 644 645 unsigned Idx = 0; 646 for (const ParmVarDecl *Param : Call.parameters()) { 647 if (Param->isParameterPack()) 648 break; 649 650 if (Idx >= Call.getNumArgs()) 651 break; 652 653 const Expr *ArgExpr = Call.getArgExpr(Idx); 654 auto ArgSVal = Call.getArgSVal(Idx++).getAs<DefinedOrUnknownSVal>(); 655 if (!ArgSVal) 656 continue; 657 658 if (!Param->getType()->isAnyPointerType() && 659 !Param->getType()->isReferenceType()) 660 continue; 661 662 NullConstraint Nullness = getNullConstraint(*ArgSVal, State); 663 664 Nullability RequiredNullability = 665 getNullabilityAnnotation(Param->getType()); 666 Nullability ArgExprTypeLevelNullability = 667 getNullabilityAnnotation(ArgExpr->getType()); 668 669 unsigned ParamIdx = Param->getFunctionScopeIndex() + 1; 670 671 if (Filter.CheckNullPassedToNonnull && Nullness == NullConstraint::IsNull && 672 ArgExprTypeLevelNullability != Nullability::Nonnull && 673 RequiredNullability == Nullability::Nonnull && 674 isDiagnosableCall(Call)) { 675 ExplodedNode *N = C.generateErrorNode(State); 676 if (!N) 677 return; 678 679 SmallString<256> SBuf; 680 llvm::raw_svector_ostream OS(SBuf); 681 OS << (Param->getType()->isObjCObjectPointerType() ? "nil" : "Null"); 682 OS << " passed to a callee that requires a non-null " << ParamIdx 683 << llvm::getOrdinalSuffix(ParamIdx) << " parameter"; 684 reportBugIfInvariantHolds(OS.str(), ErrorKind::NilPassedToNonnull, N, 685 nullptr, C, 686 ArgExpr, /*SuppressPath=*/false); 687 return; 688 } 689 690 const MemRegion *Region = getTrackRegion(*ArgSVal); 691 if (!Region) 692 continue; 693 694 const NullabilityState *TrackedNullability = 695 State->get<NullabilityMap>(Region); 696 697 if (TrackedNullability) { 698 if (Nullness == NullConstraint::IsNotNull || 699 TrackedNullability->getValue() != Nullability::Nullable) 700 continue; 701 702 if (Filter.CheckNullablePassedToNonnull && 703 RequiredNullability == Nullability::Nonnull && 704 isDiagnosableCall(Call)) { 705 ExplodedNode *N = C.addTransition(State); 706 SmallString<256> SBuf; 707 llvm::raw_svector_ostream OS(SBuf); 708 OS << "Nullable pointer is passed to a callee that requires a non-null " 709 << ParamIdx << llvm::getOrdinalSuffix(ParamIdx) << " parameter"; 710 reportBugIfInvariantHolds(OS.str(), 711 ErrorKind::NullablePassedToNonnull, N, 712 Region, C, ArgExpr, /*SuppressPath=*/true); 713 return; 714 } 715 if (Filter.CheckNullableDereferenced && 716 Param->getType()->isReferenceType()) { 717 ExplodedNode *N = C.addTransition(State); 718 reportBugIfInvariantHolds("Nullable pointer is dereferenced", 719 ErrorKind::NullableDereferenced, N, Region, 720 C, ArgExpr, /*SuppressPath=*/true); 721 return; 722 } 723 continue; 724 } 725 } 726 if (State != OrigState) 727 C.addTransition(State); 728 } 729 730 /// Suppress the nullability warnings for some functions. 731 void NullabilityChecker::checkPostCall(const CallEvent &Call, 732 CheckerContext &C) const { 733 auto Decl = Call.getDecl(); 734 if (!Decl) 735 return; 736 // ObjC Messages handles in a different callback. 737 if (Call.getKind() == CE_ObjCMessage) 738 return; 739 const FunctionType *FuncType = Decl->getFunctionType(); 740 if (!FuncType) 741 return; 742 QualType ReturnType = FuncType->getReturnType(); 743 if (!ReturnType->isAnyPointerType()) 744 return; 745 ProgramStateRef State = C.getState(); 746 if (State->get<InvariantViolated>()) 747 return; 748 749 const MemRegion *Region = getTrackRegion(Call.getReturnValue()); 750 if (!Region) 751 return; 752 753 // CG headers are misannotated. Do not warn for symbols that are the results 754 // of CG calls. 755 const SourceManager &SM = C.getSourceManager(); 756 StringRef FilePath = SM.getFilename(SM.getSpellingLoc(Decl->getBeginLoc())); 757 if (llvm::sys::path::filename(FilePath).startswith("CG")) { 758 State = State->set<NullabilityMap>(Region, Nullability::Contradicted); 759 C.addTransition(State); 760 return; 761 } 762 763 const NullabilityState *TrackedNullability = 764 State->get<NullabilityMap>(Region); 765 766 if (!TrackedNullability && 767 getNullabilityAnnotation(ReturnType) == Nullability::Nullable) { 768 State = State->set<NullabilityMap>(Region, Nullability::Nullable); 769 C.addTransition(State); 770 } 771 } 772 773 static Nullability getReceiverNullability(const ObjCMethodCall &M, 774 ProgramStateRef State) { 775 if (M.isReceiverSelfOrSuper()) { 776 // For super and super class receivers we assume that the receiver is 777 // nonnull. 778 return Nullability::Nonnull; 779 } 780 // Otherwise look up nullability in the state. 781 SVal Receiver = M.getReceiverSVal(); 782 if (auto DefOrUnknown = Receiver.getAs<DefinedOrUnknownSVal>()) { 783 // If the receiver is constrained to be nonnull, assume that it is nonnull 784 // regardless of its type. 785 NullConstraint Nullness = getNullConstraint(*DefOrUnknown, State); 786 if (Nullness == NullConstraint::IsNotNull) 787 return Nullability::Nonnull; 788 } 789 auto ValueRegionSVal = Receiver.getAs<loc::MemRegionVal>(); 790 if (ValueRegionSVal) { 791 const MemRegion *SelfRegion = ValueRegionSVal->getRegion(); 792 assert(SelfRegion); 793 794 const NullabilityState *TrackedSelfNullability = 795 State->get<NullabilityMap>(SelfRegion); 796 if (TrackedSelfNullability) 797 return TrackedSelfNullability->getValue(); 798 } 799 return Nullability::Unspecified; 800 } 801 802 /// Calculate the nullability of the result of a message expr based on the 803 /// nullability of the receiver, the nullability of the return value, and the 804 /// constraints. 805 void NullabilityChecker::checkPostObjCMessage(const ObjCMethodCall &M, 806 CheckerContext &C) const { 807 auto Decl = M.getDecl(); 808 if (!Decl) 809 return; 810 QualType RetType = Decl->getReturnType(); 811 if (!RetType->isAnyPointerType()) 812 return; 813 814 ProgramStateRef State = C.getState(); 815 if (State->get<InvariantViolated>()) 816 return; 817 818 const MemRegion *ReturnRegion = getTrackRegion(M.getReturnValue()); 819 if (!ReturnRegion) 820 return; 821 822 auto Interface = Decl->getClassInterface(); 823 auto Name = Interface ? Interface->getName() : ""; 824 // In order to reduce the noise in the diagnostics generated by this checker, 825 // some framework and programming style based heuristics are used. These 826 // heuristics are for Cocoa APIs which have NS prefix. 827 if (Name.startswith("NS")) { 828 // Developers rely on dynamic invariants such as an item should be available 829 // in a collection, or a collection is not empty often. Those invariants can 830 // not be inferred by any static analysis tool. To not to bother the users 831 // with too many false positives, every item retrieval function should be 832 // ignored for collections. The instance methods of dictionaries in Cocoa 833 // are either item retrieval related or not interesting nullability wise. 834 // Using this fact, to keep the code easier to read just ignore the return 835 // value of every instance method of dictionaries. 836 if (M.isInstanceMessage() && Name.contains("Dictionary")) { 837 State = 838 State->set<NullabilityMap>(ReturnRegion, Nullability::Contradicted); 839 C.addTransition(State); 840 return; 841 } 842 // For similar reasons ignore some methods of Cocoa arrays. 843 StringRef FirstSelectorSlot = M.getSelector().getNameForSlot(0); 844 if (Name.contains("Array") && 845 (FirstSelectorSlot == "firstObject" || 846 FirstSelectorSlot == "lastObject")) { 847 State = 848 State->set<NullabilityMap>(ReturnRegion, Nullability::Contradicted); 849 C.addTransition(State); 850 return; 851 } 852 853 // Encoding related methods of string should not fail when lossless 854 // encodings are used. Using lossless encodings is so frequent that ignoring 855 // this class of methods reduced the emitted diagnostics by about 30% on 856 // some projects (and all of that was false positives). 857 if (Name.contains("String")) { 858 for (auto Param : M.parameters()) { 859 if (Param->getName() == "encoding") { 860 State = State->set<NullabilityMap>(ReturnRegion, 861 Nullability::Contradicted); 862 C.addTransition(State); 863 return; 864 } 865 } 866 } 867 } 868 869 const ObjCMessageExpr *Message = M.getOriginExpr(); 870 Nullability SelfNullability = getReceiverNullability(M, State); 871 872 const NullabilityState *NullabilityOfReturn = 873 State->get<NullabilityMap>(ReturnRegion); 874 875 if (NullabilityOfReturn) { 876 // When we have a nullability tracked for the return value, the nullability 877 // of the expression will be the most nullable of the receiver and the 878 // return value. 879 Nullability RetValTracked = NullabilityOfReturn->getValue(); 880 Nullability ComputedNullab = 881 getMostNullable(RetValTracked, SelfNullability); 882 if (ComputedNullab != RetValTracked && 883 ComputedNullab != Nullability::Unspecified) { 884 const Stmt *NullabilitySource = 885 ComputedNullab == RetValTracked 886 ? NullabilityOfReturn->getNullabilitySource() 887 : Message->getInstanceReceiver(); 888 State = State->set<NullabilityMap>( 889 ReturnRegion, NullabilityState(ComputedNullab, NullabilitySource)); 890 C.addTransition(State); 891 } 892 return; 893 } 894 895 // No tracked information. Use static type information for return value. 896 Nullability RetNullability = getNullabilityAnnotation(RetType); 897 898 // Properties might be computed. For this reason the static analyzer creates a 899 // new symbol each time an unknown property is read. To avoid false pozitives 900 // do not treat unknown properties as nullable, even when they explicitly 901 // marked nullable. 902 if (M.getMessageKind() == OCM_PropertyAccess && !C.wasInlined) 903 RetNullability = Nullability::Nonnull; 904 905 Nullability ComputedNullab = getMostNullable(RetNullability, SelfNullability); 906 if (ComputedNullab == Nullability::Nullable) { 907 const Stmt *NullabilitySource = ComputedNullab == RetNullability 908 ? Message 909 : Message->getInstanceReceiver(); 910 State = State->set<NullabilityMap>( 911 ReturnRegion, NullabilityState(ComputedNullab, NullabilitySource)); 912 C.addTransition(State); 913 } 914 } 915 916 /// Explicit casts are trusted. If there is a disagreement in the nullability 917 /// annotations in the destination and the source or '0' is casted to nonnull 918 /// track the value as having contraditory nullability. This will allow users to 919 /// suppress warnings. 920 void NullabilityChecker::checkPostStmt(const ExplicitCastExpr *CE, 921 CheckerContext &C) const { 922 QualType OriginType = CE->getSubExpr()->getType(); 923 QualType DestType = CE->getType(); 924 if (!OriginType->isAnyPointerType()) 925 return; 926 if (!DestType->isAnyPointerType()) 927 return; 928 929 ProgramStateRef State = C.getState(); 930 if (State->get<InvariantViolated>()) 931 return; 932 933 Nullability DestNullability = getNullabilityAnnotation(DestType); 934 935 // No explicit nullability in the destination type, so this cast does not 936 // change the nullability. 937 if (DestNullability == Nullability::Unspecified) 938 return; 939 940 auto RegionSVal = C.getSVal(CE).getAs<DefinedOrUnknownSVal>(); 941 const MemRegion *Region = getTrackRegion(*RegionSVal); 942 if (!Region) 943 return; 944 945 // When 0 is converted to nonnull mark it as contradicted. 946 if (DestNullability == Nullability::Nonnull) { 947 NullConstraint Nullness = getNullConstraint(*RegionSVal, State); 948 if (Nullness == NullConstraint::IsNull) { 949 State = State->set<NullabilityMap>(Region, Nullability::Contradicted); 950 C.addTransition(State); 951 return; 952 } 953 } 954 955 const NullabilityState *TrackedNullability = 956 State->get<NullabilityMap>(Region); 957 958 if (!TrackedNullability) { 959 if (DestNullability != Nullability::Nullable) 960 return; 961 State = State->set<NullabilityMap>(Region, 962 NullabilityState(DestNullability, CE)); 963 C.addTransition(State); 964 return; 965 } 966 967 if (TrackedNullability->getValue() != DestNullability && 968 TrackedNullability->getValue() != Nullability::Contradicted) { 969 State = State->set<NullabilityMap>(Region, Nullability::Contradicted); 970 C.addTransition(State); 971 } 972 } 973 974 /// For a given statement performing a bind, attempt to syntactically 975 /// match the expression resulting in the bound value. 976 static const Expr * matchValueExprForBind(const Stmt *S) { 977 // For `x = e` the value expression is the right-hand side. 978 if (auto *BinOp = dyn_cast<BinaryOperator>(S)) { 979 if (BinOp->getOpcode() == BO_Assign) 980 return BinOp->getRHS(); 981 } 982 983 // For `int x = e` the value expression is the initializer. 984 if (auto *DS = dyn_cast<DeclStmt>(S)) { 985 if (DS->isSingleDecl()) { 986 auto *VD = dyn_cast<VarDecl>(DS->getSingleDecl()); 987 if (!VD) 988 return nullptr; 989 990 if (const Expr *Init = VD->getInit()) 991 return Init; 992 } 993 } 994 995 return nullptr; 996 } 997 998 /// Returns true if \param S is a DeclStmt for a local variable that 999 /// ObjC automated reference counting initialized with zero. 1000 static bool isARCNilInitializedLocal(CheckerContext &C, const Stmt *S) { 1001 // We suppress diagnostics for ARC zero-initialized _Nonnull locals. This 1002 // prevents false positives when a _Nonnull local variable cannot be 1003 // initialized with an initialization expression: 1004 // NSString * _Nonnull s; // no-warning 1005 // @autoreleasepool { 1006 // s = ... 1007 // } 1008 // 1009 // FIXME: We should treat implicitly zero-initialized _Nonnull locals as 1010 // uninitialized in Sema's UninitializedValues analysis to warn when a use of 1011 // the zero-initialized definition will unexpectedly yield nil. 1012 1013 // Locals are only zero-initialized when automated reference counting 1014 // is turned on. 1015 if (!C.getASTContext().getLangOpts().ObjCAutoRefCount) 1016 return false; 1017 1018 auto *DS = dyn_cast<DeclStmt>(S); 1019 if (!DS || !DS->isSingleDecl()) 1020 return false; 1021 1022 auto *VD = dyn_cast<VarDecl>(DS->getSingleDecl()); 1023 if (!VD) 1024 return false; 1025 1026 // Sema only zero-initializes locals with ObjCLifetimes. 1027 if(!VD->getType().getQualifiers().hasObjCLifetime()) 1028 return false; 1029 1030 const Expr *Init = VD->getInit(); 1031 assert(Init && "ObjC local under ARC without initializer"); 1032 1033 // Return false if the local is explicitly initialized (e.g., with '= nil'). 1034 if (!isa<ImplicitValueInitExpr>(Init)) 1035 return false; 1036 1037 return true; 1038 } 1039 1040 /// Propagate the nullability information through binds and warn when nullable 1041 /// pointer or null symbol is assigned to a pointer with a nonnull type. 1042 void NullabilityChecker::checkBind(SVal L, SVal V, const Stmt *S, 1043 CheckerContext &C) const { 1044 const TypedValueRegion *TVR = 1045 dyn_cast_or_null<TypedValueRegion>(L.getAsRegion()); 1046 if (!TVR) 1047 return; 1048 1049 QualType LocType = TVR->getValueType(); 1050 if (!LocType->isAnyPointerType()) 1051 return; 1052 1053 ProgramStateRef State = C.getState(); 1054 if (State->get<InvariantViolated>()) 1055 return; 1056 1057 auto ValDefOrUnknown = V.getAs<DefinedOrUnknownSVal>(); 1058 if (!ValDefOrUnknown) 1059 return; 1060 1061 NullConstraint RhsNullness = getNullConstraint(*ValDefOrUnknown, State); 1062 1063 Nullability ValNullability = Nullability::Unspecified; 1064 if (SymbolRef Sym = ValDefOrUnknown->getAsSymbol()) 1065 ValNullability = getNullabilityAnnotation(Sym->getType()); 1066 1067 Nullability LocNullability = getNullabilityAnnotation(LocType); 1068 1069 // If the type of the RHS expression is nonnull, don't warn. This 1070 // enables explicit suppression with a cast to nonnull. 1071 Nullability ValueExprTypeLevelNullability = Nullability::Unspecified; 1072 const Expr *ValueExpr = matchValueExprForBind(S); 1073 if (ValueExpr) { 1074 ValueExprTypeLevelNullability = 1075 getNullabilityAnnotation(lookThroughImplicitCasts(ValueExpr)->getType()); 1076 } 1077 1078 bool NullAssignedToNonNull = (LocNullability == Nullability::Nonnull && 1079 RhsNullness == NullConstraint::IsNull); 1080 if (Filter.CheckNullPassedToNonnull && 1081 NullAssignedToNonNull && 1082 ValNullability != Nullability::Nonnull && 1083 ValueExprTypeLevelNullability != Nullability::Nonnull && 1084 !isARCNilInitializedLocal(C, S)) { 1085 static CheckerProgramPointTag Tag(this, "NullPassedToNonnull"); 1086 ExplodedNode *N = C.generateErrorNode(State, &Tag); 1087 if (!N) 1088 return; 1089 1090 1091 const Stmt *ValueStmt = S; 1092 if (ValueExpr) 1093 ValueStmt = ValueExpr; 1094 1095 SmallString<256> SBuf; 1096 llvm::raw_svector_ostream OS(SBuf); 1097 OS << (LocType->isObjCObjectPointerType() ? "nil" : "Null"); 1098 OS << " assigned to a pointer which is expected to have non-null value"; 1099 reportBugIfInvariantHolds(OS.str(), 1100 ErrorKind::NilAssignedToNonnull, N, nullptr, C, 1101 ValueStmt); 1102 return; 1103 } 1104 1105 // If null was returned from a non-null function, mark the nullability 1106 // invariant as violated even if the diagnostic was suppressed. 1107 if (NullAssignedToNonNull) { 1108 State = State->set<InvariantViolated>(true); 1109 C.addTransition(State); 1110 return; 1111 } 1112 1113 // Intentionally missing case: '0' is bound to a reference. It is handled by 1114 // the DereferenceChecker. 1115 1116 const MemRegion *ValueRegion = getTrackRegion(*ValDefOrUnknown); 1117 if (!ValueRegion) 1118 return; 1119 1120 const NullabilityState *TrackedNullability = 1121 State->get<NullabilityMap>(ValueRegion); 1122 1123 if (TrackedNullability) { 1124 if (RhsNullness == NullConstraint::IsNotNull || 1125 TrackedNullability->getValue() != Nullability::Nullable) 1126 return; 1127 if (Filter.CheckNullablePassedToNonnull && 1128 LocNullability == Nullability::Nonnull) { 1129 static CheckerProgramPointTag Tag(this, "NullablePassedToNonnull"); 1130 ExplodedNode *N = C.addTransition(State, C.getPredecessor(), &Tag); 1131 reportBugIfInvariantHolds("Nullable pointer is assigned to a pointer " 1132 "which is expected to have non-null value", 1133 ErrorKind::NullableAssignedToNonnull, N, 1134 ValueRegion, C); 1135 } 1136 return; 1137 } 1138 1139 const auto *BinOp = dyn_cast<BinaryOperator>(S); 1140 1141 if (ValNullability == Nullability::Nullable) { 1142 // Trust the static information of the value more than the static 1143 // information on the location. 1144 const Stmt *NullabilitySource = BinOp ? BinOp->getRHS() : S; 1145 State = State->set<NullabilityMap>( 1146 ValueRegion, NullabilityState(ValNullability, NullabilitySource)); 1147 C.addTransition(State); 1148 return; 1149 } 1150 1151 if (LocNullability == Nullability::Nullable) { 1152 const Stmt *NullabilitySource = BinOp ? BinOp->getLHS() : S; 1153 State = State->set<NullabilityMap>( 1154 ValueRegion, NullabilityState(LocNullability, NullabilitySource)); 1155 C.addTransition(State); 1156 } 1157 } 1158 1159 void NullabilityChecker::printState(raw_ostream &Out, ProgramStateRef State, 1160 const char *NL, const char *Sep) const { 1161 1162 NullabilityMapTy B = State->get<NullabilityMap>(); 1163 1164 if (State->get<InvariantViolated>()) 1165 Out << Sep << NL 1166 << "Nullability invariant was violated, warnings suppressed." << NL; 1167 1168 if (B.isEmpty()) 1169 return; 1170 1171 if (!State->get<InvariantViolated>()) 1172 Out << Sep << NL; 1173 1174 for (NullabilityMapTy::iterator I = B.begin(), E = B.end(); I != E; ++I) { 1175 Out << I->first << " : "; 1176 I->second.print(Out); 1177 Out << NL; 1178 } 1179 } 1180 1181 void ento::registerNullabilityBase(CheckerManager &mgr) { 1182 mgr.registerChecker<NullabilityChecker>(); 1183 } 1184 1185 bool ento::shouldRegisterNullabilityBase(const CheckerManager &mgr) { 1186 return true; 1187 } 1188 1189 #define REGISTER_CHECKER(name, trackingRequired) \ 1190 void ento::register##name##Checker(CheckerManager &mgr) { \ 1191 NullabilityChecker *checker = mgr.getChecker<NullabilityChecker>(); \ 1192 checker->Filter.Check##name = true; \ 1193 checker->Filter.CheckName##name = mgr.getCurrentCheckerName(); \ 1194 checker->NeedTracking = checker->NeedTracking || trackingRequired; \ 1195 checker->NoDiagnoseCallsToSystemHeaders = \ 1196 checker->NoDiagnoseCallsToSystemHeaders || \ 1197 mgr.getAnalyzerOptions().getCheckerBooleanOption( \ 1198 checker, "NoDiagnoseCallsToSystemHeaders", true); \ 1199 } \ 1200 \ 1201 bool ento::shouldRegister##name##Checker(const CheckerManager &mgr) { \ 1202 return true; \ 1203 } 1204 1205 // The checks are likely to be turned on by default and it is possible to do 1206 // them without tracking any nullability related information. As an optimization 1207 // no nullability information will be tracked when only these two checks are 1208 // enables. 1209 REGISTER_CHECKER(NullPassedToNonnull, false) 1210 REGISTER_CHECKER(NullReturnedFromNonnull, false) 1211 1212 REGISTER_CHECKER(NullableDereferenced, true) 1213 REGISTER_CHECKER(NullablePassedToNonnull, true) 1214 REGISTER_CHECKER(NullableReturnedFromNonnull, true) 1215