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

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_CONSUMED_H

15#define LLVM_CLANG_ANALYSIS_ANALYSES_CONSUMED_H

16

22#include "llvm/ADT/DenseMap.h"

23#include "llvm/ADT/SmallVector.h"

24#include "llvm/ADT/StringRef.h"

25#include

26#include

27#include

28#include

29

31

32class AnalysisDeclContext;

33class CXXBindTemporaryExpr;

34class FunctionDecl;

35class PostOrderCFGView;

36class Stmt;

37class VarDecl;

38

39namespace consumed {

40

42

44

46

51

53 using DelayedDiag = std::pair<PartialDiagnosticAt, OptionalNotes>;

54 using DiagList = std::list;

55

57 public:

59

60

62

63

64

65

66

67

68

69

71 StringRef VariableName) {}

72

73

74

75

76

77

78

79

80

81

83 StringRef VariableName,

84 StringRef ExpectedState,

85 StringRef ObservedState) {}

86

87

89 StringRef ExpectedState,

90 StringRef ObservedState) {}

91

92

93

94

95

96

97

98

100 StringRef TypeName) {}

101

102

103

104

105

106

107

108

109

110

112 StringRef ExpectedState,

113 StringRef ObservedState) {}

114

115

116

117

118

119

120

121

123 StringRef State,

125

126

127

128

129

130

131

132

133

134

135

137 StringRef VariableName,

138 StringRef State,

140 };

141

143 using VarMapType = llvm::DenseMap<const VarDecl *, ConsumedState>;

144 using TmpMapType =

145 llvm::DenseMap<const CXXBindTemporaryExpr *, ConsumedState>;

146

147 protected:

152

153 public:

157

158

159

161

162

163

166

167

169

170

172

173

175

176

178

182

183

185

186

188

189

190

191

193

194

196

197

199

200

202

203

204

205

206

208 };

209

211 std::vector<std::unique_ptr> StateMapsArray;

212 std::vector VisitOrder;

213

214 public:

216

218 : StateMapsArray(NumBlocks), VisitOrder(NumBlocks, 0) {

219 unsigned int VisitOrderCounter = 0;

220 for (const auto BI : *SortedGraph)

221 VisitOrder[BI->getBlockID()] = VisitOrderCounter++;

222 }

223

225 const CFGBlock *TargetBlock);

226

228 std::unique_ptr &OwnedStateMap);

230 std::unique_ptr StateMap);

231

233

235

237

240 };

241

242

245 std::unique_ptr CurrStates;

246

248

251 bool splitState(const CFGBlock *CurrBlock,

253

254 public:

256

259

261

262

263

264

265

266

267

269 };

270

271}

272

273}

274

275#endif

Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.

Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.

Defines the clang::SourceLocation class and associated facilities.

AnalysisDeclContext contains the context data for the function, method or block under analysis.

Represents a single basic block in a source-level CFG.

Represents binding an expression to a temporary.

Represents a function declaration or definition.

Encodes a location in the source.

Stmt - This represents one statement.

Represents a variable declaration or definition.

A class that handles the analysis of uniqueness violations.

ConsumedWarningsHandlerBase & WarningsHandler

ConsumedState getExpectedReturnState() const

ConsumedAnalyzer(ConsumedWarningsHandlerBase &WarningsHandler)

void run(AnalysisDeclContext &AC)

Check a function's CFG for consumed violations.

ConsumedStateMap * borrowInfo(const CFGBlock *Block)

bool isBackEdgeTarget(const CFGBlock *Block)

ConsumedBlockInfo()=default

std::unique_ptr< ConsumedStateMap > getInfo(const CFGBlock *Block)

ConsumedBlockInfo(unsigned int NumBlocks, PostOrderCFGView *SortedGraph)

void addInfo(const CFGBlock *Block, ConsumedStateMap *StateMap, std::unique_ptr< ConsumedStateMap > &OwnedStateMap)

void discardInfo(const CFGBlock *Block)

bool allBackEdgesVisited(const CFGBlock *CurrBlock, const CFGBlock *TargetBlock)

bool isBackEdge(const CFGBlock *From, const CFGBlock *To)

bool isReachable() const

Return true if this block is reachable.

void clearTemporaries()

Clear the TmpMap.

ConsumedStateMap & operator=(const ConsumedStateMap &)=delete

void checkParamsForReturnTypestate(SourceLocation BlameLoc, ConsumedWarningsHandlerBase &WarningsHandler) const

Warn if any of the parameters being tracked are not in the state they were declared to be in upon ret...

void intersect(const ConsumedStateMap &Other)

Merge this state map with another map.

ConsumedState getState(const VarDecl *Var) const

Get the consumed state of a given variable.

void intersectAtLoopHead(const CFGBlock *LoopHead, const CFGBlock *LoopBack, const ConsumedStateMap *LoopBackStates, ConsumedWarningsHandlerBase &WarningsHandler)

void remove(const CXXBindTemporaryExpr *Tmp)

Remove the temporary value from our state map.

void markUnreachable()

Mark the block as unreachable.

bool operator!=(const ConsumedStateMap *Other) const

Tests to see if there is a mismatch in the states stored in two maps.

ConsumedStateMap()=default

ConsumedStateMap(const ConsumedStateMap &Other)

void setState(const VarDecl *Var, ConsumedState State)

Set the consumed state of a given variable.

void setSource(const Stmt *Source)

Set the source for a decision about the branching of states.

virtual void warnUseOfTempInInvalidState(StringRef MethodName, StringRef State, SourceLocation Loc)

Warn about use-while-consumed errors.

virtual void warnParamTypestateMismatch(SourceLocation LOC, StringRef ExpectedState, StringRef ObservedState)

virtual void warnLoopStateMismatch(SourceLocation Loc, StringRef VariableName)

Warn that a variable's state doesn't match at the entry and exit of a loop.

virtual void warnUseInInvalidState(StringRef MethodName, StringRef VariableName, StringRef State, SourceLocation Loc)

Warn about use-while-consumed errors.

virtual void emitDiagnostics()

Emit the warnings and notes left by the analysis.

virtual void warnReturnTypestateMismatch(SourceLocation Loc, StringRef ExpectedState, StringRef ObservedState)

Warn about return typestate mismatches.

virtual void warnReturnTypestateForUnconsumableType(SourceLocation Loc, StringRef TypeName)

Warn about return typestates set for unconsumable types.

virtual ~ConsumedWarningsHandlerBase()

virtual void warnParamReturnTypestateMismatch(SourceLocation Loc, StringRef VariableName, StringRef ExpectedState, StringRef ObservedState)

Warn about parameter typestate mismatches upon return.

std::list< DelayedDiag > DiagList

std::pair< PartialDiagnosticAt, OptionalNotes > DelayedDiag

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

@ Other

Other implicit parameter.