clang 17.0.0git
Enumerations | Functions
clang::ento::errno_modeling Namespace Reference

Enumerations

enum  ErrnoCheckState : unsigned { Irrelevant = 0 , MustBeChecked = 1 , MustNotBeChecked = 2 }
 Describe how reads and writes of errno are handled by the checker. More...
 

Functions

std::optional< SValgetErrnoValue (ProgramStateRef State)
 Returns the value of 'errno', if 'errno' was found in the AST.
 
ProgramStateRef setErrnoValue (ProgramStateRef State, const LocationContext *LCtx, SVal Value, ErrnoCheckState EState)
 Set value of 'errno' to any SVal, if possible.
 
ProgramStateRef setErrnoValue (ProgramStateRef State, CheckerContext &C, uint64_t Value, ErrnoCheckState EState)
 Set value of 'errno' to a concrete (signed) integer, if possible.
 
std::optional< LocgetErrnoLoc (ProgramStateRef State)
 Returns the location that points to the MemoryRegion where the 'errno' value is stored.
 
ErrnoCheckState getErrnoState (ProgramStateRef State)
 Returns the errno check state, Errno_Irrelevant if 'errno' was not found (this is not the only case for that value).
 
ProgramStateRef setErrnoState (ProgramStateRef State, ErrnoCheckState EState)
 Set the errno check state, do not modify the errno value.
 
ProgramStateRef clearErrnoState (ProgramStateRef State)
 Clear state of errno (make it irrelevant).
 
bool isErrno (const Decl *D)
 Determine if a Decl node related to 'errno'.
 
const char * describeErrnoCheckState (ErrnoCheckState CS)
 Produce a textual description about how errno is allowed to be used (in a ErrnoCheckState).
 
const NoteTaggetErrnoNoteTag (CheckerContext &C, const std::string &Message)
 Create a NoteTag that displays the message if the 'errno' memory region is marked as interesting, and resets the interestingness.
 
ProgramStateRef setErrnoForStdSuccess (ProgramStateRef State, CheckerContext &C)
 Set errno state for the common case when a standard function is successful.
 
ProgramStateRef setErrnoForStdFailure (ProgramStateRef State, CheckerContext &C, NonLoc ErrnoSym)
 Set errno state for the common case when a standard function fails.
 
ProgramStateRef setErrnoStdMustBeChecked (ProgramStateRef State, CheckerContext &C, const Expr *InvalE)
 Set errno state for the common case when a standard function indicates failure only by errno.
 
const NoteTaggetNoteTagForStdSuccess (CheckerContext &C, llvm::StringRef Fn)
 Generate the note tag that can be applied at the state generated by setErrnoForStdSuccess .
 
const NoteTaggetNoteTagForStdMustBeChecked (CheckerContext &C, llvm::StringRef Fn)
 Generate the note tag that can be applied at the state generated by setErrnoStdMustBeChecked .
 

Enumeration Type Documentation

◆ ErrnoCheckState

Describe how reads and writes of errno are handled by the checker.

Enumerator
Irrelevant 

We do not know anything about 'errno'.

Read and write is always allowed.

MustBeChecked 

Value of 'errno' should be checked to find out if a previous function call has failed.

When this state is set errno must be read by the program before a next standard function call or other overwrite of errno follows, otherwise a bug report is emitted.

MustNotBeChecked 

Value of 'errno' is not allowed to be read, it can contain an unspecified value.

When this state is set errno is not allowed to be read by the program until it is overwritten or invalidated.

Definition at line 26 of file ErrnoModeling.h.

Function Documentation

◆ clearErrnoState()

ProgramStateRef clang::ento::errno_modeling::clearErrnoState ( ProgramStateRef  State)

Clear state of errno (make it irrelevant).

Definition at line 258 of file ErrnoModeling.cpp.

References Irrelevant, and setErrnoState().

◆ describeErrnoCheckState()

const char * clang::ento::errno_modeling::describeErrnoCheckState ( ErrnoCheckState  CS)

Produce a textual description about how errno is allowed to be used (in a ErrnoCheckState).

The returned string is insertable into a longer warning message in the form "the value 'errno' <...>". Currently only the errno_modeling::MustNotBeChecked state is supported, others are not used by the clients.

Definition at line 272 of file ErrnoModeling.cpp.

References MustNotBeChecked.

Referenced by getNoteTagForStdSuccess().

◆ getErrnoLoc()

std::optional< Loc > clang::ento::errno_modeling::getErrnoLoc ( ProgramStateRef  State)

Returns the location that points to the MemoryRegion where the 'errno' value is stored.

Returns std::nullopt if 'errno' was not found. Otherwise it always returns a valid memory region in the system global memory space.

Definition at line 243 of file ErrnoModeling.cpp.

◆ getErrnoNoteTag()

const NoteTag * clang::ento::errno_modeling::getErrnoNoteTag ( CheckerContext C,
const std::string &  Message 
)

Create a NoteTag that displays the message if the 'errno' memory region is marked as interesting, and resets the interestingness.

Definition at line 278 of file ErrnoModeling.cpp.

References clang::C, clang::ento::PathSensitiveBugReport::getErrorNode(), and clang::ento::PathSensitiveBugReport::isInteresting().

Referenced by getNoteTagForStdMustBeChecked(), and getNoteTagForStdSuccess().

◆ getErrnoState()

ErrnoCheckState clang::ento::errno_modeling::getErrnoState ( ProgramStateRef  State)

Returns the errno check state, Errno_Irrelevant if 'errno' was not found (this is not the only case for that value).

Definition at line 250 of file ErrnoModeling.cpp.

◆ getErrnoValue()

std::optional< SVal > clang::ento::errno_modeling::getErrnoValue ( ProgramStateRef  State)

Returns the value of 'errno', if 'errno' was found in the AST.

Definition at line 211 of file ErrnoModeling.cpp.

◆ getNoteTagForStdMustBeChecked()

const NoteTag * clang::ento::errno_modeling::getNoteTagForStdMustBeChecked ( CheckerContext C,
llvm::StringRef  Fn 
)

Generate the note tag that can be applied at the state generated by setErrnoStdMustBeChecked .

  • Fn Name of the (standard) function that is modeled.

Definition at line 328 of file ErrnoModeling.cpp.

References clang::C, and getErrnoNoteTag().

◆ getNoteTagForStdSuccess()

const NoteTag * clang::ento::errno_modeling::getNoteTagForStdSuccess ( CheckerContext C,
llvm::StringRef  Fn 
)

Generate the note tag that can be applied at the state generated by setErrnoForStdSuccess .

  • Fn Name of the (standard) function that is modeled.

Definition at line 320 of file ErrnoModeling.cpp.

References clang::C, describeErrnoCheckState(), getErrnoNoteTag(), and MustNotBeChecked.

◆ isErrno()

bool clang::ento::errno_modeling::isErrno ( const Decl D)

Determine if a Decl node related to 'errno'.

This is true if the declaration is the errno variable or a function that returns a pointer to the 'errno' value (usually the 'errno' macro is defined with this function). D is not required to be a canonical declaration.

Definition at line 262 of file ErrnoModeling.cpp.

◆ setErrnoForStdFailure()

ProgramStateRef clang::ento::errno_modeling::setErrnoForStdFailure ( ProgramStateRef  State,
CheckerContext C,
NonLoc  ErrnoSym 
)

Set errno state for the common case when a standard function fails.

Set errno value to be not equal to zero and ErrnoCheckState to Irrelevant . The irrelevant errno state ensures that no related bug report is emitted later and no note tag is needed.

  • ErrnoSym Value to be used for errno and constrained to be non-zero.

Definition at line 294 of file ErrnoModeling.cpp.

References clang::C, clang::ento::SVal::castAs(), clang::ento::SValBuilder::evalBinOp(), clang::ento::SValBuilder::getConditionType(), Irrelevant, clang::ento::SValBuilder::makeZeroVal(), and setErrnoValue().

◆ setErrnoForStdSuccess()

ProgramStateRef clang::ento::errno_modeling::setErrnoForStdSuccess ( ProgramStateRef  State,
CheckerContext C 
)

Set errno state for the common case when a standard function is successful.

Set ErrnoCheckState to MustNotBeChecked (the errno value is not affected). At the state transition a note tag created by getNoteTagForStdSuccess can be used.

Definition at line 289 of file ErrnoModeling.cpp.

References MustNotBeChecked, and setErrnoState().

◆ setErrnoState()

ProgramStateRef clang::ento::errno_modeling::setErrnoState ( ProgramStateRef  State,
ErrnoCheckState  EState 
)

Set the errno check state, do not modify the errno value.

Definition at line 254 of file ErrnoModeling.cpp.

Referenced by clearErrnoState(), setErrnoForStdSuccess(), setErrnoStateIrrelevant(), and setErrnoStdMustBeChecked().

◆ setErrnoStdMustBeChecked()

ProgramStateRef clang::ento::errno_modeling::setErrnoStdMustBeChecked ( ProgramStateRef  State,
CheckerContext C,
const Expr InvalE 
)

Set errno state for the common case when a standard function indicates failure only by errno.

Sets ErrnoCheckState to MustBeChecked, and invalidates the errno region (clear of previous value). At the state transition a note tag created by getNoteTagForStdMustBeChecked can be used.

  • InvalE Expression that causes invalidation of errno.

Definition at line 307 of file ErrnoModeling.cpp.

References clang::C, MustBeChecked, and setErrnoState().

◆ setErrnoValue() [1/2]

ProgramStateRef clang::ento::errno_modeling::setErrnoValue ( ProgramStateRef  State,
CheckerContext C,
uint64_t  Value,
ErrnoCheckState  EState 
)

Set value of 'errno' to a concrete (signed) integer, if possible.

The errno check state is set always when the 'errno' value is set.

Definition at line 231 of file ErrnoModeling.cpp.

References clang::C.

◆ setErrnoValue() [2/2]

ProgramStateRef clang::ento::errno_modeling::setErrnoValue ( ProgramStateRef  State,
const LocationContext LCtx,
SVal  Value,
ErrnoCheckState  EState 
)

Set value of 'errno' to any SVal, if possible.

The errno check state is set always when the 'errno' value is set.

Definition at line 219 of file ErrnoModeling.cpp.

Referenced by setErrnoForStdFailure().