clang  15.0.0git
ErrnoModeling.h
Go to the documentation of this file.
1 //=== ErrnoModeling.h - Tracking value of 'errno'. -----------------*- C++ -*-//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Defines inter-checker API for using the system value 'errno'.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_ERRNOMODELING_H
14 #define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_ERRNOMODELING_H
15 
19 
20 namespace clang {
21 namespace ento {
22 namespace errno_modeling {
23 
24 enum ErrnoCheckState : unsigned {
25  /// We do not know anything about 'errno'.
27 
28  /// Value of 'errno' should be checked to find out if a previous function call
29  /// has failed.
31 
32  /// Value of 'errno' is not allowed to be read, it can contain an unspecified
33  /// value.
35 };
36 
37 /// Returns the value of 'errno', if 'errno' was found in the AST.
39 
40 /// Returns the errno check state, \c Errno_Irrelevant if 'errno' was not found
41 /// (this is not the only case for that value).
43 
44 /// Returns the location that points to the \c MemoryRegion where the 'errno'
45 /// value is stored. Returns \c None if 'errno' was not found. Otherwise it
46 /// always returns a valid memory region in the system global memory space.
48 
49 /// Set value of 'errno' to any SVal, if possible.
50 /// The errno check state is set always when the 'errno' value is set.
52  const LocationContext *LCtx, SVal Value,
53  ErrnoCheckState EState);
54 
55 /// Set value of 'errno' to a concrete (signed) integer, if possible.
56 /// The errno check state is set always when the 'errno' value is set.
59 
60 /// Set the errno check state, do not modify the errno value.
62 
63 /// Determine if a `Decl` node related to 'errno'.
64 /// This is true if the declaration is the errno variable or a function
65 /// that returns a pointer to the 'errno' value (usually the 'errno' macro is
66 /// defined with this function). \p D is not required to be a canonical
67 /// declaration.
68 bool isErrno(const Decl *D);
69 
70 /// Create a NoteTag that displays the message if the 'errno' memory region is
71 /// marked as interesting, and resets the interestingness.
72 const NoteTag *getErrnoNoteTag(CheckerContext &C, const std::string &Message);
73 
74 } // namespace errno_modeling
75 } // namespace ento
76 } // namespace clang
77 
78 #endif // LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_ERRNOMODELING_H
clang::LocationContext
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
Definition: AnalysisDeclContext.h:215
SVals.h
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::ento::errno_modeling::Irrelevant
@ Irrelevant
We do not know anything about 'errno'.
Definition: ErrnoModeling.h:26
clang::ento::errno_modeling::MustBeChecked
@ MustBeChecked
Value of 'errno' should be checked to find out if a previous function call has failed.
Definition: ErrnoModeling.h:30
llvm::Optional
Definition: LLVM.h:40
uint64_t
unsigned long uint64_t
Definition: hlsl_basic_types.h:24
clang::ento::errno_modeling::getErrnoNoteTag
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,...
Definition: ErrnoModeling.cpp:267
clang::ento::errno_modeling::setErrnoState
ProgramStateRef setErrnoState(ProgramStateRef State, ErrnoCheckState EState)
Set the errno check state, do not modify the errno value.
Definition: ErrnoModeling.cpp:249
clang::ento::errno_modeling::MustNotBeChecked
@ MustNotBeChecked
Value of 'errno' is not allowed to be read, it can contain an unspecified value.
Definition: ErrnoModeling.h:34
clang::ento::errno_modeling::setErrnoValue
ProgramStateRef setErrnoValue(ProgramStateRef State, const LocationContext *LCtx, SVal Value, ErrnoCheckState EState)
Set value of 'errno' to any SVal, if possible.
Definition: ErrnoModeling.cpp:218
clang::ento::errno_modeling::ErrnoCheckState
ErrnoCheckState
Definition: ErrnoModeling.h:24
clang::ento::errno_modeling::getErrnoValue
Optional< SVal > getErrnoValue(ProgramStateRef State)
Returns the value of 'errno', if 'errno' was found in the AST.
Definition: ErrnoModeling.cpp:210
clang::ento::errno_modeling::isErrno
bool isErrno(const Decl *D)
Determine if a Decl node related to 'errno'.
Definition: ErrnoModeling.cpp:257
Value
Value
Definition: UninitializedValues.cpp:102
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
State
LineState State
Definition: UnwrappedLineFormatter.cpp:1126
CheckerContext.h
ProgramState.h
clang
Definition: CalledOnceCheck.h:17
clang::ento::errno_modeling::getErrnoLoc
Optional< Loc > getErrnoLoc(ProgramStateRef State)
Returns the location that points to the MemoryRegion where the 'errno' value is stored.
Definition: ErrnoModeling.cpp:242
clang::ento::CheckerContext
Definition: CheckerContext.h:23
clang::ento::SVal
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
Definition: SVals.h:74
clang::ento::errno_modeling::getErrnoState
ErrnoCheckState getErrnoState(ProgramStateRef State)
Returns the errno check state, Errno_Irrelevant if 'errno' was not found (this is not the only case f...
Definition: ErrnoModeling.cpp:253
clang::ento::NoteTag
The tag upon which the TagVisitor reacts.
Definition: BugReporter.h:763
llvm::IntrusiveRefCntPtr
Definition: LLVM.h:47