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

30}

31

33 if (!FunDecl)

34 return StringRef();

36 if (!funI)

37 return StringRef();

39}

40

42 if (isa<ObjCMethodDecl, CXXMethodDecl>(D))

43 return "method";

44 if (isa(D))

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;

145 if (!isa(LHSVal)) {

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

165}

166

170}

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.

Builtin::Context & BuiltinInfo

llvm::StringRef 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.

const SourceManager & getSourceManager()

SValBuilder & getSValBuilder()

StringRef getCalleeName(const FunctionDecl *FunDecl) const

Get the name of the called function (path-sensitive).

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.

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.

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,...

const FunctionDecl * getCalleeDecl(const CallExpr *CE) const

Get the declaration of the called function (path-sensitive).

StringRef getMacroNameOrSpelling(SourceLocation &Loc)

Depending on wither the location corresponds to a macro, return either the macro name or the token sp...

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...

SVal getSVal(const Stmt *S) const

Get the value of an arbitrary expression at this node.

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.

The JSON file list parser is used to communicate input to InstallAPI.