]> granicus.if.org Git - clang/commitdiff
retain/release checker: Allow allocations to fail by returning nil.
authorTed Kremenek <kremenek@apple.com>
Mon, 9 Mar 2009 22:46:49 +0000 (22:46 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 9 Mar 2009 22:46:49 +0000 (22:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66487 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CFRefCount.cpp
test/Analysis/retain-release.m

index b08bce1d58a3d7c0df803174094e6e7e4e6dccdd..550410d66bf491b75ffd4813a109e6671bd720dd 100644 (file)
@@ -1840,12 +1840,16 @@ void CFRefCount::EvalSummary(ExplodedNodeSet<GRState>& Dst,
         state.set<RefBindings>(Sym, RefVal::makeOwned(RE.getObjKind(), RetT));      
       state = state.BindExpr(Ex, loc::SymbolVal(Sym), false);
 
-      // FIXME: Add a flag to the checker where allocations are allowed to fail.      
+
+      // FIXME: Add a flag to the checker where allocations are assumed to
+      // *not fail.
+#if 0
       if (RE.getKind() == RetEffect::OwnedAllocatedSymbol) {
         bool isFeasible;
         state = state.Assume(loc::SymbolVal(Sym), true, isFeasible);
         assert(isFeasible && "Cannot assume fresh symbol is non-null.");        
       }
+#endif
       
       break;
     }
index 6b1315811961b4e20e0f7e4e42cf6e41b336ee5f..c05d73049165373e97dc68d184b0f679310c88aa 100644 (file)
@@ -196,9 +196,8 @@ CFDateRef f8() {
 CFDateRef f9() {
   CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent());
   int *p = 0;
-  // test that the checker assumes that CFDateCreate returns a non-null
-  // pointer
-  if (!date) *p = 1; // no-warning
+  // When allocations fail, CFDateCreate can return null.
+  if (!date) *p = 1; // expected-warning{{null}}
   return date;
 }
 
@@ -316,7 +315,7 @@ static void rdar_6659160(char *inkind, char *inname)
     kindC = [kind UTF8String];
   if(name)
     nameC = [name UTF8String];
-  if(!isFoo(kindC[0])) // no-warning
+  if(!isFoo(kindC[0])) // expected-warning{{null}}
     return;
   if(!isFoo(nameC[0])) // no-warning
     return;