]> granicus.if.org Git - clang/commitdiff
OSAtomic simulation: use the original region as the location to load from,
authorZhongxing Xu <xuzhongxing@gmail.com>
Wed, 9 Dec 2009 08:32:57 +0000 (08:32 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Wed, 9 Dec 2009 08:32:57 +0000 (08:32 +0000)
instead of the ElementRegion obtained from casts.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90964 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/GRExprEngine.cpp
lib/Analysis/Store.cpp
test/Analysis/NSString.m

index 4a960c69379aba04631bfbd9051de826f4f37815..daa249f901cd947e1140fba2e22f1a9bc91e9271 100644 (file)
@@ -1483,10 +1483,13 @@ static bool EvalOSAtomicCompareAndSwap(ExplodedNodeSet& Dst,
   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);
 
index e591842838428eb184b81b4c1d3f66613a05b652..be4ce2d57c63a25bc5094ead355b7db96e15ca4a 100644 (file)
@@ -199,7 +199,7 @@ SVal  StoreManager::CastRetrievedVal(SVal V, const TypedRegion *R,
                                      QualType castTy) {
   if (castTy.isNull())
     return V;
-  
+
   assert(ValMgr.getContext().hasSameUnqualifiedType(castTy,
                                          R->getValueType(ValMgr.getContext())));
   return V;
@@ -228,4 +228,4 @@ const GRState *StoreManager::InvalidateRegions(const GRState *state,
 SVal StoreManager::getLValueCompoundLiteral(const CompoundLiteralExpr* CL,
                                             const LocationContext *LC) {
   return loc::MemRegionVal(MRMgr.getCompoundLiteralRegion(CL, LC));
-}
\ No newline at end of file
+}
index 481a94055ffd3dee66e7e0a8e94fdfdfb825e08c..295cac4275e41e4482f6de26a5a7e05614ce2835 100644 (file)
@@ -302,7 +302,7 @@ void testOSCompareAndSwapXXBarrier() {
 
 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() {
 
 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