From 7de52e76490d9cf297dcb9f182d63644a1767ced Mon Sep 17 00:00:00 2001 From: Martino Luca Date: Mon, 22 Aug 2016 04:28:10 -0700 Subject: [PATCH] Check early whether the given decl has to be checked with linters or not Reviewed By: dulmarod Differential Revision: D3728836 fbshipit-source-id: a3fa865 --- infer/src/clang/cFrontend_checkers_main.ml | 6 ++- infer/src/clang/cFrontend_errors.ml | 45 ++++++++++------------ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/infer/src/clang/cFrontend_checkers_main.ml b/infer/src/clang/cFrontend_checkers_main.ml index 8fc75bd0b..67af8c3d0 100644 --- a/infer/src/clang/cFrontend_checkers_main.ml +++ b/infer/src/clang/cFrontend_checkers_main.ml @@ -76,7 +76,11 @@ let do_frontend_checks cfg cg source_file ast = match ast with | Clang_ast_t.TranslationUnitDecl(_, decl_list, _, _) -> let context = context_with_ck_set CLintersContext.empty decl_list in - IList.iter (do_frontend_checks_decl context cfg cg) decl_list; + let is_decl_allowed decl = + let decl_info = Clang_ast_proj.get_decl_tuple decl in + CLocation.should_do_frontend_check decl_info.Clang_ast_t.di_source_range in + let allowed_decls = IList.filter is_decl_allowed decl_list in + IList.iter (do_frontend_checks_decl context cfg cg) allowed_decls; (* TODO (t12740727): Remove condition once the transition to linters mode is finished *) if Config.analyzer = Some Config.Linters then store_issues source_file | _ -> assert false (* NOTE: Assumes that an AST alsways starts with a TranslationUnitDecl *) diff --git a/infer/src/clang/cFrontend_errors.ml b/infer/src/clang/cFrontend_errors.ml index 632b253b2..4d4759c18 100644 --- a/infer/src/clang/cFrontend_errors.ml +++ b/infer/src/clang/cFrontend_errors.ml @@ -161,27 +161,24 @@ let run_frontend_checkers_on_stmt context cfg cg instr = let run_frontend_checkers_on_decl context cfg cg dec = let open Clang_ast_t in - let decl_info = Clang_ast_proj.get_decl_tuple dec in - if CLocation.should_do_frontend_check decl_info.Clang_ast_t.di_source_range then - match dec with - | ObjCImplementationDecl (decl_info, _, decl_list, _, _) - | ObjCProtocolDecl (decl_info, _, decl_list, _, _) -> - let idi = match dec with - | ObjCImplementationDecl (_, _, _, _, impl_decl_info) -> Some impl_decl_info - | _ -> None in - let call_ns_checker = checkers_for_ns decl_info idi decl_list in - let key = Ast_utils.generate_key_decl dec in - invoke_set_of_checkers call_ns_checker context cfg cg key ns_notification_checker_list; - context - | VarDecl _ -> - let call_var_checker = checker_for_var dec in - let key = Ast_utils.generate_key_decl dec in - invoke_set_of_checkers call_var_checker context cfg cg key var_checker_list; - context - | ObjCPropertyDecl (decl_info, pname_info, pdi) -> - let call_property_checker = checkers_for_property decl_info pname_info pdi in - let key = Ast_utils.generate_key_decl dec in - invoke_set_of_checkers call_property_checker context cfg cg key property_checkers_list; - context - | _ -> context - else context + match dec with + | ObjCImplementationDecl (decl_info, _, decl_list, _, _) + | ObjCProtocolDecl (decl_info, _, decl_list, _, _) -> + let idi = match dec with + | ObjCImplementationDecl (_, _, _, _, impl_decl_info) -> Some impl_decl_info + | _ -> None in + let call_ns_checker = checkers_for_ns decl_info idi decl_list in + let key = Ast_utils.generate_key_decl dec in + invoke_set_of_checkers call_ns_checker context cfg cg key ns_notification_checker_list; + context + | VarDecl _ -> + let call_var_checker = checker_for_var dec in + let key = Ast_utils.generate_key_decl dec in + invoke_set_of_checkers call_var_checker context cfg cg key var_checker_list; + context + | ObjCPropertyDecl (decl_info, pname_info, pdi) -> + let call_property_checker = checkers_for_property decl_info pname_info pdi in + let key = Ast_utils.generate_key_decl dec in + invoke_set_of_checkers call_property_checker context cfg cg key property_checkers_list; + context + | _ -> context