Don't warn about direct ivar access for atomic readonly properties

Reviewed By: jvillard

Differential Revision: D26425553

fbshipit-source-id: f1aeb3a07
master
Adam Ernst 4 years ago committed by Facebook GitHub Bot
parent 4f77f82cba
commit bf87088a35

@ -217,6 +217,7 @@ is_class ("class_name")
is_const_var () is_const_var ()
is_global_var () is_global_var ()
is_ivar_atomic () is_ivar_atomic ()
is_ivar_readonly ()
is_method_property_accessor_of_ivar () is_method_property_accessor_of_ivar ()
is_node ("node_name") is_node ("node_name")
is_objc_constructor () is_objc_constructor ()

@ -9,7 +9,9 @@ DEFINE-CHECKER DIRECT_ATOMIC_PROPERTY_ACCESS = {
SET report_when = SET report_when =
WHEN WHEN
((NOT context_in_synchronized_block()) AND is_ivar_atomic()) is_ivar_atomic()
AND NOT context_in_synchronized_block()
AND NOT is_ivar_readonly()
AND NOT is_method_property_accessor_of_ivar() AND NOT is_method_property_accessor_of_ivar()
AND NOT is_objc_constructor() AND NOT is_objc_constructor()
AND NOT is_objc_dealloc() AND NOT is_objc_dealloc()

@ -634,6 +634,8 @@ let eval_Atomic pred_name_ args an lcxt =
CPredicates.is_in_objc_category_named lcxt name CPredicates.is_in_objc_category_named lcxt name
| "is_in_objc_protocol_named", [name], _ -> | "is_in_objc_protocol_named", [name], _ ->
CPredicates.is_in_objc_protocol_named lcxt name CPredicates.is_in_objc_protocol_named lcxt name
| "is_ivar_readonly", [], an ->
CPredicates.is_ivar_readonly an
| "is_ivar_atomic", [], an -> | "is_ivar_atomic", [], an ->
CPredicates.is_ivar_atomic an CPredicates.is_ivar_atomic an
| "is_method_property_accessor_of_ivar", [], an -> | "is_method_property_accessor_of_ivar", [], an ->

@ -713,6 +713,22 @@ let is_ivar_atomic an =
false false
(* checks if ivar is defined among a set of fields and if it is readonly *)
let is_ivar_readonly an =
match an with
| Ctl_parser_types.Stmt (Clang_ast_t.ObjCIvarRefExpr (_, _, _, irei)) -> (
let dr_ref = irei.Clang_ast_t.ovrei_decl_ref in
let ivar_pointer = dr_ref.Clang_ast_t.dr_decl_pointer in
match CAst_utils.get_decl ivar_pointer with
| Some d ->
let attributes = get_ivar_attributes d in
List.exists ~f:(PolyVariantEqual.( = ) `Readonly) attributes
| _ ->
false )
| _ ->
false
let is_method_property_accessor_of_ivar an context = let is_method_property_accessor_of_ivar an context =
let open Clang_ast_t in let open Clang_ast_t in
match an with match an with

@ -98,7 +98,10 @@ val context_in_synchronized_block : CLintersContext.context -> bool
(** true if the current node is in the context of a synchronized objc block *) (** true if the current node is in the context of a synchronized objc block *)
val is_ivar_atomic : Ctl_parser_types.ast_node -> bool val is_ivar_atomic : Ctl_parser_types.ast_node -> bool
(** [is_ivar_atomic an] is true iff an denotes an atomi objc ivar *) (** [is_ivar_atomic an] is true iff an denotes an atomic objc ivar *)
val is_ivar_readonly : Ctl_parser_types.ast_node -> bool
(** [is_ivar_readonly an] is true iff an denotes a readonly objc ivar *)
val is_method_property_accessor_of_ivar : val is_method_property_accessor_of_ivar :
Ctl_parser_types.ast_node -> CLintersContext.context -> bool Ctl_parser_types.ast_node -> CLintersContext.context -> bool

@ -25,7 +25,7 @@
@property(nonatomic) int* p; @property(nonatomic) int* p;
@property int* q; // atomic by default @property int* q; // atomic by default
@property(atomic, assign) float f; @property(atomic, assign) float f;
@property(atomic, readonly, assign) float fReadonly;
@property(strong) B* b; @property(strong) B* b;
- (void)write_p:(int)i; - (void)write_p:(int)i;
@ -115,4 +115,8 @@
b(); b();
} }
- (float)readonlyAccess {
return _fReadonly; // good access
}
@end @end

@ -232,6 +232,7 @@ is_class ("class_name")
is_const_var () is_const_var ()
is_global_var () is_global_var ()
is_ivar_atomic () is_ivar_atomic ()
is_ivar_readonly ()
is_method_property_accessor_of_ivar () is_method_property_accessor_of_ivar ()
is_node ("node_name") is_node ("node_name")
is_objc_constructor () is_objc_constructor ()

Loading…
Cancel
Save