From: Ted Kremenek Date: Mon, 14 Nov 2011 19:36:08 +0000 (+0000) Subject: [analyzer] teach AnalysisDeclContext::getSelfDecl() about blocks that capture the... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ccf1bfde160c03c677ba530c9dcb77365a9c2d7b;p=clang [analyzer] teach AnalysisDeclContext::getSelfDecl() about blocks that capture the 'self' variable of the enclosing ObjC method decl. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144556 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/AnalysisDeclContext.cpp b/lib/Analysis/AnalysisDeclContext.cpp index 680f2c4050..546cf98f68 100644 --- a/lib/Analysis/AnalysisDeclContext.cpp +++ b/lib/Analysis/AnalysisDeclContext.cpp @@ -95,6 +95,15 @@ Stmt *AnalysisDeclContext::getBody() const { const ImplicitParamDecl *AnalysisDeclContext::getSelfDecl() const { if (const ObjCMethodDecl *MD = dyn_cast(D)) return MD->getSelfDecl(); + if (const BlockDecl *BD = dyn_cast(D)) { + // See if 'self' was captured by the block. + for (BlockDecl::capture_const_iterator it = BD->capture_begin(), + et = BD->capture_end(); it != et; ++it) { + const VarDecl *VD = it->getVariable(); + if (VD->getName() == "self") + return dyn_cast(VD); + } + } return NULL; } diff --git a/test/Analysis/misc-ps.m b/test/Analysis/misc-ps.m index 007c558299..48c84c12fa 100644 --- a/test/Analysis/misc-ps.m +++ b/test/Analysis/misc-ps.m @@ -1321,3 +1321,16 @@ void radar9414427() { @implementation RDar9465344 @end +// Don't crash when analyzing access to 'self' within a block. +@interface Rdar10380300Base +- (void) foo; +@end +@interface Rdar10380300 : Rdar10380300Base @end +@implementation Rdar10380300 +- (void)foo { + ^{ + [super foo]; + }(); +} +@end +