From 25d01badc5c37d3c8b7b9a41001f9c7e2cabda05 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 9 Mar 2009 22:46:49 +0000 Subject: [PATCH] retain/release checker: Allow allocations to fail by returning nil. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66487 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/CFRefCount.cpp | 6 +++++- test/Analysis/retain-release.m | 7 +++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index b08bce1d58..550410d66b 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -1840,12 +1840,16 @@ void CFRefCount::EvalSummary(ExplodedNodeSet& Dst, state.set(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; } diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index 6b13158119..c05d730491 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -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; -- 2.40.0