diff options
| author | Ted Kremenek <kremenek@apple.com> | 2011-11-14 19:36:08 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2011-11-14 19:36:08 +0000 |
| commit | b39fcfaa1996736dfefe5434dc1691880011d79e (patch) | |
| tree | 0bc82e7b2a9439efc854ddd4e59cbd134ff1e256 | |
| parent | 42d098e1b4d2aabe72fcba1406f89fd6a401d392 (diff) | |
| download | bcm5719-llvm-b39fcfaa1996736dfefe5434dc1691880011d79e.tar.gz bcm5719-llvm-b39fcfaa1996736dfefe5434dc1691880011d79e.zip | |
[analyzer] teach AnalysisDeclContext::getSelfDecl() about blocks that capture the 'self' variable of the enclosing ObjC method decl. Fixes <rdar://problem/10380300>.
llvm-svn: 144556
| -rw-r--r-- | clang/lib/Analysis/AnalysisDeclContext.cpp | 9 | ||||
| -rw-r--r-- | clang/test/Analysis/misc-ps.m | 13 |
2 files changed, 22 insertions, 0 deletions
diff --git a/clang/lib/Analysis/AnalysisDeclContext.cpp b/clang/lib/Analysis/AnalysisDeclContext.cpp index 680f2c40506..546cf98f689 100644 --- a/clang/lib/Analysis/AnalysisDeclContext.cpp +++ b/clang/lib/Analysis/AnalysisDeclContext.cpp @@ -95,6 +95,15 @@ Stmt *AnalysisDeclContext::getBody() const { const ImplicitParamDecl *AnalysisDeclContext::getSelfDecl() const { if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) return MD->getSelfDecl(); + if (const BlockDecl *BD = dyn_cast<BlockDecl>(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<ImplicitParamDecl>(VD); + } + } return NULL; } diff --git a/clang/test/Analysis/misc-ps.m b/clang/test/Analysis/misc-ps.m index 007c558299f..48c84c12faa 100644 --- a/clang/test/Analysis/misc-ps.m +++ b/clang/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 + |

