[cfe-commits] r161822 - in /cfe/trunk: lib/Analysis/LiveVariables.cpp test/Analysis/inlining/RetainCountExamples.m

Anna Zaks ganna at apple.com
Mon Aug 13 17:36:20 PDT 2012


Author: zaks
Date: Mon Aug 13 19:36:20 2012
New Revision: 161822

URL: http://llvm.org/viewvc/llvm-project?rev=161822&view=rev
Log:
[analyzer] Teach live variable analyzes that super uses self pointer.

Added:
    cfe/trunk/test/Analysis/inlining/RetainCountExamples.m
Modified:
    cfe/trunk/lib/Analysis/LiveVariables.cpp

Modified: cfe/trunk/lib/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/LiveVariables.cpp?rev=161822&r1=161821&r2=161822&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/lib/Analysis/LiveVariables.cpp Mon Aug 13 19:36:20 2012
@@ -284,6 +284,14 @@
       }
       break;
     }
+    case Stmt::ObjCMessageExprClass: {
+      // In calls to super, include the implicit "self" pointer as being live.
+      ObjCMessageExpr *CE = cast<ObjCMessageExpr>(S);
+      if (CE->getReceiverKind() == ObjCMessageExpr::SuperInstance)
+        val.liveDecls = LV.DSetFact.add(val.liveDecls,
+                                        LV.analysisContext.getSelfDecl());
+      break;
+    }
     case Stmt::DeclStmtClass: {
       const DeclStmt *DS = cast<DeclStmt>(S);
       if (const VarDecl *VD = dyn_cast<VarDecl>(DS->getSingleDecl())) {

Added: cfe/trunk/test/Analysis/inlining/RetainCountExamples.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/RetainCountExamples.m?rev=161822&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/inlining/RetainCountExamples.m (added)
+++ cfe/trunk/test/Analysis/inlining/RetainCountExamples.m Mon Aug 13 19:36:20 2012
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.RetainCount -analyzer-ipa=dynamic-bifurcate -verify %s
+
+typedef signed char BOOL;
+typedef struct objc_class *Class;
+typedef struct objc_object {
+    Class isa;
+} *id;
+ at protocol NSObject  - (BOOL)isEqual:(id)object; @end
+ at interface NSObject <NSObject> {}
++(id)alloc;
++(id)new;
+- (oneway void)release;
+-(id)init;
+-(id)autorelease;
+-(id)copy;
+- (Class)class;
+-(id)retain;
+ at end
+
+ at interface SelfStaysLive : NSObject
+- (id)init;
+ at end
+
+ at implementation SelfStaysLive
+- (id)init {
+  return [super init];
+}
+ at end
+
+void selfStaysLive() {
+    SelfStaysLive *foo = [[SelfStaysLive alloc] init]; 
+    [foo release];
+}
\ No newline at end of file





More information about the cfe-commits mailing list