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

Ted Kremenek kremenek at apple.com
Thu Jul 2 11:15:04 PDT 2009


Author: kremenek
Date: Thu Jul  2 13:14:59 2009
New Revision: 74715

URL: http://llvm.org/viewvc/llvm-project?rev=74715&view=rev
Log:
Add a separate MemSpaceRegion for function/method arguments passed on the stack.
This will simplify the logic of StoreManagers that want to specially reason
about the values of parameters.

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=74715&r1=74714&r2=74715&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h Thu Jul  2 13:14:59 2009
@@ -583,15 +583,17 @@
   llvm::BumpPtrAllocator& A;
   llvm::FoldingSet<MemRegion> Regions;
   
-  MemSpaceRegion* globals;
-  MemSpaceRegion* stack;
-  MemSpaceRegion* heap;
-  MemSpaceRegion* unknown;
-  MemSpaceRegion* code;
+  MemSpaceRegion *globals;
+  MemSpaceRegion *stack;
+  MemSpaceRegion *stackArguments;
+  MemSpaceRegion *heap;
+  MemSpaceRegion *unknown;
+  MemSpaceRegion *code;
 
 public:
   MemRegionManager(ASTContext &c, llvm::BumpPtrAllocator& a)
-    : C(c), A(a), globals(0), stack(0), heap(0), unknown(0), code(0) {}
+    : C(c), A(a), globals(0), stack(0), stackArguments(0), heap(0),
+      unknown(0), code(0) {}
   
   ~MemRegionManager() {}
   
@@ -599,24 +601,28 @@
   
   /// getStackRegion - Retrieve the memory region associated with the
   ///  current stack frame.
-  MemSpaceRegion* getStackRegion();
+  MemSpaceRegion *getStackRegion();
+
+  /// getStackArgumentsRegion - Retrieve the memory region associated with
+  ///  function/method arguments of the current stack frame.
+  MemSpaceRegion *getStackArgumentsRegion();
   
   /// getGlobalsRegion - Retrieve the memory region associated with
   ///  all global variables.
-  MemSpaceRegion* getGlobalsRegion();
+  MemSpaceRegion *getGlobalsRegion();
   
   /// getHeapRegion - Retrieve the memory region associated with the
   ///  generic "heap".
-  MemSpaceRegion* getHeapRegion();
+  MemSpaceRegion *getHeapRegion();
 
   /// getUnknownRegion - Retrieve the memory region associated with unknown
   /// memory space.
-  MemSpaceRegion* getUnknownRegion();
+  MemSpaceRegion *getUnknownRegion();
 
-  MemSpaceRegion* getCodeRegion();
+  MemSpaceRegion *getCodeRegion();
 
   /// getAllocaRegion - Retrieve a region associated with a call to alloca().
-  AllocaRegion* getAllocaRegion(const Expr* Ex, unsigned Cnt);
+  AllocaRegion *getAllocaRegion(const Expr* Ex, unsigned Cnt);
   
   /// getCompoundLiteralRegion - Retrieve the region associated with a
   ///  given CompoundLiteral.
@@ -784,8 +790,12 @@
   typedef MemRegion SuperRegionTy;
   static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,
                                              const VarDecl *d) {
-    return d->hasLocalStorage() ? MRMgr.getStackRegion() 
-                                : MRMgr.getGlobalsRegion();
+    if (d->hasLocalStorage()) {
+      return isa<ParmVarDecl>(d) || isa<ImplicitParamDecl>(d)
+             ? MRMgr.getStackArgumentsRegion() : MRMgr.getStackRegion();
+    }
+    
+    return MRMgr.getGlobalsRegion();
   }
 };
   

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

==============================================================================
--- cfe/trunk/lib/Analysis/MemRegion.cpp (original)
+++ cfe/trunk/lib/Analysis/MemRegion.cpp Thu Jul  2 13:14:59 2009
@@ -223,6 +223,10 @@
   return LazyAllocate(stack);
 }
 
+MemSpaceRegion* MemRegionManager::getStackArgumentsRegion() {
+  return LazyAllocate(stackArguments);
+}
+
 MemSpaceRegion* MemRegionManager::getGlobalsRegion() {
   return LazyAllocate(globals);
 }
@@ -332,8 +336,10 @@
 }
 
 bool MemRegion::hasStackStorage() const {
-  if (const MemSpaceRegion *MS = getMemorySpace())
-    return MS == getMemRegionManager()->getStackRegion();
+  if (const MemSpaceRegion *MS = getMemorySpace()) {
+    MemRegionManager *Mgr = getMemRegionManager();
+    return MS == Mgr->getStackRegion() || MS == Mgr->getStackArgumentsRegion();
+  }
 
   return false;
 }
@@ -348,7 +354,9 @@
 bool MemRegion::hasHeapOrStackStorage() const {
   if (const MemSpaceRegion *MS = getMemorySpace()) {
     MemRegionManager *Mgr = getMemRegionManager();
-    return MS == Mgr->getHeapRegion() || MS == Mgr->getStackRegion();
+    return MS == Mgr->getHeapRegion()
+      || MS == Mgr->getStackRegion()
+      || MS == Mgr->getStackArgumentsRegion();
   }
   return false;
 }  





More information about the cfe-commits mailing list