28class ErrnoTesterChecker :
public Checker<eval::Call> {
30 bool evalCall(
const CallEvent &
Call, CheckerContext &
C)
const;
35 static void evalSetErrno(CheckerContext &
C,
const CallEvent &
Call);
38 static void evalGetErrno(CheckerContext &
C,
const CallEvent &
Call);
44 static void evalSetErrnoIfError(CheckerContext &
C,
const CallEvent &
Call);
48 static void evalSetErrnoIfErrorRange(CheckerContext &
C,
49 const CallEvent &
Call);
69 static void evalSetErrnoCheckState(CheckerContext &
C,
const CallEvent &
Call);
71 using EvalFn =
std::function<void(CheckerContext &,
const CallEvent &)>;
72 const CallDescriptionMap<EvalFn> TestCalls{
73 {{CDM::SimpleFunc, {
"ErrnoTesterChecker_setErrno"}, 1},
74 &ErrnoTesterChecker::evalSetErrno},
75 {{CDM::SimpleFunc, {
"ErrnoTesterChecker_getErrno"}, 0},
76 &ErrnoTesterChecker::evalGetErrno},
77 {{CDM::SimpleFunc, {
"ErrnoTesterChecker_setErrnoIfError"}, 0},
78 &ErrnoTesterChecker::evalSetErrnoIfError},
79 {{CDM::SimpleFunc, {
"ErrnoTesterChecker_setErrnoIfErrorRange"}, 0},
80 &ErrnoTesterChecker::evalSetErrnoIfErrorRange},
81 {{CDM::SimpleFunc, {
"ErrnoTesterChecker_setErrnoCheckState"}, 0},
82 &ErrnoTesterChecker::evalSetErrnoCheckState}};
93void ErrnoTesterChecker::evalGetErrno(CheckerContext &
C,
94 const CallEvent &
Call) {
98 assert(ErrnoVal &&
"Errno value should be available.");
99 State = State->BindExpr(
Call.getOriginExpr(),
C.getStackFrame(), *ErrnoVal);
101 C.addTransition(State);
104void ErrnoTesterChecker::evalSetErrnoIfError(CheckerContext &
C,
105 const CallEvent &
Call) {
107 SValBuilder &SVB =
C.getSValBuilder();
117 C.addTransition(StateSuccess);
118 C.addTransition(StateFailure);
121void ErrnoTesterChecker::evalSetErrnoIfErrorRange(CheckerContext &
C,
122 const CallEvent &
Call) {
124 SValBuilder &SVB =
C.getSValBuilder();
133 StateFailure = StateFailure->assume(ErrnoVal,
true);
134 assert(StateFailure &&
"Failed to assume on an initial value.");
138 C.addTransition(StateSuccess);
139 C.addTransition(StateFailure);
142void ErrnoTesterChecker::evalSetErrnoCheckState(CheckerContext &
C,
143 const CallEvent &
Call) {
145 SValBuilder &SVB =
C.getSValBuilder();
159 C.addTransition(StateSuccess,
161 "sets 'errno' to an unspecified value."));
162 C.addTransition(StateFailure1);
166 "should be checked to test for failure."));
169bool ErrnoTesterChecker::evalCall(
const CallEvent &
Call,
170 CheckerContext &
C)
const {
171 const EvalFn *
Fn = TestCalls.lookup(
Call);
174 return C.isDifferent();
179void ento::registerErrnoTesterChecker(CheckerManager &Mgr) {
183bool ento::shouldRegisterErrnoTesterChecker(
const CheckerManager &Mgr) {
Represents an abstract call to a function or method along a particular path.
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
Simple checker classes that implement one frontend (i.e.
nonloc::ConcreteInt makeIntVal(const IntegerLiteral *integer)
DefinedOrUnknownSVal conjureSymbolVal(const void *symbolTag, ConstCFGElementRef elem, const StackFrame *SF, unsigned count)
Create a new symbol with a unique 'name'.
ProgramStateRef setErrnoState(ProgramStateRef State, ErrnoCheckState EState)
Set the errno check state, do not modify the errno value.
const NoteTag * getErrnoNoteTag(CheckerContext &C, const std::string &Message)
Create a NoteTag that displays the message if the 'errno' memory region is marked as interesting,...
std::optional< SVal > getErrnoValue(ProgramStateRef State)
Returns the value of 'errno', if 'errno' was found in the AST.
@ MustBeChecked
Value of 'errno' should be checked to find out if a previous function call has failed.
@ Irrelevant
We do not know anything about 'errno'.
@ MustNotBeChecked
Value of 'errno' is not allowed to be read, it can contain an unspecified value.
ProgramStateRef setErrnoValue(ProgramStateRef State, const StackFrame *SF, SVal Value, ErrnoCheckState EState)
Set value of 'errno' to any SVal, if possible.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
The JSON file list parser is used to communicate input to InstallAPI.
int const char * function