clang: include/clang/Analysis/Analyses/UnsafeBufferUsage.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_UNSAFEBUFFERUSAGE_H

15#define LLVM_CLANG_ANALYSIS_ANALYSES_UNSAFEBUFFERUSAGE_H

16

22#include "llvm/Support/Debug.h"

23#include

24

26

27using VarGrpTy = std::vector<const VarDecl *>;

29

31public:

34

35

36

37

38

39

41 bool *HasParm = nullptr) const =0;

42

43

44

46};

47

48

49

50

51

53public:

61

62private:

63 using MapTy = llvm::DenseMap<const VarDecl *, Kind>;

64

66

67public:

73

75

77 auto I = Map.find(VD);

78 if (I == Map.end())

80

81 return I->second;

82 }

83};

84

85

86

88#ifndef NDEBUG

89public:

90

91

92

93

94 using DebugNote = std::pair<SourceLocation, std::string>;

96 using DebugNoteByVar = std::map<const VarDecl *, DebugNoteList>;

98#endif

99

100public:

103

104

105

107

108

110 bool IsRelatedToDecl, ASTContext &Ctx) = 0;

111

112

113

114

115

116

117

118

119

120

121

124 const Expr *UnsafeArg = nullptr) = 0;

125

126

128 bool IsRelatedToDecl,

130

131

132

133

134

135

136

137 virtual void

142

143

144

146 bool IsRelatedToDecl,

148

149#ifndef NDEBUG

150public:

152 DEBUG_WITH_TYPE("SafeBuffers", return true);

153 return false;

154 }

155

157 std::string Text) {

160 }

161

166#endif

167

168public:

169

171

172

173

174 virtual bool

176

177

178 virtual bool

180

181 virtual std::string

183 StringRef WSSuffix = "") const = 0;

184};

185

186

187

189 bool EmitSuggestions);

190

192

193

196}

197

199}

200

201#endif

llvm::DenseMap< Stmt *, Stmt * > MapTy

Defines the clang::SourceLocation class and associated facilities.

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).

Decl - This represents one declaration (or definition), e.g.

A dynamically typed AST node container.

This represents one expression.

Definition UnsafeBufferUsage.h:52

FixitStrategy(FixitStrategy &&)=default

FixitStrategy & operator=(const FixitStrategy &)=delete

FixitStrategy & operator=(FixitStrategy &&)=default

FixitStrategy(const FixitStrategy &)=delete

Kind lookup(const VarDecl *VD) const

Definition UnsafeBufferUsage.h:76

void set(const VarDecl *VD, Kind K)

Definition UnsafeBufferUsage.h:74

Kind

Definition UnsafeBufferUsage.h:54

@ Iterator

Definition UnsafeBufferUsage.h:57

@ Array

Definition UnsafeBufferUsage.h:58

@ Vector

Definition UnsafeBufferUsage.h:59

@ Wontfix

Definition UnsafeBufferUsage.h:55

@ Span

Definition UnsafeBufferUsage.h:56

Encodes a location in the source.

This class handles loading and caching of source files into memory.

Stmt - This represents one statement.

The interface that lets the caller handle unsafe buffer usage analysis results by overriding this cla...

Definition UnsafeBufferUsage.h:87

virtual void handleUnsafeUniquePtrArrayAccess(const DynTypedNode &Node, bool IsRelatedToDecl, ASTContext &Ctx)=0

DebugNoteByVar DebugNotesByVar

Definition UnsafeBufferUsage.h:97

bool areDebugNotesRequested()

Definition UnsafeBufferUsage.h:151

void clearDebugNotes()

Definition UnsafeBufferUsage.h:162

void addDebugNoteForVar(const VarDecl *VD, SourceLocation Loc, std::string Text)

Definition UnsafeBufferUsage.h:156

std::vector< DebugNote > DebugNoteList

Definition UnsafeBufferUsage.h:95

virtual std::string getUnsafeBufferUsageAttributeTextAt(SourceLocation Loc, StringRef WSSuffix="") const =0

virtual bool isSafeBufferOptOut(const SourceLocation &Loc) const =0

std::map< const VarDecl *, DebugNoteList > DebugNoteByVar

Definition UnsafeBufferUsage.h:96

std::pair< SourceLocation, std::string > DebugNote

Definition UnsafeBufferUsage.h:94

llvm::SmallVectorImpl< FixItHint > FixItList

This analyses produces large fixits that are organized into lists of primitive fixits (individual ins...

Definition UnsafeBufferUsage.h:106

virtual bool ignoreUnsafeBufferInContainer(const SourceLocation &Loc) const =0

virtual void handleUnsafeOperation(const Stmt *Operation, bool IsRelatedToDecl, ASTContext &Ctx)=0

Invoked when an unsafe operation over raw pointers is found.

UnsafeBufferUsageHandler()=default

virtual void handleUnsafeVariableGroup(const VarDecl *Variable, const VariableGroupsManager &VarGrpMgr, FixItList &&Fixes, const Decl *D, const FixitStrategy &VarTargetTypes)=0

Invoked when a fix is suggested against a variable.

virtual ~UnsafeBufferUsageHandler()=default

virtual void handleUnsafeOperationInContainer(const Stmt *Operation, bool IsRelatedToDecl, ASTContext &Ctx)=0

Invoked when an unsafe operation with a std container is found.

virtual bool ignoreUnsafeBufferInLibcCall(const SourceLocation &Loc) const =0

virtual void handleUnsafeLibcCall(const CallExpr *Call, unsigned PrintfInfo, ASTContext &Ctx, const Expr *UnsafeArg=nullptr)=0

Invoked when a call to an unsafe libc function is found.

Represents a variable declaration or definition.

Definition UnsafeBufferUsage.h:30

virtual ~VariableGroupsManager()=default

VariableGroupsManager()=default

virtual VarGrpRef getGroupOfVar(const VarDecl *Var, bool *HasParm=nullptr) const =0

Returns the set of variables (including Var) that need to be fixed together in one step.

virtual VarGrpRef getGroupOfParms() const =0

Returns the non-empty group of variables that include parameters of the analyzing function,...

bool anyConflict(const llvm::SmallVectorImpl< FixItHint > &FixIts, const SourceManager &SM)

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

void checkUnsafeBufferUsage(const Decl *D, UnsafeBufferUsageHandler &Handler, bool EmitSuggestions)

std::vector< const VarDecl * > VarGrpTy

Definition UnsafeBufferUsage.h:27

std::set< const Expr * > findUnsafePointers(const FunctionDecl *FD)

ArrayRef< const VarDecl * > VarGrpRef

Definition UnsafeBufferUsage.h:28