From 69392d41929870f3250b99bd1a8816709e81267f Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Fri, 27 Apr 2018 08:06:14 -0700 Subject: [PATCH] [biabduction] Log reasons for skipping also in non Java context Reviewed By: mbouaziz, da319 Differential Revision: D7788663 fbshipit-source-id: 466faed --- infer/src/biabduction/SymExec.ml | 91 ++++++++++--------- .../build_systems/buck_flavors/issues.exp | 2 +- .../tests/codetoanalyze/cpp/errors/issues.exp | 2 +- .../codetoanalyze/objc/errors/issues.exp | 2 +- 4 files changed, 49 insertions(+), 48 deletions(-) diff --git a/infer/src/biabduction/SymExec.ml b/infer/src/biabduction/SymExec.ml index 07808decd..b6a6e2fbe 100644 --- a/infer/src/biabduction/SymExec.ml +++ b/infer/src/biabduction/SymExec.ml @@ -1249,52 +1249,53 @@ let rec sym_exec exe_env tenv current_pdesc instr_ (prop_: Prop.normal Prop.t) p else [(prop_r, path)] in let do_call (prop, path) = - if - Option.value_map - ~f:(fun summary -> is_some (reason_to_skip summary)) - ~default:true resolved_summary_opt - then - let ret_annots = - match resolved_summary_opt with - | Some summ -> - let ret_annots, _ = - (Specs.get_attributes summ).ProcAttributes.method_annotation - in - ret_annots - | None -> - load_ret_annots resolved_pname - in - let attrs_opt = Option.map ~f:Procdesc.get_attributes callee_pdesc_opt in - match attrs_opt with - | Some attrs - -> ( - let ret_type = attrs.ProcAttributes.ret_type in - let model_as_malloc = Objc_models.is_malloc_model ret_type callee_pname in - match (attrs.ProcAttributes.objc_accessor, model_as_malloc) with - | Some objc_accessor, _ -> - (* If it's an ObjC getter or setter, call the builtin rather than skipping *) - handle_objc_instance_method_call n_actual_params n_actual_params prop - tenv ret_id current_pdesc callee_pname loc path - (sym_exec_objc_accessor callee_pname objc_accessor ret_type) - | None, true -> - (* If it's an alloc model, call alloc rather than skipping *) - sym_exec_alloc_model exe_env callee_pname ret_type tenv ret_id - current_pdesc loc prop path - | None, false -> - let is_objc_instance_method = - ProcAttributes.equal_clang_method_kind - attrs.ProcAttributes.clang_method_kind ProcAttributes.OBJC_INSTANCE + let reason_to_skip_opt = + Option.value_map ~f:reason_to_skip ~default:(Some "function or method not found") + resolved_summary_opt + in + match reason_to_skip_opt with + | Some reason + -> ( + let ret_annots = + match resolved_summary_opt with + | Some summ -> + let ret_annots, _ = + (Specs.get_attributes summ).ProcAttributes.method_annotation in - skip_call ~is_objc_instance_method ~reason:"function or method not found" - prop path resolved_pname ret_annots loc ret_id ret_typ_opt - n_actual_params ) - | None -> - skip_call ~reason:"function or method not found" prop path resolved_pname - ret_annots loc ret_id ret_typ_opt n_actual_params - else - proc_call exe_env - (Option.value_exn resolved_summary_opt) - (call_args prop resolved_pname n_actual_params ret_id loc) + ret_annots + | None -> + load_ret_annots resolved_pname + in + match callee_pdesc_opt with + | Some callee_pdesc + -> ( + let attrs = Procdesc.get_attributes callee_pdesc in + let ret_type = attrs.ProcAttributes.ret_type in + let model_as_malloc = Objc_models.is_malloc_model ret_type callee_pname in + match (attrs.ProcAttributes.objc_accessor, model_as_malloc) with + | Some objc_accessor, _ -> + (* If it's an ObjC getter or setter, call the builtin rather than skipping *) + handle_objc_instance_method_call n_actual_params n_actual_params prop + tenv ret_id current_pdesc callee_pname loc path + (sym_exec_objc_accessor callee_pname objc_accessor ret_type) + | None, true -> + (* If it's an alloc model, call alloc rather than skipping *) + sym_exec_alloc_model exe_env callee_pname ret_type tenv ret_id + current_pdesc loc prop path + | None, false -> + let is_objc_instance_method = + ProcAttributes.equal_clang_method_kind + attrs.ProcAttributes.clang_method_kind ProcAttributes.OBJC_INSTANCE + in + skip_call ~is_objc_instance_method ~reason prop path resolved_pname + ret_annots loc ret_id ret_typ_opt n_actual_params ) + | None -> + skip_call ~reason prop path resolved_pname ret_annots loc ret_id + ret_typ_opt n_actual_params ) + | None -> + proc_call exe_env + (Option.value_exn resolved_summary_opt) + (call_args prop resolved_pname n_actual_params ret_id loc) in List.concat_map ~f:do_call sentinel_result ) | Sil.Call (ret_id, fun_exp, actual_params, loc, call_flags) -> diff --git a/infer/tests/build_systems/buck_flavors/issues.exp b/infer/tests/build_systems/buck_flavors/issues.exp index a197d5445..f040bd776 100644 --- a/infer/tests/build_systems/buck_flavors/issues.exp +++ b/infer/tests/build_systems/buck_flavors/issues.exp @@ -2,4 +2,4 @@ src/hello.c, test, 2, NULL_DEREFERENCE, ERROR, [start of procedure test()] src/hello2.c, test2, 2, NULL_DEREFERENCE, ERROR, [start of procedure test2()] src/hello3.c, test3, 2, NULL_DEREFERENCE, ERROR, [start of procedure test3()] src/subtarget1/z_filename_greater_than_subhello1.c, foo_defined_in_subtarget1, 2, NULL_DEREFERENCE, ERROR, [start of procedure foo_defined_in_subtarget1()] -src/subtarget2/subhello2.c, goo, 3, NULL_DEREFERENCE, ERROR, [start of procedure goo(),Skipping foo_defined_in_subtarget1(): function or method not found] +src/subtarget2/subhello2.c, goo, 3, NULL_DEREFERENCE, ERROR, [start of procedure goo(),Skipping foo_defined_in_subtarget1(): empty list of specs] diff --git a/infer/tests/codetoanalyze/cpp/errors/issues.exp b/infer/tests/codetoanalyze/cpp/errors/issues.exp index 9e89759e3..6e2d8ef74 100644 --- a/infer/tests/codetoanalyze/cpp/errors/issues.exp +++ b/infer/tests/codetoanalyze/cpp/errors/issues.exp @@ -194,7 +194,7 @@ codetoanalyze/cpp/errors/types/typeid_expr.cpp, person_typeid, 6, DIVIDE_BY_ZERO codetoanalyze/cpp/errors/types/typeid_expr.cpp, person_typeid_name, 3, MEMORY_LEAK, ERROR, [start of procedure person_typeid_name(),start of procedure Person,return from a call to Person_Person] codetoanalyze/cpp/errors/types/typeid_expr.cpp, person_typeid_name, 4, MEMORY_LEAK, ERROR, [start of procedure person_typeid_name(),start of procedure Person,return from a call to Person_Person] codetoanalyze/cpp/errors/types/typeid_expr.cpp, person_typeid_name, 8, DIVIDE_BY_ZERO, ERROR, [start of procedure person_typeid_name(),start of procedure Person,return from a call to Person_Person,Taking false branch] -codetoanalyze/cpp/errors/types/typeid_expr.cpp, template_type_id_person, 2, MEMORY_LEAK, ERROR, [start of procedure template_type_id_person(),start of procedure Person,return from a call to Person_Person,Skipping template_typeid(): function or method not found] +codetoanalyze/cpp/errors/types/typeid_expr.cpp, template_type_id_person, 2, MEMORY_LEAK, ERROR, [start of procedure template_type_id_person(),start of procedure Person,return from a call to Person_Person,Skipping template_typeid(): empty list of specs] codetoanalyze/cpp/errors/types/typeid_expr.cpp, template_type_id_person, 5, DIVIDE_BY_ZERO, ERROR, [start of procedure template_type_id_person(),start of procedure Person,return from a call to Person_Person,Taking false branch] codetoanalyze/cpp/errors/types/typeid_expr.cpp, template_typeid, 2, MEMORY_LEAK, ERROR, [start of procedure template_typeid(),start of procedure Person,return from a call to Person_Person,start of procedure Person,return from a call to Person_Person,start of procedure ~Person,start of procedure __infer_inner_destructor_~Person,return from a call to Person___infer_inner_destructor_~Person,return from a call to Person_~Person] codetoanalyze/cpp/errors/use_after_free/foreach_map.cpp, use_after_free::Basic_test_double_delete_bad, 3, USE_AFTER_FREE, ERROR, [start of procedure test_double_delete_bad,Skipping Y: function or method not found] diff --git a/infer/tests/codetoanalyze/objc/errors/issues.exp b/infer/tests/codetoanalyze/objc/errors/issues.exp index f21b3cba3..aca634098 100644 --- a/infer/tests/codetoanalyze/objc/errors/issues.exp +++ b/infer/tests/codetoanalyze/objc/errors/issues.exp @@ -93,7 +93,7 @@ codetoanalyze/objc/shared/annotations/nonnull_annotations.m, A_test3:, 1, PARAME codetoanalyze/objc/shared/annotations/nullable_annotations.m, User_otherUserName, 2, NULL_DEREFERENCE, ERROR, [start of procedure otherUserName,Skipping otherUser: function or method not found] codetoanalyze/objc/shared/annotations/nullable_annotations.m, npe_property_nullable, 3, NULL_DEREFERENCE, ERROR, [start of procedure npe_property_nullable(),Skipping child: function or method not found] codetoanalyze/objc/shared/annotations/nullable_annotations_fields.m, A_nullable_field, 3, NULL_DEREFERENCE, ERROR, [start of procedure nullable_field,Skipping getA(): function or method not found] -codetoanalyze/objc/shared/block/dispatch.m, DispatchA_dispatch_a_block_variable_from_macro_delivers_initialised_object, 3, DIVIDE_BY_ZERO, ERROR, [start of procedure dispatch_a_block_variable_from_macro_delivers_initialised_object,start of procedure dispatch_a_block_variable_from_macro,Skipping _dispatch_once(): function or method not found,return from a call to DispatchA_dispatch_a_block_variable_from_macro] +codetoanalyze/objc/shared/block/dispatch.m, DispatchA_dispatch_a_block_variable_from_macro_delivers_initialised_object, 3, DIVIDE_BY_ZERO, ERROR, [start of procedure dispatch_a_block_variable_from_macro_delivers_initialised_object,start of procedure dispatch_a_block_variable_from_macro,Skipping _dispatch_once(): empty list of specs,return from a call to DispatchA_dispatch_a_block_variable_from_macro] codetoanalyze/objc/shared/memory_leaks_benchmark/MemoryLeakExample.m, MemoryLeakExample_blockCapturedVarLeak, 6, MEMORY_LEAK, ERROR, [start of procedure blockCapturedVarLeak,start of procedure block,return from a call to objc_blockMemoryLeakExample_blockCapturedVarLeak_1] codetoanalyze/objc/shared/memory_leaks_benchmark/MemoryLeakExample.m, MemoryLeakExample_createCloseCrossGlyph:, 2, MEMORY_LEAK, ERROR, [start of procedure createCloseCrossGlyph:,Skipping CGRectGetHeight(): function or method not found] codetoanalyze/objc/shared/memory_leaks_benchmark/MemoryLeakExample.m, MemoryLeakExample_measureFrameSizeForText, 1, MEMORY_LEAK, ERROR, [start of procedure measureFrameSizeForText]