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<ConsumedStateMap*> StateMapsArray;
200 std::vector<unsigned int> VisitOrder;
207 : StateMapsArray(NumBlocks, nullptr), VisitOrder(NumBlocks, 0) {
208 unsigned int VisitOrderCounter = 0;
210 BE = SortedGraph->
end(); BI != BE; ++BI) {
211 VisitOrder[(*BI)->getBlockID()] = VisitOrderCounter++;
243 bool splitState(
const CFGBlock *CurrBlock,
251 : WarningsHandler(WarningsHandler) {}
virtual void warnReturnTypestateForUnconsumableType(SourceLocation Loc, StringRef TypeName)
Warn about return typestates set for unconsumable types.
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.
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
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)
Represents binding an expression to a temporary.
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.
ConsumedStateMap * getInfo(const CFGBlock *Block)
bool operator!=(const ConsumedStateMap *Other) const
Tests to see if there is a mismatch in the states stored in two maps.
void intersect(const ConsumedStateMap *Other)
Merge this state map with another map.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
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)
void addInfo(const CFGBlock *Block, ConsumedStateMap *StateMap, bool &AlreadyOwned)
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.
Represents a C++ struct/union/class.
bool isBackEdgeTarget(const CFGBlock *Block)
virtual void warnUseOfTempInInvalidState(StringRef MethodName, StringRef State, SourceLocation Loc)
Warn about use-while-consumed errors.
ConsumedState getExpectedReturnState() const