[cfe-commits] r127665 - /cfe/trunk/lib/Analysis/UninitializedValues.cpp

Ted Kremenek kremenek at apple.com
Mon Mar 14 21:57:32 PDT 2011


Author: kremenek
Date: Mon Mar 14 23:57:32 2011
New Revision: 127665

URL: http://llvm.org/viewvc/llvm-project?rev=127665&view=rev
Log:
UninitializedValues: introduce ValueVector:reference class to forward to llvm::BitVector.  No real functionality change, but this is a stepping stone to moving to tri-state logic.

Modified:
    cfe/trunk/lib/Analysis/UninitializedValues.cpp

Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=127665&r1=127664&r2=127665&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Mon Mar 14 23:57:32 2011
@@ -74,20 +74,37 @@
 // CFGBlockValues: dataflow values for CFG blocks.
 //====------------------------------------------------------------------------//
 
-static const bool Initialized = false;
-static const bool Uninitialized = true;
+enum Value { Initialized = 0, Uninitialized = 1 };
 
 class ValueVector {
   llvm::BitVector vec;
 public:
   ValueVector() {}
   ValueVector(unsigned size) : vec(size) {}
-  typedef llvm::BitVector::reference reference;
   void resize(unsigned n) { vec.resize(n); }
   void merge(const ValueVector &rhs) { vec |= rhs.vec; }
   bool operator!=(const ValueVector &rhs) const { return vec != rhs.vec; }
-  reference operator[](unsigned idx) { return vec[idx]; }
   void reset() { vec.reset(); }
+  
+  class reference {
+    ValueVector &vv;
+    const unsigned idx;
+
+    reference();  // Undefined    
+  public:
+    reference(ValueVector &vv, unsigned idx) : vv(vv), idx(idx) {}    
+    ~reference() {}
+    
+    reference &operator=(Value v) {
+      vv.vec[idx] = (v == Initialized ? false : true);
+      return *this;
+    }
+    bool operator==(Value v) {
+      return vv.vec[idx] == (v == Initialized ? false : true);      
+    }
+  };
+    
+  reference operator[](unsigned idx) { return reference(*this, idx); }
 };
 
 typedef std::pair<ValueVector *, ValueVector *> BVPair;
@@ -260,7 +277,7 @@
 namespace {
 class DataflowWorklist {
   llvm::SmallVector<const CFGBlock *, 20> worklist;
-  ValueVector enqueuedBlocks;
+  llvm::BitVector enqueuedBlocks;
 public:
   DataflowWorklist(const CFG &cfg) : enqueuedBlocks(cfg.getNumBlockIDs()) {}
   
@@ -450,11 +467,11 @@
       Visit(bo->getRHS());
       Visit(bo->getLHS());
 
-      ValueVector::reference bit = vals[vd];
-      if (bit == Uninitialized) {
+      ValueVector::reference val = vals[vd];
+      if (val == Uninitialized) {
         if (bo->getOpcode() != BO_Assign)
           reportUninit(res.getDeclRefExpr(), vd);
-        bit = Initialized;
+        val = Initialized;
       }
       return;
     }
@@ -602,7 +619,7 @@
   if (vals.hasNoDeclarations())
     return;
   DataflowWorklist worklist(cfg);
-  ValueVector previouslyVisited(cfg.getNumBlockIDs());
+  llvm::BitVector previouslyVisited(cfg.getNumBlockIDs());
   
   worklist.enqueueSuccessors(&cfg.getEntry());
 





More information about the cfe-commits mailing list