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

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

22

24

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

27

29public:

32

33

34

35

36

37

39 bool *HasParm = nullptr) const =0;

40

41

42

44};

45

46

47

48

49

51public:

53 Wontfix,

54 Span,

55 Iterator,

56 Array,

57 Vector

58 };

59

60private:

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

62

64

65public:

71

73

75 auto I = Map.find(VD);

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

78

79 return I->second;

80 }

81};

82

83

84

86#ifndef NDEBUG

87public:

88

89

90

91

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

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

96#endif

97

98public:

101

102

103

105

106

108 bool IsRelatedToDecl, ASTContext &Ctx) = 0;

109

110

111

112

113

114

115

116

117

118

119

122 const Expr *UnsafeArg = nullptr) = 0;

123

124

126 bool IsRelatedToDecl,

128

129

130

131

132

133

134

135 virtual void

140

141#ifndef NDEBUG

142public:

144 DEBUG_WITH_TYPE("SafeBuffers", return true);

145 return false;

146 }

147

149 std::string Text) {

152 }

153

157 }

158#endif

159

160public:

161

163

164

165

166 virtual bool

168

169

170 virtual bool

172

173 virtual std::string

175 StringRef WSSuffix = "") const = 0;

176};

177

178

179

181 bool EmitSuggestions);

182

183namespace internal {

184

185

188}

189}

190

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

This represents one expression.

FixitStrategy(FixitStrategy &&)=default

FixitStrategy & operator=(const FixitStrategy &)=delete

FixitStrategy & operator=(FixitStrategy &&)=default

FixitStrategy(const FixitStrategy &)=delete

Kind lookup(const VarDecl *VD) const

void set(const VarDecl *VD, Kind K)

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

DebugNoteByVar DebugNotesByVar

bool areDebugNotesRequested()

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

std::vector< DebugNote > DebugNoteList

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

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

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

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

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.

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