]> granicus.if.org Git - clang/commitdiff
- Fix type-punning warning in SVals.cpp by using a real iterator class for symbol_ite...
authorTed Kremenek <kremenek@apple.com>
Mon, 27 Oct 2008 23:39:39 +0000 (23:39 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 27 Oct 2008 23:39:39 +0000 (23:39 +0000)
- 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
lib/Analysis/SVals.cpp

index b37233c35f676e02de7524094797b60ac904d9e4..092e565a58edffc645dcd371ff8ada3d19db54e9 100644 (file)
@@ -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; }
index 236d857450c702c0a21f3e939463eb129540f90d..7c1098c0b88cd64e6073137de8ae8b355ef05c4f 100644 (file)
@@ -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();
 }
 
 //===----------------------------------------------------------------------===//