[cfe-commits] r90964 - in /cfe/trunk: lib/Analysis/GRExprEngine.cpp lib/Analysis/Store.cpp test/Analysis/NSString.m

Zhongxing Xu xuzhongxing at gmail.com
Wed Dec 9 00:32:58 PST 2009


Author: zhongxingxu
Date: Wed Dec  9 02:32:57 2009
New Revision: 90964

URL: http://llvm.org/viewvc/llvm-project?rev=90964&view=rev
Log:
OSAtomic simulation: use the original region as the location to load from,
instead of the ElementRegion obtained from casts.

Test cast: the leak cannot occur bacause the true branch cannot be taken.

Modified:
    cfe/trunk/lib/Analysis/GRExprEngine.cpp
    cfe/trunk/lib/Analysis/Store.cpp
    cfe/trunk/test/Analysis/NSString.m

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Wed Dec  9 02:32:57 2009
@@ -1483,10 +1483,13 @@
   ExplodedNodeSet Tmp;
   SVal location = state->getSVal(theValueExpr);
   // Here we should use the value type of the region as the load type.
-  const MemRegion *R = location.getAsRegion();
+  const MemRegion *R = location.getAsRegion()->StripCasts();
   QualType LoadTy;
-  if (R)
+  if (R) {
     LoadTy = cast<TypedRegion>(R)->getValueType(C);
+    // Use the region as the real load location.
+    location = loc::MemRegionVal(R);
+  }
   Engine.EvalLoad(Tmp, theValueExpr, Pred, state, location, OSAtomicLoadTag,
                   LoadTy);
 

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

==============================================================================
--- cfe/trunk/lib/Analysis/Store.cpp (original)
+++ cfe/trunk/lib/Analysis/Store.cpp Wed Dec  9 02:32:57 2009
@@ -199,7 +199,7 @@
                                      QualType castTy) {
   if (castTy.isNull())
     return V;
-  
+
   assert(ValMgr.getContext().hasSameUnqualifiedType(castTy,
                                          R->getValueType(ValMgr.getContext())));
   return V;
@@ -228,4 +228,4 @@
 SVal StoreManager::getLValueCompoundLiteral(const CompoundLiteralExpr* CL,
                                             const LocationContext *LC) {
   return loc::MemRegionVal(MRMgr.getCompoundLiteralRegion(CL, LC));
-}
\ No newline at end of file
+}

Modified: cfe/trunk/test/Analysis/NSString.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/NSString.m?rev=90964&r1=90963&r2=90964&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/NSString.m (original)
+++ cfe/trunk/test/Analysis/NSString.m Wed Dec  9 02:32:57 2009
@@ -302,7 +302,7 @@
 
 void testOSCompareAndSwapXXBarrier_positive() {
   NSString *old = 0;
-  NSString *s = [[NSString alloc] init]; // expected-warning{{leak}}
+  NSString *s = [[NSString alloc] init]; // no-warning
   if (!COMPARE_SWAP_BARRIER((intptr_t) 0, (intptr_t) s, (intptr_t*) &old))
     return;
   else    
@@ -326,7 +326,7 @@
 
 void test_objc_atomicCompareAndSwap_positive() {
   NSString *old = 0;
-  NSString *s = [[NSString alloc] init]; // expected-warning{{leak}}
+  NSString *s = [[NSString alloc] init]; // no-warning
   if (!objc_atomicCompareAndSwapPtr(0, s, &old))
     return;
   else    





More information about the cfe-commits mailing list