From 0d958e7066db0ac2ecbce7286068db50cdb1de63 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 27 Oct 2008 23:39:39 +0000 Subject: [PATCH] - 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 --- include/clang/Analysis/PathSensitive/SVals.h | 37 ++++++++++++++++++-- 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 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(this)) - return (symbol_iterator) (&Data); + return symbol_iterator(SymbolID((uintptr_t)Data)); else if (isa(this)) - return (symbol_iterator) (&Data); + return symbol_iterator(SymbolID((uintptr_t)Data)); else if (isa(this)) { const SymIntConstraint& C = - cast(this)->getConstraint(); - - return (symbol_iterator) &C.getSymbol(); + cast(this)->getConstraint(); + return symbol_iterator(C.getSymbol()); } else if (isa(this)) { const nonloc::LocAsInteger& V = cast(*this); return V.getPersistentLoc().symbol_begin(); } + else if (isa(this)) { + const MemRegion* R = cast(this)->getRegion(); + if (const SymbolicRegion* S = dyn_cast(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(); } //===----------------------------------------------------------------------===// -- 2.40.0