45class TrustNonnullChecker :
public Checker<check::PostCall,
46 check::PostObjCMessage,
50 static unsigned constexpr ComplexityThreshold = 10;
53 Selector SetObjectForKeyedSubscriptSel;
58 : ObjectForKeyedSubscriptSel(
61 SetObjectForKeyedSubscriptSel(
67 bool Assumption)
const {
73 State = addImplication(Antecedent, State,
true);
74 State = addImplication(Antecedent, State,
false);
82 if (!
Call.isInSystemHeader())
87 if (isNonNullPtr(
Call,
C))
88 if (
auto L =
Call.getReturnValue().getAs<
Loc>())
89 State = State->assume(*L,
true);
91 C.addTransition(State);
104 if (interfaceHasSuperclass(ID,
"NSMutableDictionary") &&
105 (Msg.
getSelector() == SetObjectForKeyedSubscriptSel ||
108 State = State->assume(*L,
true);
112 if (interfaceHasSuperclass(ID,
"NSDictionary") &&
113 (Msg.
getSelector() == ObjectForKeyedSubscriptSel ||
121 State = State->set<NonNullImplicationMap>(RetS, ArgS);
125 State = State->set<NullImplicationMap>(ArgS, RetS);
129 C.addTransition(State);
135 State = dropDeadFromGDM<NullImplicationMap>(SymReaper, State);
136 State = dropDeadFromGDM<NonNullImplicationMap>(SymReaper, State);
138 C.addTransition(State);
145 template <
typename MapName>
148 for (
const std::pair<SymbolRef, SymbolRef> &
P : State->get<MapName>())
150 State = State->remove<MapName>(
P.first);
166 if (!isa<ObjCMethodCall>(&
Call))
169 const auto *MCall = cast<ObjCMethodCall>(&
Call);
182 if (!MCall->isInstanceMessage())
186 SVal Receiver = MCall->getReceiverSVal();
196 StringRef ClassName)
const {
197 if (
ID->getIdentifier()->getName() == ClassName)
201 return interfaceHasSuperclass(Super, ClassName);
214 bool Negated)
const {
217 SValBuilder &SVB = InputState->getStateManager().getSValBuilder();
219 Negated ? InputState->get<NonNullImplicationMap>(Antecedent)
220 : InputState->get<NullImplicationMap>(Antecedent);
227 if ((Negated && InputState->isNonNull(AntecedentV).isConstrainedTrue())
228 || (!Negated && InputState->isNull(AntecedentV).isConstrainedTrue())) {
236 State = State->remove<NonNullImplicationMap>(Antecedent);
237 State = State->remove<NullImplicationMap>(*Consequent);
239 State = State->remove<NullImplicationMap>(Antecedent);
240 State = State->remove<NonNullImplicationMap>(*Consequent);
254bool ento::shouldRegisterTrustNonnullChecker(
const CheckerManager &mgr) {
#define REGISTER_MAP_WITH_PROGRAMSTATE(Name, Key, Value)
Declares an immutable map of type NameTy, suitable for placement into the ProgramState.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
DeclContext * getDeclContext()
Represents an ObjC class declaration.
ObjCMethodDecl - Represents an instance or class method declaration.
QualType getReturnType() const
A (possibly-)qualified type.
Smart pointer class that efficiently represents Objective-C method names.
bool isAnyPointerType() const
Represents an abstract call to a function or method along a particular path.
virtual SVal getArgSVal(unsigned Index) const
Returns the value of a given argument at the time of the call.
SVal getReturnValue() const
Returns the return value of the call.
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
ASTContext & getASTContext() const
bool isConstrainedTrue() const
Return true if the constraint is perfectly constrained to 'true'.
Represents any expression that calls an Objective-C method.
const ObjCInterfaceDecl * getReceiverInterface() const
Get the interface for the receiver.
Selector getSelector() const
DefinedSVal makeSymbolVal(SymbolRef Sym)
Make an SVal that represents the given symbol.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
SymbolRef getAsSymbol(bool IncludeBaseRegions=false) const
If this SVal wraps a symbol return that SymbolRef.
std::optional< T > getAs() const
Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
llvm::iterator_range< symbol_iterator > symbols() const
virtual unsigned computeComplexity() const =0
A class responsible for cleaning up unused symbols.
bool isLive(SymbolRef sym)
Nullability getNullabilityAnnotation(QualType Type)
Get nullability annotation for a given type.
The JSON file list parser is used to communicate input to InstallAPI.
static Selector getKeywordSelector(ASTContext &Ctx, const IdentifierInfos *...IIs)