[cfe-commits] r57891 - in /cfe/trunk: include/clang/Analysis/PathSensitive/MemRegion.h lib/Analysis/MemRegion.cpp

Zhongxing Xu xuzhongxing at gmail.com
Mon Oct 20 22:27:10 PDT 2008


Author: zhongxingxu
Date: Tue Oct 21 00:27:10 2008
New Revision: 57891

URL: http://llvm.org/viewvc/llvm-project?rev=57891&view=rev
Log:
Add ElementRegion to represent memory chunks for array elements.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
    cfe/trunk/lib/Analysis/MemRegion.cpp

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h?rev=57891&r1=57890&r2=57891&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h Tue Oct 21 00:27:10 2008
@@ -19,6 +19,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/Analysis/PathSensitive/SymbolManager.h"
+#include "clang/Analysis/PathSensitive/RValues.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/Support/Allocator.h"
@@ -37,7 +38,8 @@
   enum Kind { MemSpaceRegionKind, SymbolicRegionKind,
               // Typed regions.
               BEG_TYPED_REGIONS,
-              VarRegionKind, FieldRegionKind, ObjCIvarRegionKind,
+              VarRegionKind, FieldRegionKind, ElementRegionKind,
+              ObjCIvarRegionKind,
               AnonTypedRegionKind, AnonPointeeRegionKind,
               END_TYPED_REGIONS };  
 private:
@@ -257,7 +259,27 @@
     return R->getKind() == ObjCIvarRegionKind;
   }
 };
-  
+
+class ElementRegion : public SubRegion {
+  friend class MemRegionManager;
+
+  SVal Index;
+
+  ElementRegion(SVal Idx, const MemRegion* sReg)
+    : SubRegion(sReg, ElementRegionKind), Index(Idx) {}
+
+  static void ProfileRegion(llvm::FoldingSetNodeID& ID, SVal Idx, 
+                            const MemRegion* superRegion);
+
+public:
+
+  void Profile(llvm::FoldingSetNodeID& ID) const;
+
+  static bool classof(const MemRegion* R) {
+    return R->getKind() == ElementRegionKind;
+  }
+};
+
 //===----------------------------------------------------------------------===//
 // MemRegionManager - Factory object for creating regions.
 //===----------------------------------------------------------------------===//
@@ -305,7 +327,9 @@
     return getVarRegion(vd, vd->hasLocalStorage() ? getStackRegion() 
                         : getGlobalsRegion());
   }
-  
+
+  ElementRegion* getElementRegion(SVal Idx, const MemRegion* superRegion);
+
   /// getFieldRegion - Retrieve or create the memory region associated with
   ///  a specified FieldDecl.  'superRegion' corresponds to the containing
   ///  memory region (which typically represents the memory representing

Modified: cfe/trunk/lib/Analysis/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/MemRegion.cpp?rev=57891&r1=57890&r2=57891&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/MemRegion.cpp (original)
+++ cfe/trunk/lib/Analysis/MemRegion.cpp Tue Oct 21 00:27:10 2008
@@ -65,6 +65,16 @@
   SymbolicRegion::ProfileRegion(ID, sym);
 }
 
+void ElementRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, SVal Idx, 
+                                  const MemRegion* superRegion) {
+  ID.AddInteger(MemRegion::ElementRegionKind);
+  ID.AddPointer(superRegion);
+  Idx.Profile(ID);
+}
+
+void ElementRegion::Profile(llvm::FoldingSetNodeID& ID) const {
+  ElementRegion::ProfileRegion(ID, Index, superRegion);
+}
 //===----------------------------------------------------------------------===//
 // Region pretty-printing.
 //===----------------------------------------------------------------------===//
@@ -141,6 +151,24 @@
   return R;
 }
 
+ElementRegion* MemRegionManager::getElementRegion(SVal Idx,
+                                                  const MemRegion* superRegion){
+  llvm::FoldingSetNodeID ID;
+  ElementRegion::ProfileRegion(ID, Idx, superRegion);
+
+  void* InsertPos;
+  MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
+  ElementRegion* R = cast_or_null<ElementRegion>(data);
+
+  if (!R) {
+    R = (ElementRegion*) A.Allocate<ElementRegion>();
+    new (R) ElementRegion(Idx, superRegion);
+    Regions.InsertNode(R, InsertPos);
+  }
+
+  return R;
+}
+
 /// getSymbolicRegion - Retrieve or create a "symbolic" memory region.
 SymbolicRegion* MemRegionManager::getSymbolicRegion(const SymbolID sym) {
   





More information about the cfe-commits mailing list