From 24446189437d6e1ef967295ccfe9cb710f709990 Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Thu, 1 Sep 2016 04:55:00 -0700 Subject: [PATCH] Translate functions coming from std headers od demand Summary: Translate code coming from std::headers only when it's reachable from user code during translation. This way, we reduce number of functions analyzer sees and decreases size of cfg/number of .attr files Reviewed By: jvillard Differential Revision: D3797550 fbshipit-source-id: 2a9eb4c --- infer/src/clang/cFrontend_decl.ml | 7 ++++--- infer/src/clang/cLocation.ml | 8 ++++---- infer/src/clang/cLocation.mli | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/infer/src/clang/cFrontend_decl.ml b/infer/src/clang/cFrontend_decl.ml index e34dba9d0..d133b31dd 100644 --- a/infer/src/clang/cFrontend_decl.ml +++ b/infer/src/clang/cFrontend_decl.ml @@ -144,8 +144,7 @@ struct let info = Clang_ast_proj.get_decl_tuple dec in CLocation.update_curr_file info; let source_range = info.Clang_ast_t.di_source_range in - let translate_location = CLocation.should_translate_lib source_range decl_trans_context in - let always_translate_decl = match dec with + let translate_when_used = match dec with | Clang_ast_t.FunctionDecl (_, name_info, _, _) | Clang_ast_t.CXXMethodDecl (_, name_info, _, _, _) -> (* named_decl_info.ni_name has name without template parameters.*) @@ -154,13 +153,15 @@ struct let name = Ast_utils.get_qualified_name name_info in AttributesTable.is_whitelisted_cpp_method name | _ -> false in + let translate_location = + CLocation.should_translate_lib source_range decl_trans_context ~translate_when_used in let never_translate_decl = match dec with | Clang_ast_t.FunctionDecl (_, name_info, _, _) | Clang_ast_t.CXXMethodDecl (_, name_info, _, _, _) -> let fun_name = name_info.Clang_ast_t.ni_name in Str.string_match (Str.regexp "__infer_skip__" ) fun_name 0 | _ -> false in - (not never_translate_decl) && (translate_location || always_translate_decl) + (not never_translate_decl) && translate_location (* Translate one global declaration *) let rec translate_one_declaration tenv cg cfg decl_trans_context dec = diff --git a/infer/src/clang/cLocation.ml b/infer/src/clang/cLocation.ml index ea9fe3155..e0f694b42 100644 --- a/infer/src/clang/cLocation.ml +++ b/infer/src/clang/cLocation.ml @@ -101,7 +101,7 @@ let should_do_frontend_check (loc_start, _) = (* the headers because the dot files in the frontend tests should contain nothing *) (* else than the source file to avoid conflicts between different versions of the *) (* libraries in the CI *) -let should_translate (loc_start, loc_end) decl_trans_context = +let should_translate (loc_start, loc_end) decl_trans_context ~translate_when_used = let map_path_of pred loc = match loc.Clang_ast_t.sl_file with | Some f -> pred f @@ -116,7 +116,7 @@ let should_translate (loc_start, loc_end) decl_trans_context = in let file_in_project = map_path_of file_in_project loc_end || map_path_of file_in_project loc_start in - let translate_on_demand = file_in_project || Config.models_mode in + let translate_on_demand = translate_when_used || file_in_project || Config.models_mode in let file_in_models = map_path_of DB.file_is_in_cpp_model loc_end || map_path_of DB.file_is_in_cpp_model loc_start in equal_current_source !curr_file @@ -126,9 +126,9 @@ let should_translate (loc_start, loc_end) decl_trans_context = || (Config.cxx_experimental && decl_trans_context = `Translation && translate_on_demand && not Config.testing_mode) -let should_translate_lib source_range decl_trans_context = +let should_translate_lib source_range decl_trans_context ~translate_when_used = not Config.no_translate_libs - || should_translate source_range decl_trans_context + || should_translate source_range decl_trans_context ~translate_when_used let is_file_blacklisted file = let paths = Config.skip_clang_analysis_in_path in diff --git a/infer/src/clang/cLocation.mli b/infer/src/clang/cLocation.mli index 5d098dd6e..899fb5845 100644 --- a/infer/src/clang/cLocation.mli +++ b/infer/src/clang/cLocation.mli @@ -21,7 +21,8 @@ val clang_to_sil_location : Clang_ast_t.source_location -> Cfg.Procdesc.t option val get_sil_location : Clang_ast_t.stmt_info -> CContext.t -> Location.t -val should_translate_lib : Clang_ast_t.source_range -> CModule_type.decl_trans_context -> bool +val should_translate_lib : Clang_ast_t.source_range -> CModule_type.decl_trans_context -> + translate_when_used:bool -> bool val should_do_frontend_check : Clang_ast_t.source_range -> bool