diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-04-10 21:06:25 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-04-10 21:06:25 +0000 |
commit | e8063ae53bd241de10ba1053054d06867a5c56ab (patch) | |
tree | c149b1fa8ce3d309175e83eb83337dee0cf480f0 /include/clang/Analysis/ProgramPoint.h | |
parent | f36a06a9584cf351e1bb7c5ebf2f707ed416daba (diff) |
Add arbitrary "tags" to ProgramPoints. While this fattens up ProgramPoint even
more, it gives us a tremendous amount of flexibility for extending the analyzer
to handle arbitrary program points.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68823 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Analysis/ProgramPoint.h')
-rw-r--r-- | include/clang/Analysis/ProgramPoint.h | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/include/clang/Analysis/ProgramPoint.h b/include/clang/Analysis/ProgramPoint.h index 5d04351591..7c73a1f25d 100644 --- a/include/clang/Analysis/ProgramPoint.h +++ b/include/clang/Analysis/ProgramPoint.h @@ -46,19 +46,20 @@ private: enum { TwoPointers = 0x1, Custom = 0x2, Mask = 0x3 }; std::pair<uintptr_t,uintptr_t> Data; + const void *Tag; protected: - ProgramPoint(const void* P, Kind k) + ProgramPoint(const void* P, Kind k, const void *tag = 0) : Data(reinterpret_cast<uintptr_t>(P), - (uintptr_t) k) {} + (uintptr_t) k), Tag(tag) {} - ProgramPoint(const void* P1, const void* P2) + ProgramPoint(const void* P1, const void* P2, const void *tag = 0) : Data(reinterpret_cast<uintptr_t>(P1) | TwoPointers, - reinterpret_cast<uintptr_t>(P2)) {} + reinterpret_cast<uintptr_t>(P2)), Tag(tag) {} ProgramPoint(const void* P1, const void* P2, bool) : Data(reinterpret_cast<uintptr_t>(P1) | Custom, - reinterpret_cast<uintptr_t>(P2)) {} + reinterpret_cast<uintptr_t>(P2)), Tag(0) {} protected: void* getData1NoMask() const { @@ -78,6 +79,8 @@ protected: assert(k == BlockEdgeKind || k == PostStmtCustomKind); return reinterpret_cast<void*>(Data.second); } + + const void *getTag() const { return Tag; } public: Kind getKind() const { @@ -88,25 +91,27 @@ public: } } - // For use with DenseMap. + // For use with DenseMap. This hash is probably slow. unsigned getHashValue() const { - std::pair<void*,void*> P(reinterpret_cast<void*>(Data.first), - reinterpret_cast<void*>(Data.second)); - return llvm::DenseMapInfo<std::pair<void*,void*> >::getHashValue(P); + llvm::FoldingSetNodeID ID; + ID.AddPointer(reinterpret_cast<void*>(Data.first)); + ID.AddPointer(reinterpret_cast<void*>(Data.second)); + ID.AddPointer(Tag); + return ID.ComputeHash(); } static bool classof(const ProgramPoint*) { return true; } bool operator==(const ProgramPoint & RHS) const { - return Data == RHS.Data; + return Data == RHS.Data && Tag == RHS.Tag; } bool operator!=(const ProgramPoint& RHS) const { - return Data != RHS.Data; + return Data != RHS.Data || Tag != RHS.Tag; } bool operator<(const ProgramPoint& RHS) const { - return Data < RHS.Data; + return Data < RHS.Data && Tag < RHS.Tag; } void Profile(llvm::FoldingSetNodeID& ID) const { @@ -119,6 +124,7 @@ public: ID.AddPointer(P->first); ID.AddPointer(P->second); } + ID.AddPointer(Tag); } }; @@ -162,10 +168,11 @@ public: } }; - class PostStmt : public ProgramPoint { protected: - PostStmt(const Stmt* S, Kind k) : ProgramPoint(S, k) {} + PostStmt(const Stmt* S, Kind k,const void *tag = 0) + : ProgramPoint(S, k, tag) {} + PostStmt(const Stmt* S, const void* data) : ProgramPoint(S, data, true) {} public: @@ -181,8 +188,8 @@ public: class PostLocationChecksSucceed : public PostStmt { public: - PostLocationChecksSucceed(const Stmt* S) - : PostStmt(S, PostLocationChecksSucceedKind) {} + PostLocationChecksSucceed(const Stmt* S, const void *tag = 0) + : PostStmt(S, PostLocationChecksSucceedKind, tag) {} static bool classof(const ProgramPoint* Location) { return Location->getKind() == PostLocationChecksSucceedKind; @@ -242,7 +249,8 @@ public: class PostLoad : public PostStmt { public: - PostLoad(const Stmt* S) : PostStmt(S, PostLoadKind) {} + PostLoad(const Stmt* S, const void *tag = 0) + : PostStmt(S, PostLoadKind, tag) {} static bool classof(const ProgramPoint* Location) { return Location->getKind() == PostLoadKind; @@ -251,7 +259,8 @@ public: class PostStore : public PostStmt { public: - PostStore(const Stmt* S) : PostStmt(S, PostStoreKind) {} + PostStore(const Stmt* S, const void *tag = 0) + : PostStmt(S, PostStoreKind, tag) {} static bool classof(const ProgramPoint* Location) { return Location->getKind() == PostStoreKind; |