15 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_CONSUMED_H 16 #define LLVM_CLANG_ANALYSIS_ANALYSES_CONSUMED_H 23 #include "llvm/ADT/DenseMap.h" 24 #include "llvm/ADT/SmallVector.h" 25 #include "llvm/ADT/StringRef.h" 33 class AnalysisDeclContext;
34 class CXXBindTemporaryExpr;
36 class PostOrderCFGView;
54 using DelayedDiag = std::pair<PartialDiagnosticAt, OptionalNotes>;
72 StringRef VariableName) {}
84 StringRef VariableName,
85 StringRef ExpectedState,
86 StringRef ObservedState) {}
90 StringRef ExpectedState,
91 StringRef ObservedState) {}
101 StringRef TypeName) {}
113 StringRef ExpectedState,
114 StringRef ObservedState) {}
138 StringRef VariableName,
144 using VarMapType = llvm::DenseMap<const VarDecl *, ConsumedState>;
146 llvm::DenseMap<const CXXBindTemporaryExpr *, ConsumedState>;
149 bool Reachable =
true;
157 : Reachable(Other.Reachable), From(Other.From), VarMap(Other.VarMap),
166 void clearTemporaries();
177 void intersectAtLoopHead(
const CFGBlock *LoopHead,
const CFGBlock *LoopBack,
185 void markUnreachable();
209 std::vector<std::unique_ptr<ConsumedStateMap>> StateMapsArray;
210 std::vector<unsigned int> VisitOrder;
216 : StateMapsArray(NumBlocks), VisitOrder(NumBlocks, 0) {
217 unsigned int VisitOrderCounter = 0;
218 for (
const auto BI : *SortedGraph)
219 VisitOrder[BI->getBlockID()] = VisitOrderCounter++;
222 bool allBackEdgesVisited(
const CFGBlock *CurrBlock,
226 std::unique_ptr<ConsumedStateMap> &OwnedStateMap);
228 std::unique_ptr<ConsumedStateMap> StateMap);
232 void discardInfo(
const CFGBlock *Block);
237 bool isBackEdgeTarget(
const CFGBlock *Block);
243 std::unique_ptr<ConsumedStateMap> CurrStates;
249 bool splitState(
const CFGBlock *CurrBlock,
256 : WarningsHandler(WarningsHandler) {}
273 #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.