diff options
author | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-08-15 03:17:38 +0000 |
---|---|---|
committer | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-08-15 03:17:38 +0000 |
commit | 25e695b2d574d919cc1bbddf3a2efe073d449b1c (patch) | |
tree | 69abacb15f2f0f6dcce7cc73047b6a07879f944f /include/clang/Analysis/ProgramPoint.h | |
parent | bbed6b964414145b29e7b60b3e538093734ea3f8 (diff) |
Extend the ProgramPoint to include the context information LocationContext,
which is either a stack frame context of the function or a local scope
context.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79072 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Analysis/ProgramPoint.h')
-rw-r--r-- | include/clang/Analysis/ProgramPoint.h | 106 |
1 files changed, 64 insertions, 42 deletions
diff --git a/include/clang/Analysis/ProgramPoint.h b/include/clang/Analysis/ProgramPoint.h index 8951e83a7c..cddcefa4e9 100644 --- a/include/clang/Analysis/ProgramPoint.h +++ b/include/clang/Analysis/ProgramPoint.h @@ -24,6 +24,8 @@ #include <utility> namespace clang { + +class LocationContext; class ProgramPoint { public: @@ -48,14 +50,20 @@ public: private: std::pair<const void *, const void *> Data; Kind K; + + // The LocationContext could be NULL to allow ProgramPoint to be used in + // context insensitive analysis. + const LocationContext *L; const void *Tag; protected: - ProgramPoint(const void* P, Kind k, const void *tag = 0) - : Data(P, NULL), K(k), Tag(tag) {} + ProgramPoint(const void* P, Kind k, const LocationContext *l, + const void *tag = 0) + : Data(P, NULL), K(k), L(l), Tag(tag) {} - ProgramPoint(const void* P1, const void* P2, Kind k, const void *tag = 0) - : Data(P1, P2), K(k), Tag(tag) {} + ProgramPoint(const void* P1, const void* P2, Kind k, const LocationContext *l, + const void *tag = 0) + : Data(P1, P2), K(k), L(l), Tag(tag) {} protected: const void* getData1() const { return Data.first; } @@ -65,6 +73,8 @@ protected: public: Kind getKind() const { return K; } + const LocationContext *getContext() const { return L; } + // For use with DenseMap. This hash is probably slow. unsigned getHashValue() const { llvm::FoldingSetNodeID ID; @@ -75,25 +85,27 @@ public: static bool classof(const ProgramPoint*) { return true; } bool operator==(const ProgramPoint & RHS) const { - return K == RHS.K && Data == RHS.Data && Tag == RHS.Tag; + return K == RHS.K && Data == RHS.Data && L == RHS.L && Tag == RHS.Tag; } bool operator!=(const ProgramPoint& RHS) const { - return K != RHS.K || Data != RHS.Data || Tag != RHS.Tag; + return K != RHS.K || Data != RHS.Data || L != RHS.L || Tag != RHS.Tag; } void Profile(llvm::FoldingSetNodeID& ID) const { ID.AddInteger((unsigned) K); ID.AddPointer(Data.first); ID.AddPointer(Data.second); + ID.AddPointer(L); ID.AddPointer(Tag); } }; class BlockEntrance : public ProgramPoint { public: - BlockEntrance(const CFGBlock* B, const void *tag = 0) - : ProgramPoint(B, BlockEntranceKind, tag) {} + BlockEntrance(const CFGBlock* B, const LocationContext *L, + const void *tag = 0) + : ProgramPoint(B, BlockEntranceKind, L, tag) {} CFGBlock* getBlock() const { return const_cast<CFGBlock*>(reinterpret_cast<const CFGBlock*>(getData1())); @@ -111,7 +123,8 @@ public: class BlockExit : public ProgramPoint { public: - BlockExit(const CFGBlock* B) : ProgramPoint(B, BlockExitKind) {} + BlockExit(const CFGBlock* B, const LocationContext *L) + : ProgramPoint(B, BlockExitKind, L) {} CFGBlock* getBlock() const { return const_cast<CFGBlock*>(reinterpret_cast<const CFGBlock*>(getData1())); @@ -133,8 +146,9 @@ public: class StmtPoint : public ProgramPoint { public: - StmtPoint(const Stmt *S, const void *p2, Kind k, const void *tag) - : ProgramPoint(S, p2, k, tag) {} + StmtPoint(const Stmt *S, const void *p2, Kind k, const LocationContext *L, + const void *tag) + : ProgramPoint(S, p2, k, L, tag) {} const Stmt *getStmt() const { return (const Stmt*) getData1(); } @@ -150,8 +164,9 @@ public: class PreStmt : public StmtPoint { public: - PreStmt(const Stmt *S, const void *tag, const Stmt *SubStmt = 0) - : StmtPoint(S, SubStmt, PreStmtKind, tag) {} + PreStmt(const Stmt *S, const LocationContext *L, const void *tag, + const Stmt *SubStmt = 0) + : StmtPoint(S, SubStmt, PreStmtKind, L, tag) {} const Stmt *getSubStmt() const { return (const Stmt*) getData2(); } @@ -162,15 +177,16 @@ public: class PostStmt : public StmtPoint { protected: - PostStmt(const Stmt* S, Kind k, const void *tag = 0) - : StmtPoint(S, NULL, k, tag) {} + PostStmt(const Stmt* S, Kind k, const LocationContext *L, const void *tag = 0) + : StmtPoint(S, NULL, k, L, tag) {} - PostStmt(const Stmt* S, const void* data, Kind k, const void *tag =0) - : StmtPoint(S, data, k, tag) {} + PostStmt(const Stmt* S, const void* data, Kind k, const LocationContext *L, + const void *tag =0) + : StmtPoint(S, data, k, L, tag) {} public: - explicit PostStmt(const Stmt* S, const void *tag = 0) - : StmtPoint(S, NULL, PostStmtKind, tag) {} + explicit PostStmt(const Stmt* S, const LocationContext *L,const void *tag = 0) + : StmtPoint(S, NULL, PostStmtKind, L, tag) {} static bool classof(const ProgramPoint* Location) { unsigned k = Location->getKind(); @@ -180,8 +196,9 @@ public: class PostLocationChecksSucceed : public PostStmt { public: - PostLocationChecksSucceed(const Stmt* S, const void *tag = 0) - : PostStmt(S, PostLocationChecksSucceedKind, tag) {} + PostLocationChecksSucceed(const Stmt* S, const LocationContext *L, + const void *tag = 0) + : PostStmt(S, PostLocationChecksSucceedKind, L, tag) {} static bool classof(const ProgramPoint* Location) { return Location->getKind() == PostLocationChecksSucceedKind; @@ -191,8 +208,9 @@ public: class PostStmtCustom : public PostStmt { public: PostStmtCustom(const Stmt* S, - const std::pair<const void*, const void*>* TaggedData) - : PostStmt(S, TaggedData, PostStmtCustomKind) {} + const std::pair<const void*, const void*>* TaggedData,\ + const LocationContext *L) + : PostStmt(S, TaggedData, PostStmtCustomKind, L) {} const std::pair<const void*, const void*>& getTaggedPair() const { return @@ -210,8 +228,9 @@ public: class PostOutOfBoundsCheckFailed : public PostStmt { public: - PostOutOfBoundsCheckFailed(const Stmt* S, const void *tag = 0) - : PostStmt(S, PostOutOfBoundsCheckFailedKind, tag) {} + PostOutOfBoundsCheckFailed(const Stmt* S, const LocationContext *L, + const void *tag = 0) + : PostStmt(S, PostOutOfBoundsCheckFailedKind, L, tag) {} static bool classof(const ProgramPoint* Location) { return Location->getKind() == PostOutOfBoundsCheckFailedKind; @@ -220,8 +239,9 @@ public: class PostUndefLocationCheckFailed : public PostStmt { public: - PostUndefLocationCheckFailed(const Stmt* S, const void *tag = 0) - : PostStmt(S, PostUndefLocationCheckFailedKind, tag) {} + PostUndefLocationCheckFailed(const Stmt* S, const LocationContext *L, + const void *tag = 0) + : PostStmt(S, PostUndefLocationCheckFailedKind, L, tag) {} static bool classof(const ProgramPoint* Location) { return Location->getKind() == PostUndefLocationCheckFailedKind; @@ -230,8 +250,9 @@ public: class PostNullCheckFailed : public PostStmt { public: - PostNullCheckFailed(const Stmt* S, const void *tag = 0) - : PostStmt(S, PostNullCheckFailedKind, tag) {} + PostNullCheckFailed(const Stmt* S, const LocationContext *L, + const void *tag = 0) + : PostStmt(S, PostNullCheckFailedKind, L, tag) {} static bool classof(const ProgramPoint* Location) { return Location->getKind() == PostNullCheckFailedKind; @@ -240,8 +261,8 @@ public: class PostLoad : public PostStmt { public: - PostLoad(const Stmt* S, const void *tag = 0) - : PostStmt(S, PostLoadKind, tag) {} + PostLoad(const Stmt* S, const LocationContext *L, const void *tag = 0) + : PostStmt(S, PostLoadKind, L, tag) {} static bool classof(const ProgramPoint* Location) { return Location->getKind() == PostLoadKind; @@ -250,8 +271,8 @@ public: class PostStore : public PostStmt { public: - PostStore(const Stmt* S, const void *tag = 0) - : PostStmt(S, PostStoreKind, tag) {} + PostStore(const Stmt* S, const LocationContext *L, const void *tag = 0) + : PostStmt(S, PostStoreKind, L, tag) {} static bool classof(const ProgramPoint* Location) { return Location->getKind() == PostStoreKind; @@ -260,8 +281,8 @@ public: class PostLValue : public PostStmt { public: - PostLValue(const Stmt* S, const void *tag = 0) - : PostStmt(S, PostLValueKind, tag) {} + PostLValue(const Stmt* S, const LocationContext *L, const void *tag = 0) + : PostStmt(S, PostLValueKind, L, tag) {} static bool classof(const ProgramPoint* Location) { return Location->getKind() == PostLValueKind; @@ -270,8 +291,9 @@ public: class PostPurgeDeadSymbols : public PostStmt { public: - PostPurgeDeadSymbols(const Stmt* S, const void *tag = 0) - : PostStmt(S, PostPurgeDeadSymbolsKind, tag) {} + PostPurgeDeadSymbols(const Stmt* S, const LocationContext *L, + const void *tag = 0) + : PostStmt(S, PostPurgeDeadSymbolsKind, L, tag) {} static bool classof(const ProgramPoint* Location) { return Location->getKind() == PostPurgeDeadSymbolsKind; @@ -280,8 +302,8 @@ public: class BlockEdge : public ProgramPoint { public: - BlockEdge(const CFGBlock* B1, const CFGBlock* B2) - : ProgramPoint(B1, B2, BlockEdgeKind) {} + BlockEdge(const CFGBlock* B1, const CFGBlock* B2, const LocationContext *L) + : ProgramPoint(B1, B2, BlockEdgeKind, L) {} CFGBlock* getSrc() const { return const_cast<CFGBlock*>(static_cast<const CFGBlock*>(getData1())); @@ -307,13 +329,13 @@ template <> struct DenseMapInfo<clang::ProgramPoint> { static inline clang::ProgramPoint getEmptyKey() { uintptr_t x = reinterpret_cast<uintptr_t>(DenseMapInfo<void*>::getEmptyKey()) & ~0x7; - return clang::BlockEntrance(reinterpret_cast<clang::CFGBlock*>(x)); + return clang::BlockEntrance(reinterpret_cast<clang::CFGBlock*>(x), 0); } static inline clang::ProgramPoint getTombstoneKey() { uintptr_t x = - reinterpret_cast<uintptr_t>(DenseMapInfo<void*>::getTombstoneKey()) & ~0x7; - return clang::BlockEntrance(reinterpret_cast<clang::CFGBlock*>(x)); + reinterpret_cast<uintptr_t>(DenseMapInfo<void*>::getTombstoneKey()) & ~0x7; + return clang::BlockEntrance(reinterpret_cast<clang::CFGBlock*>(x), 0); } static unsigned getHashValue(const clang::ProgramPoint& Loc) { |