]> granicus.if.org Git - clang/commitdiff
[analyzer] teach AnalysisDeclContext::getSelfDecl() about blocks that capture the...
authorTed Kremenek <kremenek@apple.com>
Mon, 14 Nov 2011 19:36:08 +0000 (19:36 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 14 Nov 2011 19:36:08 +0000 (19:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144556 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/AnalysisDeclContext.cpp
test/Analysis/misc-ps.m

index 680f2c405060da1e7fa6028cf779e6b0e25db960..546cf98f689b072223faf20b6d1e7e7f59fde05a 100644 (file)
@@ -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;
 }
index 007c558299f514cf53128dd7e74c2f421d79b3bf..48c84c12faa747ebdc5c44b917c2a56edde14345 100644 (file)
@@ -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
+