Change the check CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK to use only the clang ast

Reviewed By: sblackshear

Differential Revision: D3534441

fbshipit-source-id: 30c61cd
master
Dulma Churchill 9 years ago committed by Facebook Github Bot 3
parent caff49e411
commit 6ac4db7113

@ -118,6 +118,20 @@ let is_initialized_with_expensive_call decl =
| _ -> false)
| _ -> false
let captured_variables_cxx_ref captured_vars =
let capture_var_is_cxx_ref reference_captured_vars captured_var =
let decl_ref_opt = captured_var.Clang_ast_t.bcv_variable in
match Ast_utils.get_decl_opt_with_decl_ref decl_ref_opt with
| Some VarDecl (_, named_decl_info, type_ptr, _)
| Some ParmVarDecl (_, named_decl_info, type_ptr, _)
| Some ImplicitParamDecl (_, named_decl_info, type_ptr, _) ->
(match Ast_utils.get_desugared_type type_ptr with
| Some RValueReferenceType _ | Some LValueReferenceType _ ->
named_decl_info::reference_captured_vars
| _ -> reference_captured_vars)
| _ -> reference_captured_vars in
IList.fold_left capture_var_is_cxx_ref [] captured_vars
(* === Warnings on properties === *)
(* Assing Pointer Warning: a property with a pointer type should not be declared `assign` *)
@ -216,19 +230,17 @@ let direct_atomic_property_access_warning context stmt_info ivar_name =
(* CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK: C++ references
should not be captured in blocks. *)
let captured_cxx_ref_in_objc_block_warning stmt_info captured_vars =
let is_cxx_ref (_, typ) =
match typ with
| Typ.Tptr(_, Typ.Pk_reference) -> true
| _ -> false in
let capt_refs = IList.filter is_cxx_ref captured_vars in
let pvar_descs =
IList.fold_left (fun s (v, _) -> s ^ " '" ^ (Pvar.to_string v) ^ "' ") "" capt_refs in
let capt_refs = captured_variables_cxx_ref captured_vars in
let var_descs =
let var_desc vars var_named_decl_info =
vars ^ "'" ^ var_named_decl_info.Clang_ast_t.ni_name ^ "'" in
IList.fold_left var_desc "" capt_refs in
(* Fire if the list of captured references is not empty *)
let condition = IList.length capt_refs > 0 in
if condition then
Some {
name = "CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK";
description = "C++ Reference variable(s) " ^ pvar_descs ^
description = "C++ Reference variable(s) " ^ var_descs ^
" captured by Objective-C block";
suggestion = "C++ References are unmanaged and may be invalid " ^
"by the time the block executes.";

@ -34,8 +34,8 @@ val direct_atomic_property_access_warning :
(* CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK: C++ references
should not be captured in blocks. *)
val captured_cxx_ref_in_objc_block_warning : Clang_ast_t.stmt_info -> (Pvar.t * Typ.t) list ->
warning_desc option
val captured_cxx_ref_in_objc_block_warning : Clang_ast_t.stmt_info ->
Clang_ast_t.block_captured_variable list -> warning_desc option
(* REGISTERED_OBSERVER_BEING_DEALLOCATED: an object is registered in a notification center
but not removed before deallocation *)

@ -114,8 +114,7 @@ let run_frontend_checkers_on_stmt trans_state instr =
invoke_set_of_checkers call_checker_for_ivar cfg cg (Some pdesc) ivar_access_checker_list
| BlockExpr(stmt_info, _ , _, Clang_ast_t.BlockDecl (_, block_decl_info)) ->
let captured_block_vars = block_decl_info.Clang_ast_t.bdi_captured_variables in
let captured_vars = CVar_decl.captured_vars_from_block_info context captured_block_vars in
let call_captured_vars_checker = checkers_for_capture_vars stmt_info captured_vars in
let call_captured_vars_checker = checkers_for_capture_vars stmt_info captured_block_vars in
let pdesc_opt = Some pdesc in
invoke_set_of_checkers call_captured_vars_checker cfg cg pdesc_opt captured_vars_checker_list
| _ -> ()

Loading…
Cancel
Save