[racerd] fix NSObject.init treatment of ownership

Summary: NSObject.init has no summary yet isn't recognised as allocating memory. This breaks ownership tracking.

Reviewed By: jvillard

Differential Revision: D10852627

fbshipit-source-id: 95e016c84
master
Nikos Gorogiannis 6 years ago committed by Facebook Github Bot
parent b0b8459c3a
commit 342bfb418a

@ -201,9 +201,20 @@ let is_functional pname =
is_annotated_functional pname || is_modeled_functional pname is_annotated_functional pname || is_modeled_functional pname
let nsobject = Typ.Name.Objc.from_qual_name (QualifiedCppName.of_qual_string "NSObject")
let acquires_ownership pname tenv = let acquires_ownership pname tenv =
let is_nsobject_init = function
| Typ.Procname.ObjC_Cpp
{kind= Typ.Procname.ObjC_Cpp.ObjCInstanceMethod; method_name= "init"; class_name} ->
Typ.Name.equal class_name nsobject
| _ ->
false
in
let is_allocation pn = let is_allocation pn =
Typ.Procname.equal pn BuiltinDecl.__new || Typ.Procname.equal pn BuiltinDecl.__new_array Typ.Procname.equal pn BuiltinDecl.__new
|| Typ.Procname.equal pn BuiltinDecl.__new_array
|| is_nsobject_init pn
in in
(* identify library functions that maintain ownership invariants behind the scenes *) (* identify library functions that maintain ownership invariants behind the scenes *)
let is_owned_in_library = function let is_owned_in_library = function

@ -0,0 +1,35 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/NSObject.h>
#import <mutex>
@interface Ctor : NSObject
- (instancetype)init;
- (void)write:(int)data;
@end
@implementation Ctor {
std::mutex _mutex;
int _data;
}
- (instancetype)init {
if (!(self = [super init])) {
return nil;
}
int i = _data;
return self;
}
- (void)write:(int)data {
_mutex.lock();
_data = data;
_mutex.unlock();
}
@end

@ -0,0 +1,27 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "Ctor.mm"
#import <mutex>
@interface CtorInherit : Ctor
- (instancetype)init;
- (void)writeZero;
@end
@implementation CtorInherit
- (instancetype)init {
if (!(self = [super init])) {
return nil;
}
return self;
}
- (void)writeZero {
[self write:0];
}
@end
Loading…
Cancel
Save