From ca23ed5f5fbcbf6a5044b7b9072e6970961091de Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Wed, 4 Oct 2017 10:53:25 -0700 Subject: [PATCH] [linters] Do not report MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE when the variable has __block attribute Reviewed By: mbouaziz Differential Revision: D5964778 fbshipit-source-id: 1807a66 --- infer/src/clang/ComponentKit.ml | 2 +- infer/src/clang/cAst_utils.ml | 9 +++++++++ infer/src/clang/cAst_utils.mli | 2 ++ .../codetoanalyze/componentkit/TestIgnoreImports.mm | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/infer/src/clang/ComponentKit.ml b/infer/src/clang/ComponentKit.ml index 1ab9744dd..f685cdc1f 100644 --- a/infer/src/clang/ComponentKit.ml +++ b/infer/src/clang/ComponentKit.ml @@ -127,7 +127,7 @@ let mutable_local_vars_advice context an = && not (CAst_utils.is_static_local_var decl) && not is_const && not (is_of_whitelisted_type qual_type) && not decl_info.di_is_implicit && not context.CLintersContext.in_for_loop_declaration - && not (CAst_utils.is_std_vector qual_type) + && not (CAst_utils.is_std_vector qual_type) && not (CAst_utils.has_block_attribute decl) in if condition then Some diff --git a/infer/src/clang/cAst_utils.ml b/infer/src/clang/cAst_utils.ml index 46b64519b..bc18148db 100644 --- a/infer/src/clang/cAst_utils.ml +++ b/infer/src/clang/cAst_utils.ml @@ -498,3 +498,12 @@ let is_std_vector qt = -> false ) | None -> false + +let has_block_attribute decl = + let open Clang_ast_t in + match decl with + | VarDecl (decl_info, _, _, _) + -> let attributes = decl_info.di_attributes in + List.exists ~f:(fun attr -> match attr with BlocksAttr _ -> true | _ -> false) attributes + | _ + -> false diff --git a/infer/src/clang/cAst_utils.mli b/infer/src/clang/cAst_utils.mli index 2eaa13ee4..16a9a4f08 100644 --- a/infer/src/clang/cAst_utils.mli +++ b/infer/src/clang/cAst_utils.mli @@ -151,3 +151,5 @@ val get_cxx_base_classes : Clang_ast_t.decl -> Clang_ast_t.type_ptr list val get_cxx_virtual_base_classes : Clang_ast_t.decl -> Clang_ast_t.type_ptr list val is_std_vector : Clang_ast_t.qual_type -> bool + +val has_block_attribute : Clang_ast_t.decl -> bool diff --git a/infer/tests/build_systems/codetoanalyze/componentkit/TestIgnoreImports.mm b/infer/tests/build_systems/codetoanalyze/componentkit/TestIgnoreImports.mm index aed07158e..c31133f0a 100644 --- a/infer/tests/build_systems/codetoanalyze/componentkit/TestIgnoreImports.mm +++ b/infer/tests/build_systems/codetoanalyze/componentkit/TestIgnoreImports.mm @@ -25,6 +25,8 @@ struct D {}; } std::vector v; // no error + + __block D* var; // no error return nil; } @end