summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2012-08-14 00:36:20 +0000
committerAnna Zaks <ganna@apple.com>2012-08-14 00:36:20 +0000
commit23665a1bcfd465626848f1b5cf9c8a6a86c913b7 (patch)
tree68f9bec16359cedefa0dbb32dce1820a798232c7
parentaa4acdfdeef14211714650c96dae28cdd3fc4bd6 (diff)
downloadbcm5719-llvm-23665a1bcfd465626848f1b5cf9c8a6a86c913b7.tar.gz
bcm5719-llvm-23665a1bcfd465626848f1b5cf9c8a6a86c913b7.zip
[analyzer] Teach live variable analyzes that super uses self pointer.
llvm-svn: 161822
-rw-r--r--clang/lib/Analysis/LiveVariables.cpp8
-rw-r--r--clang/test/Analysis/inlining/RetainCountExamples.m33
2 files changed, 41 insertions, 0 deletions
diff --git a/clang/lib/Analysis/LiveVariables.cpp b/clang/lib/Analysis/LiveVariables.cpp
index 584d81284e9..38f8199bffc 100644
--- a/clang/lib/Analysis/LiveVariables.cpp
+++ b/clang/lib/Analysis/LiveVariables.cpp
@@ -284,6 +284,14 @@ void TransferFunctions::Visit(Stmt *S) {
}
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())) {
diff --git a/clang/test/Analysis/inlining/RetainCountExamples.m b/clang/test/Analysis/inlining/RetainCountExamples.m
new file mode 100644
index 00000000000..2b682c2b4bf
--- /dev/null
+++ b/clang/test/Analysis/inlining/RetainCountExamples.m
@@ -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;
+@protocol NSObject - (BOOL)isEqual:(id)object; @end
+@interface NSObject <NSObject> {}
++(id)alloc;
++(id)new;
+- (oneway void)release;
+-(id)init;
+-(id)autorelease;
+-(id)copy;
+- (Class)class;
+-(id)retain;
+@end
+
+@interface SelfStaysLive : NSObject
+- (id)init;
+@end
+
+@implementation SelfStaysLive
+- (id)init {
+ return [super init];
+}
+@end
+
+void selfStaysLive() {
+ SelfStaysLive *foo = [[SelfStaysLive alloc] init];
+ [foo release];
+} \ No newline at end of file
OpenPOWER on IntegriCloud