diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-10-27 23:39:39 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-10-27 23:39:39 +0000 |
commit | 0d958e7066db0ac2ecbce7286068db50cdb1de63 (patch) | |
tree | 98957076aee8b7aeb3a165949481f7c0bb33a2ab | |
parent | 934e3e93eface34e73257a4a80cc6752edd588ce (diff) |
- Fix type-punning warning in SVals.cpp by using a real iterator class for symbol_iterator.
- Add symbol_iterator support for SymbolicRegions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58300 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Analysis/PathSensitive/SVals.h | 37 | ||||
-rw-r--r-- | lib/Analysis/SVals.cpp | 22 |
2 files changed, 46 insertions, 13 deletions
diff --git a/include/clang/Analysis/PathSensitive/SVals.h b/include/clang/Analysis/PathSensitive/SVals.h index b37233c35f..092e565a58 100644 --- a/include/clang/Analysis/PathSensitive/SVals.h +++ b/include/clang/Analysis/PathSensitive/SVals.h @@ -92,9 +92,42 @@ public: void print(llvm::raw_ostream& OS) const; void printStdErr() const; - typedef const SymbolID* symbol_iterator; + class symbol_iterator { + const enum { One, Many } HowMany; + union { uintptr_t sym; const SymbolID* sptr; }; + public: + + bool operator==(const symbol_iterator& X) { + return X.sym == sym; + } + + bool operator!=(const symbol_iterator& X) { + return X.sym != sym; + } + + symbol_iterator& operator++() { + if (HowMany == Many) + ++sptr; + else + sym = ~0x0; + + return *this; + } + + SymbolID operator*() const { + if (HowMany) + return *sptr; + + return SymbolID(sym); + } + + symbol_iterator(SymbolID x) : HowMany(One), sym(x.getNumber()) {} + symbol_iterator() : HowMany(One), sym(~0x0) {} + symbol_iterator(const SymbolID* x) : HowMany(Many), sptr(x) {} + }; + symbol_iterator symbol_begin() const; - symbol_iterator symbol_end() const; + symbol_iterator symbol_end() const; // Implement isa<T> support. static inline bool classof(const SVal*) { return true; } diff --git a/lib/Analysis/SVals.cpp b/lib/Analysis/SVals.cpp index 236d857450..7c1098c0b8 100644 --- a/lib/Analysis/SVals.cpp +++ b/lib/Analysis/SVals.cpp @@ -26,32 +26,32 @@ using llvm::APSInt; //===----------------------------------------------------------------------===// SVal::symbol_iterator SVal::symbol_begin() const { - // FIXME: This is a rat's nest. Cleanup. if (isa<loc::SymbolVal>(this)) - return (symbol_iterator) (&Data); + return symbol_iterator(SymbolID((uintptr_t)Data)); else if (isa<nonloc::SymbolVal>(this)) - return (symbol_iterator) (&Data); + return symbol_iterator(SymbolID((uintptr_t)Data)); else if (isa<nonloc::SymIntConstraintVal>(this)) { const SymIntConstraint& C = - cast<nonloc::SymIntConstraintVal>(this)->getConstraint(); - - return (symbol_iterator) &C.getSymbol(); + cast<nonloc::SymIntConstraintVal>(this)->getConstraint(); + return symbol_iterator(C.getSymbol()); } else if (isa<nonloc::LocAsInteger>(this)) { const nonloc::LocAsInteger& V = cast<nonloc::LocAsInteger>(*this); return V.getPersistentLoc().symbol_begin(); } + else if (isa<loc::MemRegionVal>(this)) { + const MemRegion* R = cast<loc::MemRegionVal>(this)->getRegion(); + if (const SymbolicRegion* S = dyn_cast<SymbolicRegion>(R)) + return symbol_iterator(S->getSymbol()); + } - // FIXME: We need to iterate over the symbols of regions. - - return NULL; + return symbol_iterator(); } SVal::symbol_iterator SVal::symbol_end() const { - symbol_iterator X = symbol_begin(); - return X ? X+1 : NULL; + return symbol_iterator(); } //===----------------------------------------------------------------------===// |