diff --git a/infer/src/backend/procname.ml b/infer/src/backend/procname.ml index 3edec15e8..bb9f1fabd 100644 --- a/infer/src/backend/procname.ml +++ b/infer/src/backend/procname.ml @@ -373,6 +373,11 @@ let is_constructor = function (name.method_name = "new") || Utils.string_is_prefix "init" name.method_name | _ -> false +(** [is_objc_dealloc pname] returns true if [pname] is the dealloc method in Objective-C *) +let is_objc_dealloc = function + | ObjC_Cpp_method name -> name.method_name = "dealloc" + | _ -> false + let java_is_close = function | Java_method js -> js.method_name = "close" | _ -> false diff --git a/infer/src/backend/procname.mli b/infer/src/backend/procname.mli index 40f73ad90..fd5a89e25 100644 --- a/infer/src/backend/procname.mli +++ b/infer/src/backend/procname.mli @@ -119,6 +119,9 @@ val is_anonymous_inner_class_name : string -> bool (** [is_constructor pname] returns true if [pname] is a constructor *) val is_constructor : t -> bool +(** [is_objc_dealloc pname] returns true if [pname] is the dealloc method in Objective-C *) +val is_objc_dealloc : t -> bool + (** [java_is_close pname] returns true if the method name is "close" *) val java_is_close : t -> bool diff --git a/infer/src/clang/cFrontend_checkers.ml b/infer/src/clang/cFrontend_checkers.ml index 92fec3f67..512c21556 100644 --- a/infer/src/clang/cFrontend_checkers.ml +++ b/infer/src/clang/cFrontend_checkers.ml @@ -52,7 +52,8 @@ let direct_atomic_property_access context stmt_info ivar_name = let condition = (CField_decl.is_ivar_atomic ivar (flds1 @ flds2)) && not (CContext.is_curr_proc_objc_getter context ivar) && not (CContext.is_curr_proc_objc_setter context ivar) - && not (Procname.is_constructor mname) in + && not (Procname.is_constructor mname) + && not (Procname.is_objc_dealloc mname) in let warning_desc = { name = "DIRECT_ATOMIC_PROPERTY_ACCESS"; description = "Direct access to ivar " ^ (Ident.fieldname_to_string ivar) ^ diff --git a/infer/tests/codetoanalyze/objc/warnings/atomic_prop.m b/infer/tests/codetoanalyze/objc/warnings/atomic_prop.m index 0895a4842..37fb64ea4 100644 --- a/infer/tests/codetoanalyze/objc/warnings/atomic_prop.m +++ b/infer/tests/codetoanalyze/objc/warnings/atomic_prop.m @@ -72,6 +72,11 @@ _f = e; // Good access } +- (void) dealloc +{ + _q = 0; // Good access +} + - (void) writeP: (int)i { _p = i; // Good access