From bb8c5aaa10643db9a97af6dc43f646656c3a75f7 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 18 Feb 2009 22:57:22 +0000 Subject: [PATCH] More fun with retain checker diagnostics: - Fix some grammar. - Fix a bug where a "reference count incremented" diagnostic would not be shown if the previous typestate was "Released" (only happens in GC mode). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64971 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/CFRefCount.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 72d4afc506..99a1d81ba5 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -1981,7 +1981,7 @@ RefBindings CFRefCount::Update(RefBindings B, SymbolRef sym, break; case RefVal::Released: if (isGCEnabled()) - V = V ^ RefVal::Owned; + V = (V ^ RefVal::Owned) + 1; else { V = V ^ RefVal::ErrorUseAfterRelease; hasErr = V.getKind(); @@ -1999,7 +1999,9 @@ RefBindings CFRefCount::Update(RefBindings B, SymbolRef sym, assert (false); case RefVal::Owned: - V = V.getCount() > 1 ? V - 1 : V ^ RefVal::Released; + assert(V.getCount() > 0); + if (V.getCount() == 1) V = V ^ RefVal::Released; + V = V - 1; break; case RefVal::NotOwned: @@ -2370,9 +2372,11 @@ PathDiagnosticPiece* CFRefReport::VisitNode(const ExplodedNode* N, << "' decrements an object's retain count and registers the " "object with the garbage collector. "; - if (CurrV.getKind() == RefVal::Released) - os << "The object's visible retain count is now 0 and can be " + if (CurrV.getKind() == RefVal::Released) { + assert(CurrV.getCount() == 0); + os << "Since it now has a 0 retain count the object can be " "automatically collected by the garbage collector."; + } else os << "An object must have a 0 retain count to be garbage collected. " "After this call its retain count is +" << CurrV.getCount() @@ -2399,16 +2403,22 @@ PathDiagnosticPiece* CFRefReport::VisitNode(const ExplodedNode* N, os << "Reference count decremented."; else os << "Reference count incremented."; - + if (unsigned Count = CurrV.getCount()) { - os << " Object has +" << Count; + os << " The object now has +" << Count; if (Count > 1) os << " retain counts."; else os << " retain count."; } - + + if (PrevV.getKind() == RefVal::Released) { + assert(TF.isGCEnabled() && CurrV.getCount() > 0); + os << " The object is not eligible for garbage collection until the " + "retain count reaches 0 again."; + } + break; case RefVal::Released: -- 2.40.0