14 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_CONSUMED_H 15 #define LLVM_CLANG_ANALYSIS_ANALYSES_CONSUMED_H 22 #include "llvm/ADT/DenseMap.h" 23 #include "llvm/ADT/SmallVector.h" 24 #include "llvm/ADT/StringRef.h" 32 class AnalysisDeclContext;
33 class CXXBindTemporaryExpr;
35 class PostOrderCFGView;
53 using DelayedDiag = std::pair<PartialDiagnosticAt, OptionalNotes>;
71 StringRef VariableName) {}
83 StringRef VariableName,
84 StringRef ExpectedState,
85 StringRef ObservedState) {}
89 StringRef ExpectedState,
90 StringRef ObservedState) {}
100 StringRef TypeName) {}
112 StringRef ExpectedState,
113 StringRef ObservedState) {}
137 StringRef VariableName,
143 using VarMapType = llvm::DenseMap<const VarDecl *, ConsumedState>;
145 llvm::DenseMap<const CXXBindTemporaryExpr *, ConsumedState>;
148 bool Reachable =
true;
156 : Reachable(Other.Reachable), From(Other.From), VarMap(Other.VarMap),
165 void clearTemporaries();
176 void intersectAtLoopHead(
const CFGBlock *LoopHead,
const CFGBlock *LoopBack,
184 void markUnreachable();
208 std::vector<std::unique_ptr<ConsumedStateMap>> StateMapsArray;
209 std::vector<unsigned int> VisitOrder;
215 : StateMapsArray(NumBlocks), VisitOrder(NumBlocks, 0) {
216 unsigned int VisitOrderCounter = 0;
217 for (
const auto BI : *SortedGraph)
218 VisitOrder[BI->getBlockID()] = VisitOrderCounter++;
221 bool allBackEdgesVisited(
const CFGBlock *CurrBlock,
225 std::unique_ptr<ConsumedStateMap> &OwnedStateMap);
227 std::unique_ptr<ConsumedStateMap> StateMap);
231 void discardInfo(
const CFGBlock *Block);
236 bool isBackEdgeTarget(
const CFGBlock *Block);
242 std::unique_ptr<ConsumedStateMap> CurrStates;
248 bool splitState(
const CFGBlock *CurrBlock,
255 : WarningsHandler(WarningsHandler) {}
272 #endif // LLVM_CLANG_ANALYSIS_ANALYSES_CONSUMED_H Represents a function declaration or definition.
virtual void warnReturnTypestateForUnconsumableType(SourceLocation Loc, StringRef TypeName)
Warn about return typestates set for unconsumable types.
Stmt - This represents one statement.
virtual void warnParamReturnTypestateMismatch(SourceLocation Loc, StringRef VariableName, StringRef ExpectedState, StringRef ObservedState)
Warn about parameter typestate mismatches upon return.
virtual void warnUseInInvalidState(StringRef MethodName, StringRef VariableName, StringRef State, SourceLocation Loc)
Warn about use-while-consumed errors.
Represents a variable declaration or definition.
ConsumedState getExpectedReturnState() const
AnalysisDeclContext contains the context data for the function or method under analysis.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
std::list< DelayedDiag > DiagList
Represents binding an expression to a temporary.
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 isReachable() const
Return true if this block is reachable.
std::pair< PartialDiagnosticAt, OptionalNotes > DelayedDiag
virtual void emitDiagnostics()
Emit the warnings and notes left by the analysis.
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)
Dataflow Directional Tag Classes.
A class that handles the analysis of uniqueness violations.
ConsumedBlockInfo(unsigned int NumBlocks, PostOrderCFGView *SortedGraph)
ConsumedWarningsHandlerBase & WarningsHandler
static const TypeInfo & getInfo(unsigned id)
ConsumedStateMap(const ConsumedStateMap &Other)
virtual ~ConsumedWarningsHandlerBase()
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream...
void setSource(const Stmt *Source)
Set the source for a decision about the branching of states.
Defines the clang::SourceLocation class and associated facilities.
bool operator!=(CanQual< T > x, CanQual< U > y)
virtual void warnUseOfTempInInvalidState(StringRef MethodName, StringRef State, SourceLocation Loc)
Warn about use-while-consumed errors.