diff options
Diffstat (limited to 'include')
6 files changed, 102 insertions, 56 deletions
diff --git a/include/clang/Analysis/ProgramPoint.h b/include/clang/Analysis/ProgramPoint.h index 07b4dea987..0e6a659e39 100644 --- a/include/clang/Analysis/ProgramPoint.h +++ b/include/clang/Analysis/ProgramPoint.h @@ -21,15 +21,18 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/Support/Casting.h" +#include "llvm/ADT/StringRef.h" #include <cassert> #include <utility> +#include <string> namespace clang { -class LocationContext; class AnalysisContext; class FunctionDecl; - +class LocationContext; +class ProgramPointTag; + class ProgramPoint { public: enum Kind { BlockEdgeKind, @@ -58,15 +61,17 @@ private: // The LocationContext could be NULL to allow ProgramPoint to be used in // context insensitive analysis. const LocationContext *L; - const void *Tag; + const ProgramPointTag *Tag; + ProgramPoint(); + protected: ProgramPoint(const void* P, Kind k, const LocationContext *l, - const void *tag = 0) + const ProgramPointTag *tag = 0) : Data(P, static_cast<const void*>(NULL)), K(k), L(l), Tag(tag) {} ProgramPoint(const void* P1, const void* P2, Kind k, const LocationContext *l, - const void *tag = 0) + const ProgramPointTag *tag = 0) : Data(P1, P2), K(k), L(l), Tag(tag) {} protected: @@ -76,7 +81,7 @@ protected: public: Kind getKind() const { return K; } - const void *getTag() const { return Tag; } + const ProgramPointTag *getTag() const { return Tag; } const LocationContext *getLocationContext() const { return L; } @@ -109,7 +114,7 @@ public: class BlockEntrance : public ProgramPoint { public: BlockEntrance(const CFGBlock* B, const LocationContext *L, - const void *tag = 0) + const ProgramPointTag *tag = 0) : ProgramPoint(B, BlockEntranceKind, L, tag) {} const CFGBlock* getBlock() const { @@ -123,7 +128,7 @@ public: /// Create a new BlockEntrance object that is the same as the original /// except for using the specified tag value. - BlockEntrance withTag(const void *tag) { + BlockEntrance withTag(const ProgramPointTag *tag) { return BlockEntrance(getBlock(), getLocationContext(), tag); } @@ -153,7 +158,7 @@ public: class StmtPoint : public ProgramPoint { public: StmtPoint(const Stmt *S, const void *p2, Kind k, const LocationContext *L, - const void *tag) + const ProgramPointTag *tag) : ProgramPoint(S, p2, k, L, tag) {} const Stmt *getStmt() const { return (const Stmt*) getData1(); } @@ -170,7 +175,7 @@ public: class PreStmt : public StmtPoint { public: - PreStmt(const Stmt *S, const LocationContext *L, const void *tag, + PreStmt(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag, const Stmt *SubStmt = 0) : StmtPoint(S, SubStmt, PreStmtKind, L, tag) {} @@ -184,15 +189,16 @@ public: class PostStmt : public StmtPoint { protected: PostStmt(const Stmt* S, const void* data, Kind k, const LocationContext *L, - const void *tag =0) + const ProgramPointTag *tag =0) : StmtPoint(S, data, k, L, tag) {} public: explicit PostStmt(const Stmt* S, Kind k, - const LocationContext *L, const void *tag = 0) + const LocationContext *L, const ProgramPointTag *tag = 0) : StmtPoint(S, NULL, k, L, tag) {} - explicit PostStmt(const Stmt* S, const LocationContext *L,const void *tag = 0) + explicit PostStmt(const Stmt* S, const LocationContext *L, + const ProgramPointTag *tag = 0) : StmtPoint(S, NULL, PostStmtKind, L, tag) {} static bool classof(const ProgramPoint* Location) { @@ -225,7 +231,8 @@ public: // PostCondition represents the post program point of a branch condition. class PostCondition : public PostStmt { public: - PostCondition(const Stmt* S, const LocationContext *L, const void *tag = 0) + PostCondition(const Stmt* S, const LocationContext *L, + const ProgramPointTag *tag = 0) : PostStmt(S, PostConditionKind, L, tag) {} static bool classof(const ProgramPoint* Location) { @@ -236,7 +243,7 @@ public: class LocationCheck : public StmtPoint { protected: LocationCheck(const Stmt *S, const LocationContext *L, - ProgramPoint::Kind K, const void *tag) + ProgramPoint::Kind K, const ProgramPointTag *tag) : StmtPoint(S, NULL, K, L, tag) {} static bool classof(const ProgramPoint *location) { @@ -247,7 +254,8 @@ protected: class PreLoad : public LocationCheck { public: - PreLoad(const Stmt *S, const LocationContext *L, const void *tag = 0) + PreLoad(const Stmt *S, const LocationContext *L, + const ProgramPointTag *tag = 0) : LocationCheck(S, L, PreLoadKind, tag) {} static bool classof(const ProgramPoint *location) { @@ -257,7 +265,8 @@ public: class PreStore : public LocationCheck { public: - PreStore(const Stmt *S, const LocationContext *L, const void *tag = 0) + PreStore(const Stmt *S, const LocationContext *L, + const ProgramPointTag *tag = 0) : LocationCheck(S, L, PreStoreKind, tag) {} static bool classof(const ProgramPoint *location) { @@ -267,7 +276,8 @@ public: class PostLoad : public PostStmt { public: - PostLoad(const Stmt* S, const LocationContext *L, const void *tag = 0) + PostLoad(const Stmt* S, const LocationContext *L, + const ProgramPointTag *tag = 0) : PostStmt(S, PostLoadKind, L, tag) {} static bool classof(const ProgramPoint* Location) { @@ -277,7 +287,8 @@ public: class PostStore : public PostStmt { public: - PostStore(const Stmt* S, const LocationContext *L, const void *tag = 0) + PostStore(const Stmt* S, const LocationContext *L, + const ProgramPointTag *tag = 0) : PostStmt(S, PostStoreKind, L, tag) {} static bool classof(const ProgramPoint* Location) { @@ -287,7 +298,8 @@ public: class PostLValue : public PostStmt { public: - PostLValue(const Stmt* S, const LocationContext *L, const void *tag = 0) + PostLValue(const Stmt* S, const LocationContext *L, + const ProgramPointTag *tag = 0) : PostStmt(S, PostLValueKind, L, tag) {} static bool classof(const ProgramPoint* Location) { @@ -298,7 +310,7 @@ public: class PostPurgeDeadSymbols : public PostStmt { public: PostPurgeDeadSymbols(const Stmt* S, const LocationContext *L, - const void *tag = 0) + const ProgramPointTag *tag = 0) : PostStmt(S, PostPurgeDeadSymbolsKind, L, tag) {} static bool classof(const ProgramPoint* Location) { @@ -365,6 +377,28 @@ public: } }; +/// ProgramPoints can be "tagged" as representing points specific to a given +/// analysis entity. Tags are abstract annotations, with an associated +/// description and potentially other information. +class ProgramPointTag { +public: + ProgramPointTag(void *tagKind = 0) : TagKind(tagKind) {} + virtual ~ProgramPointTag(); + virtual StringRef getTagDescription() const = 0; + +protected: + const void *getTagKind() { return TagKind; } + +private: + const void *TagKind; +}; + +class SimpleProgramPointTag : public ProgramPointTag { + std::string desc; +public: + SimpleProgramPointTag(StringRef description); + StringRef getTagDescription() const; +}; } // end namespace clang diff --git a/include/clang/StaticAnalyzer/Core/Checker.h b/include/clang/StaticAnalyzer/Core/Checker.h index eb38bd8951..26476454a6 100644 --- a/include/clang/StaticAnalyzer/Core/Checker.h +++ b/include/clang/StaticAnalyzer/Core/Checker.h @@ -14,6 +14,7 @@ #ifndef LLVM_CLANG_SA_CORE_CHECKER #define LLVM_CLANG_SA_CORE_CHECKER +#include "clang/Analysis/ProgramPoint.h" #include "clang/StaticAnalyzer/Core/CheckerManager.h" #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" #include "llvm/Support/Casting.h" @@ -329,6 +330,11 @@ public: } // end eval namespace +class CheckerBase : public ProgramPointTag { +public: + StringRef getTagDescription() const; +}; + template <typename CHECK1, typename CHECK2=check::_VoidCheck, typename CHECK3=check::_VoidCheck, typename CHECK4=check::_VoidCheck, typename CHECK5=check::_VoidCheck, typename CHECK6=check::_VoidCheck, @@ -341,7 +347,9 @@ template <> class Checker<check::_VoidCheck, check::_VoidCheck, check::_VoidCheck, check::_VoidCheck, check::_VoidCheck, check::_VoidCheck, check::_VoidCheck, check::_VoidCheck, check::_VoidCheck, - check::_VoidCheck, check::_VoidCheck, check::_VoidCheck> { + check::_VoidCheck, check::_VoidCheck, check::_VoidCheck> + : public CheckerBase +{ public: static void _register(void *checker, CheckerManager &mgr) { } }; diff --git a/include/clang/StaticAnalyzer/Core/CheckerManager.h b/include/clang/StaticAnalyzer/Core/CheckerManager.h index c275c19b40..42e6bd1b18 100644 --- a/include/clang/StaticAnalyzer/Core/CheckerManager.h +++ b/include/clang/StaticAnalyzer/Core/CheckerManager.h @@ -27,6 +27,7 @@ namespace clang { class CallExpr; namespace ento { + class CheckerBase; class ExprEngine; class AnalysisManager; class BugReporter; @@ -55,8 +56,8 @@ class CheckerFn<RET(P1, P2, P3, P4)> { typedef RET (*Func)(void *, P1, P2, P3, P4); Func Fn; public: - void *Checker; - CheckerFn(void *checker, Func fn) : Fn(fn), Checker(checker) { } + CheckerBase *Checker; + CheckerFn(CheckerBase *checker, Func fn) : Fn(fn), Checker(checker) { } RET operator()(P1 p1, P2 p2, P3 p3, P4 p4) const { return Fn(Checker, p1, p2, p3, p4); } @@ -67,8 +68,8 @@ class CheckerFn<RET(P1, P2, P3)> { typedef RET (*Func)(void *, P1, P2, P3); Func Fn; public: - void *Checker; - CheckerFn(void *checker, Func fn) : Fn(fn), Checker(checker) { } + CheckerBase *Checker; + CheckerFn(CheckerBase *checker, Func fn) : Fn(fn), Checker(checker) { } RET operator()(P1 p1, P2 p2, P3 p3) const { return Fn(Checker, p1, p2, p3); } }; @@ -77,8 +78,8 @@ class CheckerFn<RET(P1, P2)> { typedef RET (*Func)(void *, P1, P2); Func Fn; public: - void *Checker; - CheckerFn(void *checker, Func fn) : Fn(fn), Checker(checker) { } + CheckerBase *Checker; + CheckerFn(CheckerBase *checker, Func fn) : Fn(fn), Checker(checker) { } RET operator()(P1 p1, P2 p2) const { return Fn(Checker, p1, p2); } }; @@ -87,8 +88,8 @@ class CheckerFn<RET(P1)> { typedef RET (*Func)(void *, P1); Func Fn; public: - void *Checker; - CheckerFn(void *checker, Func fn) : Fn(fn), Checker(checker) { } + CheckerBase *Checker; + CheckerFn(CheckerBase *checker, Func fn) : Fn(fn), Checker(checker) { } RET operator()(P1 p1) const { return Fn(Checker, p1); } }; @@ -97,8 +98,8 @@ class CheckerFn<RET()> { typedef RET (*Func)(void *); Func Fn; public: - void *Checker; - CheckerFn(void *checker, Func fn) : Fn(fn), Checker(checker) { } + CheckerBase *Checker; + CheckerFn(CheckerBase *checker, Func fn) : Fn(fn), Checker(checker) { } RET operator()() const { return Fn(Checker); } }; @@ -115,8 +116,8 @@ public: const LangOptions &getLangOptions() const { return LangOpts; } - typedef void *CheckerRef; - typedef void *CheckerTag; + typedef CheckerBase *CheckerRef; + typedef const void *CheckerTag; typedef CheckerFn<void ()> CheckerDtor; //===----------------------------------------------------------------------===// diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h b/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h index 62887cd2e2..4b3df1262e 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h @@ -28,7 +28,7 @@ class CheckerContext { ExprEngine &Eng; ExplodedNode *Pred; SaveAndRestore<bool> OldSink; - const void *checkerTag; + const ProgramPointTag *checkerTag; SaveAndRestore<ProgramPoint::Kind> OldPointKind; SaveOr OldHasGen; const GRState *ST; @@ -39,7 +39,7 @@ public: public: CheckerContext(ExplodedNodeSet &dst, StmtNodeBuilder &builder, ExprEngine &eng, ExplodedNode *pred, - const void *tag, ProgramPoint::Kind K, + const ProgramPointTag *tag, ProgramPoint::Kind K, bool *respondsToCB = 0, const Stmt *stmt = 0, const GRState *st = 0) : Dst(dst), B(builder), Eng(eng), Pred(pred), @@ -104,7 +104,7 @@ public: } ExplodedNode *generateNode(const Stmt *stmt, const GRState *state, - bool autoTransition = true, const void *tag = 0) { + bool autoTransition = true, const ProgramPointTag *tag = 0) { assert(state); ExplodedNode *N = generateNodeImpl(stmt, state, false, tag ? tag : checkerTag); @@ -123,7 +123,7 @@ public: } ExplodedNode *generateNode(const GRState *state, bool autoTransition = true, - const void *tag = 0) { + const ProgramPointTag *tag = 0) { assert(statement && "Only transitions with statements currently supported"); ExplodedNode *N = generateNodeImpl(statement, state, false, tag ? tag : checkerTag); @@ -147,7 +147,7 @@ public: Dst.Add(node); } - void addTransition(const GRState *state, const void *tag = 0) { + void addTransition(const GRState *state, const ProgramPointTag *tag = 0) { assert(state); // If the 'state' is not new, we need to check if the cached state 'ST' // is new. @@ -168,7 +168,7 @@ public: private: ExplodedNode *generateNodeImpl(const Stmt* stmt, const GRState *state, - bool markAsSink, const void *tag) { + bool markAsSink, const ProgramPointTag *tag) { ExplodedNode *node = B.generateNode(stmt, state, Pred, tag); if (markAsSink && node) node->markAsSink(); diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h b/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h index 19daeda6b5..31e862fdd0 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h @@ -24,6 +24,8 @@ namespace clang { +class ProgramPointTag; + namespace ento { //===----------------------------------------------------------------------===// @@ -170,7 +172,7 @@ public: bool BuildSinks; bool hasGeneratedNode; ProgramPoint::Kind PointKind; - const void *Tag; + const ProgramPointTag *Tag; typedef llvm::SmallPtrSet<ExplodedNode*,5> DeferredTy; DeferredTy Deferred; @@ -203,7 +205,7 @@ public: ExplodedNode* generateNode(const Stmt *S, const GRState *St, ExplodedNode *Pred, ProgramPoint::Kind K, - const void *tag = 0) { + const ProgramPointTag *tag = 0) { hasGeneratedNode = true; if (PurgingDeadSymbols) @@ -213,7 +215,8 @@ public: } ExplodedNode* generateNode(const Stmt *S, const GRState *St, - ExplodedNode *Pred, const void *tag = 0) { + ExplodedNode *Pred, + const ProgramPointTag *tag = 0) { return generateNode(S, St, Pred, PointKind, tag); } @@ -230,7 +233,7 @@ public: ExplodedNode* generateNodeInternal(const Stmt* S, const GRState* State, ExplodedNode* Pred, ProgramPoint::Kind K = ProgramPoint::PostStmtKind, - const void *tag = 0); + const ProgramPointTag *tag = 0); /// getStmt - Return the current block-level expression associated with /// this builder. @@ -367,7 +370,7 @@ class SwitchNodeBuilder { public: SwitchNodeBuilder(ExplodedNode* pred, const CFGBlock* src, - const Expr* condition, CoreEngine* eng) + const Expr* condition, CoreEngine* eng) : Eng(*eng), Src(src), Condition(condition), Pred(pred) {} class iterator { @@ -443,7 +446,7 @@ public: : GenericNodeBuilderImpl(eng, pr, p) {} ExplodedNode *generateNode(const GRState *state, ExplodedNode *pred, - const void *tag, bool asSink) { + const ProgramPointTag *tag, bool asSink) { return generateNodeImpl(state, pred, cast<PP_T>(pp).withTag(tag), asSink); } @@ -455,19 +458,19 @@ class EndOfFunctionNodeBuilder { CoreEngine &Eng; const CFGBlock& B; ExplodedNode* Pred; - void *Tag; + const ProgramPointTag *Tag; public: bool hasGeneratedNode; public: EndOfFunctionNodeBuilder(const CFGBlock* b, ExplodedNode* N, CoreEngine* e, - void *checkerTag = 0) - : Eng(*e), B(*b), Pred(N), Tag(checkerTag), hasGeneratedNode(false) {} + const ProgramPointTag *tag = 0) + : Eng(*e), B(*b), Pred(N), Tag(tag), hasGeneratedNode(false) {} ~EndOfFunctionNodeBuilder(); - EndOfFunctionNodeBuilder withCheckerTag(void *tag) { + EndOfFunctionNodeBuilder withCheckerTag(const ProgramPointTag *tag) { return EndOfFunctionNodeBuilder(&B, Pred, &Eng, tag); } @@ -486,7 +489,7 @@ public: } ExplodedNode* generateNode(const GRState* State, ExplodedNode *P = 0, - const void *tag = 0); + const ProgramPointTag *tag = 0); void GenerateCallExitNode(const GRState *state); diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h b/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h index ee89f314d9..5649f71b86 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h @@ -226,7 +226,7 @@ public: ExplodedNode* MakeNode(ExplodedNodeSet& Dst, const Stmt* S, ExplodedNode* Pred, const GRState* St, ProgramPoint::Kind K = ProgramPoint::PostStmtKind, - const void *tag = 0); + const ProgramPointTag *tag = 0); /// Visit - Transfer function logic for all statements. Dispatches to /// other functions that handle specific kinds of statements. @@ -430,24 +430,24 @@ public: // same as state->getLValue(Ex). /// Simulate a read of the result of Ex. void evalLoad(ExplodedNodeSet& Dst, const Expr* Ex, ExplodedNode* Pred, - const GRState* St, SVal location, const void *tag = 0, + const GRState* St, SVal location, const ProgramPointTag *tag = 0, QualType LoadTy = QualType()); // FIXME: 'tag' should be removed, and a LocationContext should be used // instead. void evalStore(ExplodedNodeSet& Dst, const Expr* AssignE, const Expr* StoreE, ExplodedNode* Pred, const GRState* St, SVal TargetLV, SVal Val, - const void *tag = 0); + const ProgramPointTag *tag = 0); private: void evalLoadCommon(ExplodedNodeSet& Dst, const Expr* Ex, ExplodedNode* Pred, - const GRState* St, SVal location, const void *tag, + const GRState* St, SVal location, const ProgramPointTag *tag, QualType LoadTy); // FIXME: 'tag' should be removed, and a LocationContext should be used // instead. void evalLocation(ExplodedNodeSet &Dst, const Stmt *S, ExplodedNode* Pred, const GRState* St, SVal location, - const void *tag, bool isLoad); + const ProgramPointTag *tag, bool isLoad); bool InlineCall(ExplodedNodeSet &Dst, const CallExpr *CE, ExplodedNode *Pred); |