clang: lib/StaticAnalyzer/Core/CheckerContext.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
17#include "llvm/ADT/StringExtras.h"
18
19using namespace clang;
20using namespace ento;
21
24 if (D)
25 return D;
26
28 SVal L = Pred->getSVal(Callee);
30}
31
33 if (!FunDecl)
34 return StringRef();
36 if (!funI)
37 return StringRef();
39}
40
43 return "method";
45 return "anonymous block";
46 return "function";
47}
48
50 StringRef Name) {
51
52
53
55 if (BId != 0) {
56 if (Name.empty())
57 return true;
59 size_t start = BName.find(Name);
60 if (start != StringRef::npos) {
61
62 if (BName.size() == Name.size())
63 return true;
64
65
66
67
68
69
70 const auto MatchPredecessor = [&]() -> bool {
71 return start <= 0 || !llvm::isAlpha(BName[start - 1]);
72 };
73 const auto MatchSuccessor = [&]() -> bool {
74 std::size_t LookbehindPlace = start + Name.size();
75 return LookbehindPlace >= BName.size() ||
76 !llvm::isAlpha(BName[LookbehindPlace]);
77 };
78
79 if (MatchPredecessor() && MatchSuccessor())
80 return true;
81 }
82 }
83
85
86
87 if (!II)
88 return false;
89
90
91
92
95 return false;
96
97
98
99
101 return false;
102
103 if (Name.empty())
104 return true;
105
106 StringRef FName = II->getName();
107 if (FName == Name)
108 return true;
109
110 if (FName.starts_with("__inline") && FName.contains(Name))
111 return true;
112
113 return false;
114}
115
117 StringRef Name) {
119 if (!II)
120 return false;
121
122 auto CompletelyMatchesParts = [II](auto... Parts) -> bool {
123 StringRef FName = II->getName();
124 return (FName.consume_front(Parts) && ...) && FName.empty();
125 };
126
127 return CompletelyMatchesParts("__", Name, "_chk") ||
128 CompletelyMatchesParts("__builtin_", "__", Name, "_chk");
129}
130
132 if (Loc.isMacroID())
137}
138
139
143 return false;
149 return false;
150 }
151
153 SVal Eval = Bldr.evalBinOp(State, ComparisonOp, LHSVal, RHSVal,
156 return false;
158 std::tie(StTrue, StFalse) = State->assume(Eval.castAs<DefinedSVal>());
159 return StTrue && !StFalse;
160}
161
166
Defines enum values for all the target-independent builtin functions.
static bool evalComparison(SVal LHSVal, BinaryOperatorKind ComparisonOp, SVal RHSVal, ProgramStateRef State)
Evaluate comparison and return true if it's known that condition is true.
Definition CheckerContext.cpp:140
Builtin::Context & BuiltinInfo
std::string getName(unsigned ID) const
Return the identifier name for the specified builtin, e.g.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool isTranslationUnit() const
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
bool isStdNamespace() const
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
DeclContext * getDeclContext()
This represents one expression.
Represents a function declaration or definition.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
static StringRef getImmediateMacroName(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts)
Retrieve the name of the immediate macro expansion.
static unsigned getSpelling(const Token &Tok, const char *&Buffer, const SourceManager &SourceMgr, const LangOptions &LangOpts, bool *Invalid=nullptr)
getSpelling - This method is used to get the spelling of a token into a preallocated buffer,...
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
bool isExternallyVisible() const
Encodes a location in the source.
StringRef getDeclDescription(const Decl *D)
Returns the word that should be used to refer to the declaration in the report.
Definition CheckerContext.cpp:41
const SourceManager & getSourceManager()
SValBuilder & getSValBuilder()
StringRef getCalleeName(const FunctionDecl *FunDecl) const
Get the name of the called function (path-sensitive).
Definition CheckerContext.cpp:32
ASTContext & getASTContext()
const ProgramStateRef & getState() const
SVal getSVal(const Stmt *S) const
Get the value of arbitrary expressions at this point in the path.
bool isNegative(const Expr *E)
Returns true if the value of E is negative.
Definition CheckerContext.cpp:167
bool isGreaterOrEqual(const Expr *E, unsigned long long Val)
Returns true if the value of E is greater than or equal to Val under unsigned comparison.
Definition CheckerContext.cpp:162
static bool isCLibraryFunction(const FunctionDecl *FD, StringRef Name=StringRef())
Returns true if the given function is an externally-visible function in the top-level namespace,...
Definition CheckerContext.cpp:49
const FunctionDecl * getCalleeDecl(const CallExpr *CE) const
Get the declaration of the called function (path-sensitive).
Definition CheckerContext.cpp:22
StringRef getMacroNameOrSpelling(SourceLocation &Loc)
Depending on whether the location corresponds to a macro, return either the macro name or the token s...
Definition CheckerContext.cpp:131
const LangOptions & getLangOpts() const
static bool isHardenedVariantOf(const FunctionDecl *FD, StringRef Name)
In builds that use source hardening (-D_FORTIFY_SOURCE), many standard functions are implemented as m...
Definition CheckerContext.cpp:116
SValBuilder & getSValBuilder()
StoreManager & getStoreManager()
nonloc::ConcreteInt makeIntVal(const IntegerLiteral *integer)
QualType getConditionType() const
SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op, SVal lhs, SVal rhs, QualType type)
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
bool isUnknownOrUndef() const
const FunctionDecl * getAsFunctionDecl() const
getAsFunctionDecl - If this SVal is a MemRegionVal and wraps a CodeTextRegion wrapping a FunctionDecl...
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
virtual SVal getBinding(Store store, Loc loc, QualType T=QualType())=0
Return the value bound to specified location in a given state.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)