//== TrustNonnullChecker.cpp --------- API nullability modeling -*- C++ -*--==// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This checker adds nullability-related assumptions: // // 1. Methods annotated with _Nonnull // which come from system headers actually return a non-null pointer. // // 2. NSDictionary key is non-null after the keyword subscript operation // on read if and only if the resulting expression is non-null. // // 3. NSMutableDictionary index is non-null after a write operation. // //===----------------------------------------------------------------------===// #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" #include "clang/Analysis/SelectorExtras.h" #include "clang/StaticAnalyzer/Core/Checker.h" #include "clang/StaticAnalyzer/Core/CheckerManager.h" #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h" #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" usingnamespaceclang; usingnamespaceento; /// Records implications between symbols. /// The semantics is: /// (antecedent != 0) => (consequent != 0) /// These implications are then read during the evaluation of the assumption, /// and the appropriate antecedents are applied. REGISTER_MAP_WITH_PROGRAMSTATE(…) /// The semantics is: /// (antecedent == 0) => (consequent == 0) REGISTER_MAP_WITH_PROGRAMSTATE(…) namespace { class TrustNonnullChecker : public Checker<check::PostCall, check::PostObjCMessage, check::DeadSymbols, eval::Assume> { … }; } // end empty namespace void ento::registerTrustNonnullChecker(CheckerManager &Mgr) { … } bool ento::shouldRegisterTrustNonnullChecker(const CheckerManager &mgr) { … }