summaryrefslogtreecommitdiff
path: root/include/clang/Analysis/Analyses/Consumed.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang/Analysis/Analyses/Consumed.h')
-rw-r--r--include/clang/Analysis/Analyses/Consumed.h109
1 files changed, 59 insertions, 50 deletions
diff --git a/include/clang/Analysis/Analyses/Consumed.h b/include/clang/Analysis/Analyses/Consumed.h
index 5ba42b475c830..6003d665fd88b 100644
--- a/include/clang/Analysis/Analyses/Consumed.h
+++ b/include/clang/Analysis/Analyses/Consumed.h
@@ -1,4 +1,4 @@
-//===- Consumed.h ----------------------------------------------*- C++ --*-===//
+//===- Consumed.h -----------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -15,16 +15,32 @@
#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_CONSUMED_H
#define LLVM_CLANG_ANALYSIS_ANALYSES_CONSUMED_H
-#include "clang/AST/DeclCXX.h"
-#include "clang/AST/ExprCXX.h"
-#include "clang/AST/StmtCXX.h"
#include "clang/Analysis/Analyses/PostOrderCFGView.h"
-#include "clang/Analysis/AnalysisDeclContext.h"
+#include "clang/Analysis/CFG.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include <list>
+#include <memory>
+#include <utility>
+#include <vector>
namespace clang {
+
+class AnalysisDeclContext;
+class CXXBindTemporaryExpr;
+class FunctionDecl;
+class PostOrderCFGView;
+class Stmt;
+class VarDecl;
+
namespace consumed {
+ class ConsumedStmtVisitor;
+
enum ConsumedState {
// No state information for the given variable.
CS_None,
@@ -34,22 +50,18 @@ namespace consumed {
CS_Consumed
};
- class ConsumedStmtVisitor;
-
- typedef SmallVector<PartialDiagnosticAt, 1> OptionalNotes;
- typedef std::pair<PartialDiagnosticAt, OptionalNotes> DelayedDiag;
- typedef std::list<DelayedDiag> DiagList;
+ using OptionalNotes = SmallVector<PartialDiagnosticAt, 1>;
+ using DelayedDiag = std::pair<PartialDiagnosticAt, OptionalNotes>;
+ using DiagList = std::list<DelayedDiag>;
class ConsumedWarningsHandlerBase {
-
public:
-
virtual ~ConsumedWarningsHandlerBase();
- /// \brief Emit the warnings and notes left by the analysis.
+ /// Emit the warnings and notes left by the analysis.
virtual void emitDiagnostics() {}
- /// \brief Warn that a variable's state doesn't match at the entry and exit
+ /// Warn that a variable's state doesn't match at the entry and exit
/// of a loop.
///
/// \param Loc -- The location of the end of the loop.
@@ -59,7 +71,7 @@ namespace consumed {
virtual void warnLoopStateMismatch(SourceLocation Loc,
StringRef VariableName) {}
- /// \brief Warn about parameter typestate mismatches upon return.
+ /// Warn about parameter typestate mismatches upon return.
///
/// \param Loc -- The SourceLocation of the return statement.
///
@@ -80,7 +92,7 @@ namespace consumed {
// FIXME: This can be removed when the attr propagation fix for templated
// classes lands.
- /// \brief Warn about return typestates set for unconsumable types.
+ /// Warn about return typestates set for unconsumable types.
///
/// \param Loc -- The location of the attributes.
///
@@ -88,7 +100,7 @@ namespace consumed {
virtual void warnReturnTypestateForUnconsumableType(SourceLocation Loc,
StringRef TypeName) {}
- /// \brief Warn about return typestate mismatches.
+ /// Warn about return typestate mismatches.
///
/// \param Loc -- The SourceLocation of the return statement.
///
@@ -101,7 +113,7 @@ namespace consumed {
StringRef ExpectedState,
StringRef ObservedState) {}
- /// \brief Warn about use-while-consumed errors.
+ /// Warn about use-while-consumed errors.
/// \param MethodName -- The name of the method that was incorrectly
/// invoked.
///
@@ -112,7 +124,7 @@ namespace consumed {
StringRef State,
SourceLocation Loc) {}
- /// \brief Warn about use-while-consumed errors.
+ /// Warn about use-while-consumed errors.
/// \param MethodName -- The name of the method that was incorrectly
/// invoked.
///
@@ -129,66 +141,64 @@ namespace consumed {
};
class ConsumedStateMap {
-
- typedef llvm::DenseMap<const VarDecl *, ConsumedState> VarMapType;
- typedef llvm::DenseMap<const CXXBindTemporaryExpr *, ConsumedState>
- TmpMapType;
+ using VarMapType = llvm::DenseMap<const VarDecl *, ConsumedState>;
+ using TmpMapType =
+ llvm::DenseMap<const CXXBindTemporaryExpr *, ConsumedState>;
protected:
-
- bool Reachable;
- const Stmt *From;
+ bool Reachable = true;
+ const Stmt *From = nullptr;
VarMapType VarMap;
TmpMapType TmpMap;
public:
- ConsumedStateMap() : Reachable(true), From(nullptr) {}
+ ConsumedStateMap() = default;
ConsumedStateMap(const ConsumedStateMap &Other)
- : Reachable(Other.Reachable), From(Other.From), VarMap(Other.VarMap),
- TmpMap() {}
+ : Reachable(Other.Reachable), From(Other.From), VarMap(Other.VarMap),
+ TmpMap() {}
- /// \brief Warn if any of the parameters being tracked are not in the state
+ /// Warn if any of the parameters being tracked are not in the state
/// they were declared to be in upon return from a function.
void checkParamsForReturnTypestate(SourceLocation BlameLoc,
ConsumedWarningsHandlerBase &WarningsHandler) const;
- /// \brief Clear the TmpMap.
+ /// Clear the TmpMap.
void clearTemporaries();
- /// \brief Get the consumed state of a given variable.
+ /// Get the consumed state of a given variable.
ConsumedState getState(const VarDecl *Var) const;
- /// \brief Get the consumed state of a given temporary value.
+ /// Get the consumed state of a given temporary value.
ConsumedState getState(const CXXBindTemporaryExpr *Tmp) const;
- /// \brief Merge this state map with another map.
+ /// Merge this state map with another map.
void intersect(const ConsumedStateMap &Other);
void intersectAtLoopHead(const CFGBlock *LoopHead, const CFGBlock *LoopBack,
const ConsumedStateMap *LoopBackStates,
ConsumedWarningsHandlerBase &WarningsHandler);
- /// \brief Return true if this block is reachable.
+ /// Return true if this block is reachable.
bool isReachable() const { return Reachable; }
- /// \brief Mark the block as unreachable.
+ /// Mark the block as unreachable.
void markUnreachable();
- /// \brief Set the source for a decision about the branching of states.
+ /// Set the source for a decision about the branching of states.
/// \param Source -- The statement that was the origin of a branching
/// decision.
void setSource(const Stmt *Source) { this->From = Source; }
- /// \brief Set the consumed state of a given variable.
+ /// Set the consumed state of a given variable.
void setState(const VarDecl *Var, ConsumedState State);
- /// \brief Set the consumed state of a given temporary value.
+ /// Set the consumed state of a given temporary value.
void setState(const CXXBindTemporaryExpr *Tmp, ConsumedState State);
- /// \brief Remove the temporary value from our state map.
+ /// Remove the temporary value from our state map.
void remove(const CXXBindTemporaryExpr *Tmp);
- /// \brief Tests to see if there is a mismatch in the states stored in two
+ /// Tests to see if there is a mismatch in the states stored in two
/// maps.
///
/// \param Other -- The second map to compare against.
@@ -205,10 +215,8 @@ namespace consumed {
ConsumedBlockInfo(unsigned int NumBlocks, PostOrderCFGView *SortedGraph)
: StateMapsArray(NumBlocks), VisitOrder(NumBlocks, 0) {
unsigned int VisitOrderCounter = 0;
- for (PostOrderCFGView::iterator BI = SortedGraph->begin(),
- BE = SortedGraph->end(); BI != BE; ++BI) {
- VisitOrder[(*BI)->getBlockID()] = VisitOrderCounter++;
- }
+ for (const auto BI : *SortedGraph)
+ VisitOrder[BI->getBlockID()] = VisitOrderCounter++;
}
bool allBackEdgesVisited(const CFGBlock *CurrBlock,
@@ -231,7 +239,6 @@ namespace consumed {
/// A class that handles the analysis of uniqueness violations.
class ConsumedAnalyzer {
-
ConsumedBlockInfo BlockInfo;
std::unique_ptr<ConsumedStateMap> CurrStates;
@@ -243,7 +250,6 @@ namespace consumed {
const ConsumedStmtVisitor &Visitor);
public:
-
ConsumedWarningsHandlerBase &WarningsHandler;
ConsumedAnalyzer(ConsumedWarningsHandlerBase &WarningsHandler)
@@ -251,7 +257,7 @@ namespace consumed {
ConsumedState getExpectedReturnState() const { return ExpectedReturnState; }
- /// \brief Check a function's CFG for consumed violations.
+ /// Check a function's CFG for consumed violations.
///
/// We traverse the blocks in the CFG, keeping track of the state of each
/// value who's type has uniquness annotations. If methods are invoked in
@@ -259,6 +265,9 @@ namespace consumed {
/// exactly once.
void run(AnalysisDeclContext &AC);
};
-}} // end namespace clang::consumed
-#endif
+} // namespace consumed
+
+} // namespace clang
+
+#endif // LLVM_CLANG_ANALYSIS_ANALYSES_CONSUMED_H