Path: blob/main/contrib/llvm-project/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
35269 views
//=== ErrnoModeling.h - Tracking value of 'errno'. -----------------*- C++ -*-//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// Defines inter-checker API for using the system value 'errno'.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_ERRNOMODELING_H13#define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_ERRNOMODELING_H1415#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"16#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"17#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"18#include <optional>1920namespace clang {21namespace ento {22namespace errno_modeling {2324/// Describe how reads and writes of \c errno are handled by the checker.25enum ErrnoCheckState : unsigned {26/// We do not know anything about 'errno'.27/// Read and write is always allowed.28Irrelevant = 0,2930/// Value of 'errno' should be checked to find out if a previous function call31/// has failed.32/// When this state is set \c errno must be read by the program before a next33/// standard function call or other overwrite of \c errno follows, otherwise34/// a bug report is emitted.35MustBeChecked = 1,3637/// Value of 'errno' is not allowed to be read, it can contain an unspecified38/// value.39/// When this state is set \c errno is not allowed to be read by the program40/// until it is overwritten or invalidated.41MustNotBeChecked = 242};4344/// Returns the value of 'errno', if 'errno' was found in the AST.45std::optional<SVal> getErrnoValue(ProgramStateRef State);4647/// Returns the errno check state, \c Errno_Irrelevant if 'errno' was not found48/// (this is not the only case for that value).49ErrnoCheckState getErrnoState(ProgramStateRef State);5051/// Returns the location that points to the \c MemoryRegion where the 'errno'52/// value is stored. Returns \c std::nullopt if 'errno' was not found. Otherwise53/// it always returns a valid memory region in the system global memory space.54std::optional<Loc> getErrnoLoc(ProgramStateRef State);5556/// Set value of 'errno' to any SVal, if possible.57/// The errno check state is set always when the 'errno' value is set.58ProgramStateRef setErrnoValue(ProgramStateRef State,59const LocationContext *LCtx, SVal Value,60ErrnoCheckState EState);6162/// Set value of 'errno' to a concrete (signed) integer, if possible.63/// The errno check state is set always when the 'errno' value is set.64ProgramStateRef setErrnoValue(ProgramStateRef State, CheckerContext &C,65uint64_t Value, ErrnoCheckState EState);6667/// Set the errno check state, do not modify the errno value.68ProgramStateRef setErrnoState(ProgramStateRef State, ErrnoCheckState EState);6970/// Clear state of errno (make it irrelevant).71ProgramStateRef clearErrnoState(ProgramStateRef State);7273/// Determine if `Call` is a call to an internal function that returns the74/// location of `errno` (in environments where errno is accessed this way).75bool isErrnoLocationCall(const CallEvent &Call);7677/// Create a NoteTag that displays the message if the 'errno' memory region is78/// marked as interesting, and resets the interestingness.79const NoteTag *getErrnoNoteTag(CheckerContext &C, const std::string &Message);8081/// Set errno state for the common case when a standard function is successful.82/// Set \c ErrnoCheckState to \c MustNotBeChecked (the \c errno value is not83/// affected).84ProgramStateRef setErrnoForStdSuccess(ProgramStateRef State, CheckerContext &C);8586/// Set errno state for the common case when a standard function fails.87/// Set \c errno value to be not equal to zero and \c ErrnoCheckState to88/// \c Irrelevant . The irrelevant errno state ensures that no related bug89/// report is emitted later and no note tag is needed.90/// \arg \c ErrnoSym Value to be used for \c errno and constrained to be91/// non-zero.92ProgramStateRef setErrnoForStdFailure(ProgramStateRef State, CheckerContext &C,93NonLoc ErrnoSym);9495/// Set errno state for the common case when a standard function indicates96/// failure only by \c errno. Sets \c ErrnoCheckState to \c MustBeChecked, and97/// invalidates the errno region (clear of previous value).98/// \arg \c InvalE Expression that causes invalidation of \c errno.99ProgramStateRef setErrnoStdMustBeChecked(ProgramStateRef State,100CheckerContext &C, const Expr *InvalE);101102} // namespace errno_modeling103} // namespace ento104} // namespace clang105106#endif // LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_ERRNOMODELING_H107108109