[cfe-commits] r58300 - in /cfe/trunk: include/clang/Analysis/PathSensitive/SVals.h lib/Analysis/SVals.cpp
Ted Kremenek
kremenek at apple.com
Mon Oct 27 16:39:39 PDT 2008
Author: kremenek
Date: Mon Oct 27 18:39:39 2008
New Revision: 58300
URL: http://llvm.org/viewvc/llvm-project?rev=58300&view=rev
Log:
- Fix type-punning warning in SVals.cpp by using a real iterator class for symbol_iterator.
- Add symbol_iterator support for SymbolicRegions.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h
cfe/trunk/lib/Analysis/SVals.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h?rev=58300&r1=58299&r2=58300&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h Mon Oct 27 18:39:39 2008
@@ -92,9 +92,42 @@
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; }
Modified: cfe/trunk/lib/Analysis/SVals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/SVals.cpp?rev=58300&r1=58299&r2=58300&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/SVals.cpp (original)
+++ cfe/trunk/lib/Analysis/SVals.cpp Mon Oct 27 18:39:39 2008
@@ -26,32 +26,32 @@
//===----------------------------------------------------------------------===//
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();
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list