15 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_CONSUMED_H
16 #define LLVM_CLANG_ANALYSIS_ANALYSES_CONSUMED_H
40 typedef std::pair<PartialDiagnosticAt, OptionalNotes>
DelayedDiag;
60 StringRef VariableName) {}
72 StringRef VariableName,
73 StringRef ExpectedState,
74 StringRef ObservedState) {}
78 StringRef ExpectedState,
79 StringRef ObservedState) {}
89 StringRef TypeName) {}
101 StringRef ExpectedState,
102 StringRef ObservedState) {}
126 StringRef VariableName,
133 typedef llvm::DenseMap<const VarDecl *, ConsumedState> VarMapType;
134 typedef llvm::DenseMap<const CXXBindTemporaryExpr *, ConsumedState>
199 std::vector<std::unique_ptr<ConsumedStateMap>> StateMapsArray;
200 std::vector<unsigned int> VisitOrder;
205 StateMapsArray = std::move(Other.StateMapsArray);
206 VisitOrder = std::move(Other.VisitOrder);
211 : StateMapsArray(NumBlocks), VisitOrder(NumBlocks, 0) {
212 unsigned int VisitOrderCounter = 0;
214 BE = SortedGraph->
end(); BI != BE; ++BI) {
215 VisitOrder[(*BI)->getBlockID()] = VisitOrderCounter++;
223 std::unique_ptr<ConsumedStateMap> &OwnedStateMap);
225 std::unique_ptr<ConsumedStateMap> StateMap);
241 std::unique_ptr<ConsumedStateMap> CurrStates;
247 bool splitState(
const CFGBlock *CurrBlock,
255 : WarningsHandler(WarningsHandler) {}
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
virtual void warnReturnTypestateForUnconsumableType(SourceLocation Loc, StringRef TypeName)
Warn about return typestates set for unconsumable types.
void addInfo(const CFGBlock *Block, ConsumedStateMap *StateMap, std::unique_ptr< ConsumedStateMap > &OwnedStateMap)
virtual void warnParamReturnTypestateMismatch(SourceLocation Loc, StringRef VariableName, StringRef ExpectedState, StringRef ObservedState)
Warn about parameter typestate mismatches upon return.
void run(AnalysisDeclContext &AC)
Check a function's CFG for consumed violations.
virtual void warnUseInInvalidState(StringRef MethodName, StringRef VariableName, StringRef State, SourceLocation Loc)
Warn about use-while-consumed errors.
bool isReachable() const
Return true if this block is reachable.
void setState(const VarDecl *Var, ConsumedState State)
Set the consumed state of a given variable.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Defines the clang::Expr interface and subclasses for C++ expressions.
void intersectAtLoopHead(const CFGBlock *LoopHead, const CFGBlock *LoopBack, const ConsumedStateMap *LoopBackStates, ConsumedWarningsHandlerBase &WarningsHandler)
std::pair< PartialDiagnosticAt, OptionalNotes > DelayedDiag
AnalysisDeclContext contains the context data for the function or method under analysis.
void markUnreachable()
Mark the block as unreachable.
ConsumedState getState(const VarDecl *Var) const
Get the consumed state of a given variable.
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...
bool allBackEdgesVisited(const CFGBlock *CurrBlock, const CFGBlock *TargetBlock)
ConsumedBlockInfo()=default
std::unique_ptr< ConsumedStateMap > getInfo(const CFGBlock *Block)
Represents binding an expression to a temporary.
ConsumedBlockInfo & operator=(ConsumedBlockInfo &&Other)
CFGBlock - Represents a single basic block in a source-level CFG.
virtual void warnLoopStateMismatch(SourceLocation Loc, StringRef VariableName)
Warn that a variable's state doesn't match at the entry and exit of a loop.
bool isBackEdge(const CFGBlock *From, const CFGBlock *To)
void clearTemporaries()
Clear the TmpMap.
virtual void emitDiagnostics()
Emit the warnings and notes left by the analysis.
bool operator!=(const ConsumedStateMap *Other) const
Tests to see if there is a mismatch in the states stored in two maps.
Encodes a location in the source.
virtual void warnParamTypestateMismatch(SourceLocation LOC, StringRef ExpectedState, StringRef ObservedState)
virtual void warnReturnTypestateMismatch(SourceLocation Loc, StringRef ExpectedState, StringRef ObservedState)
Warn about return typestate mismatches.
ConsumedAnalyzer(ConsumedWarningsHandlerBase &WarningsHandler)
SmallVector< PartialDiagnosticAt, 1 > OptionalNotes
A class that handles the analysis of uniqueness violations.
ConsumedBlockInfo(unsigned int NumBlocks, PostOrderCFGView *SortedGraph)
ConsumedWarningsHandlerBase & WarningsHandler
std::list< DelayedDiag > DiagList
std::vector< const CFGBlock * >::reverse_iterator iterator
ConsumedStateMap * borrowInfo(const CFGBlock *Block)
ConsumedStateMap(const ConsumedStateMap &Other)
virtual ~ConsumedWarningsHandlerBase()
void setSource(const Stmt *Source)
Set the source for a decision about the branching of states.
void discardInfo(const CFGBlock *Block)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Defines the clang::SourceLocation class and associated facilities.
bool isBackEdgeTarget(const CFGBlock *Block)
virtual void warnUseOfTempInInvalidState(StringRef MethodName, StringRef State, SourceLocation Loc)
Warn about use-while-consumed errors.
ConsumedState getExpectedReturnState() const
void intersect(const ConsumedStateMap &Other)
Merge this state map with another map.