From 0d4a0ba35cf7309868887c5662a806fd85bdc160 Mon Sep 17 00:00:00 2001 From: Martin Trojer Date: Tue, 6 Nov 2018 00:40:40 -0800 Subject: [PATCH] [objc] add test for strong/weak self references Reviewed By: jeremydubreil Differential Revision: D12900490 fbshipit-source-id: 8707dc049 --- .../objc_retain_cycles_weak/TimeSpent.m | 18 ++++++++++++++++++ .../objc_retain_cycles_weak/issues.exp | 2 ++ 2 files changed, 20 insertions(+) diff --git a/infer/tests/build_systems/codetoanalyze/objc_retain_cycles_weak/TimeSpent.m b/infer/tests/build_systems/codetoanalyze/objc_retain_cycles_weak/TimeSpent.m index 668cfac7d..5a4fd72b5 100644 --- a/infer/tests/build_systems/codetoanalyze/objc_retain_cycles_weak/TimeSpent.m +++ b/infer/tests/build_systems/codetoanalyze/objc_retain_cycles_weak/TimeSpent.m @@ -11,10 +11,14 @@ @interface TimeSpent () { AnalyticsTimeSpent* _timeSpent; } + +@property(weak) TimeSpent* weakSelfRef; +@property(strong) TimeSpent* strongSelfRef; @end @implementation TimeSpent { ListAdapter* _listAdapter; + TimeSpent* _strongSelfRef2; } - (instancetype)init { @@ -29,6 +33,20 @@ return self; } +- (instancetype)init_bad_ref { + if (self = [super init]) { + _weakSelfRef = self; + _strongSelfRef = self; + } +} + +- (instancetype)init_bad_ref2 { + if (self = [super init]) { + _weakSelfRef = self; + _strongSelfRef2 = self; + } +} + - (instancetype)init_bad { if (self = [super init]) { _listAdapter.dataSourceStrong = self; diff --git a/infer/tests/build_systems/objc_retain_cycles_weak/issues.exp b/infer/tests/build_systems/objc_retain_cycles_weak/issues.exp index 155d548c2..3eb3be4ba 100644 --- a/infer/tests/build_systems/objc_retain_cycles_weak/issues.exp +++ b/infer/tests/build_systems/objc_retain_cycles_weak/issues.exp @@ -1,2 +1,4 @@ build_systems/codetoanalyze/objc_retain_cycles_weak/TimeSpent.m, TimeSpent_init_bad, 2, RETAIN_CYCLE, no_bucket, ERROR, [start of procedure init_bad,Taking true branch,start of procedure setDataSourceStrong:,return from a call to ListAdapter_setDataSourceStrong:] +build_systems/codetoanalyze/objc_retain_cycles_weak/TimeSpent.m, TimeSpent_init_bad_ref, 3, RETAIN_CYCLE, no_bucket, ERROR, [start of procedure init_bad_ref,Taking true branch] +build_systems/codetoanalyze/objc_retain_cycles_weak/TimeSpent.m, TimeSpent_init_bad_ref2, 3, RETAIN_CYCLE, no_bucket, ERROR, [start of procedure init_bad_ref2,Taking true branch] build_systems/codetoanalyze/objc_retain_cycles_weak/TimeSpent.m, retain_cycle_weak_bad, 4, RETAIN_CYCLE, no_bucket, ERROR, [start of procedure retain_cycle_weak_bad(),start of procedure init,start of procedure initWithDelegate:,Executing synthesized setter setDelegate:,return from a call to AnalyticsTimeSpent_initWithDelegate:,return from a call to TimeSpent_init,start of procedure initWithStrongDelegate:,return from a call to AnalyticsTimeSpent_initWithStrongDelegate:,start of procedure setAnalyticsTimeSpent:,return from a call to TimeSpent_setAnalyticsTimeSpent:]