From 0747e7e025b3b07f2582739d5df0a5648b05fd5b Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 21 Oct 2008 15:53:15 +0000 Subject: [PATCH] Handle [NSAutoreleasePool addObject:] (an alternative way to add objects to the current autorelease pool). Added initial code for tracking stack of autorelease pools. llvm-svn: 57908 --- clang/lib/Analysis/CFRefCount.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/clang/lib/Analysis/CFRefCount.cpp b/clang/lib/Analysis/CFRefCount.cpp index e98a6db31669..acf4b568ede1 100644 --- a/clang/lib/Analysis/CFRefCount.cpp +++ b/clang/lib/Analysis/CFRefCount.cpp @@ -25,6 +25,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/ImmutableMap.h" +#include "llvm/ADT/ImmutableList.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/Compiler.h" #include "llvm/ADT/STLExtras.h" @@ -965,7 +966,16 @@ void RetainSummaryManager::InitializeClassMethodSummaries() { // Create the [NSAssertionHandler currentHander] summary. addClsMethSummary(&Ctx.Idents.get("NSAssertionHandler"), GetNullarySelector("currentHandler", Ctx), - getPersistentSummary(RetEffect::MakeNotOwned())); + getPersistentSummary(RetEffect::MakeNotOwned())); + + // Create the [NSAutoreleasePool addObject:] summary. + if (!isGCEnabled()) { + ScratchArgs.push_back(std::make_pair(0, Autorelease)); + addClsMethSummary(&Ctx.Idents.get("NSAutoreleasePool"), + GetUnarySelector("addObject", Ctx), + getPersistentSummary(RetEffect::MakeNoRet(), + DoNothing, DoNothing)); + } } void RetainSummaryManager::InitializeMethodSummaries() { @@ -1208,7 +1218,22 @@ namespace clang { static inline void* GDMIndex() { return &RefBIndex; } }; } - + +//===----------------------------------------------------------------------===// +// ARBindings - State used to track objects in autorelease pools. +//===----------------------------------------------------------------------===// + +typedef llvm::ImmutableSet ARPoolContents; +typedef llvm::ImmutableList< std::pair > ARBindings; +static int AutoRBIndex = 0; + +namespace clang { + template<> + struct GRStateTrait : public GRStatePartialTrait { + static inline void* GDMIndex() { return &AutoRBIndex; } + }; +} + //===----------------------------------------------------------------------===// // Transfer functions. //===----------------------------------------------------------------------===//