From c0f250c45e2519fc27158ef5cb67f012f629543d Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Tue, 21 Nov 2017 09:31:04 -0800 Subject: [PATCH] [liveness] Change the model of assert functions to include the handle failure function to avoid dead store fps Reviewed By: sblackshear Differential Revision: D6385289 fbshipit-source-id: 61ef0fd --- infer/src/checkers/liveness.ml | 9 +-------- infer/src/clang/cTrans.ml | 11 +++++++---- infer/tests/codetoanalyze/objc/errors/issues.exp | 5 ----- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/infer/src/checkers/liveness.ml b/infer/src/checkers/liveness.ml index c92ed74bd..5e3797dca 100644 --- a/infer/src/checkers/liveness.ml +++ b/infer/src/checkers/liveness.ml @@ -61,13 +61,6 @@ end module CFG = ProcCfg.OneInstrPerNode (ProcCfg.Backward (ProcCfg.Exceptional)) module Analyzer = AbstractInterpreter.Make (CFG) (TransferFunctions) -let is_whitelisted_var var = - let whitelisted_vars = ["__assert_file__"; "__assert_fn__"] in - List.exists - ~f:(fun whitelisted_var -> String.equal whitelisted_var (Pvar.get_simplified_name var)) - whitelisted_vars - - let checker {Callbacks.tenv; summary; proc_desc} : Specs.summary = let cfg = CFG.from_pdesc proc_desc in let invariant_map = @@ -89,7 +82,7 @@ let checker {Callbacks.tenv; summary; proc_desc} : Specs.summary = when not ( Pvar.is_frontend_tmp pvar || Pvar.is_return pvar || Pvar.is_global pvar || Domain.mem (Var.of_pvar pvar) live_vars || Procdesc.is_captured_var proc_desc pvar - || is_whitelisted_var pvar || is_sentinel_exp rhs_exp ) -> + || is_sentinel_exp rhs_exp ) -> let issue_id = IssueType.dead_store.unique_id in let message = F.asprintf "The value written to %a is never used" (Pvar.pp Pp.text) pvar in let ltr = [Errlog.make_trace_element 0 loc "Write of unused value" []] in diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 24ab6b290..3bda8ebb8 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -1192,9 +1192,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s in Some (new_or_alloc_trans trans_state_pri sil_loc si qual_type class_opt selector) | _ -> - None (* assertions *) - else if CTrans_models.is_handleFailureInMethod selector then - Some (CTrans_utils.trans_assertion trans_state sil_loc) + None else None @@ -1265,7 +1263,12 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s in let selector = obj_c_message_expr_info.Clang_ast_t.omei_selector in let nname = "Message Call: " ^ selector in - let all_res_trans = res_trans_subexpr_list @ [res_trans_call] in + let assertion_trans_opt = + if CTrans_models.is_handleFailureInMethod selector then + CTrans_utils.trans_assertion trans_state sil_loc + else empty_res_trans + in + let all_res_trans = res_trans_subexpr_list @ [res_trans_call; assertion_trans_opt] in let res_trans_to_parent = PriorityNode.compute_results_to_parent trans_state_pri sil_loc nname si all_res_trans in diff --git a/infer/tests/codetoanalyze/objc/errors/issues.exp b/infer/tests/codetoanalyze/objc/errors/issues.exp index 6ea415d4d..ce70e20e1 100644 --- a/infer/tests/codetoanalyze/objc/errors/issues.exp +++ b/infer/tests/codetoanalyze/objc/errors/issues.exp @@ -21,11 +21,6 @@ codetoanalyze/objc/errors/warnings/ParameterNotNullableExample.m, FBAudioRecorde codetoanalyze/objc/errors/warnings/ParameterNotNullableExample.m, FBAudioRecorder_FBAudioInputCallbackSimpleAliasing:, 3, PARAMETER_NOT_NULL_CHECKED, [start of procedure FBAudioInputCallbackSimpleAliasing:,Message recordState with receiver nil returns nil.] codetoanalyze/objc/errors/warnings/ParameterNotNullableExample.m, FBAudioRecorder_init, 2, NULL_DEREFERENCE, [start of procedure init] codetoanalyze/objc/errors/warnings/ParameterNotNullableExample.m, FBAudioRecorder_test, 3, NULL_DEREFERENCE, [start of procedure test,Message recordState with receiver nil returns nil.] -codetoanalyze/objc/shared/assertions/NSAssert_example.m, NSAssert_addTarget:, 1, MEMORY_LEAK, [start of procedure addTarget:,Condition is false,Condition is true,Condition is true] -codetoanalyze/objc/shared/assertions/NSAssert_example.m, NSAssert_initWithRequest:, 1, MEMORY_LEAK, [start of procedure initWithRequest:,Condition is false,Condition is true,Condition is true] -codetoanalyze/objc/shared/assertions/NSAssert_example.m, test1, 1, MEMORY_LEAK, [start of procedure test1(),Condition is false,Condition is true,Condition is true] -codetoanalyze/objc/shared/assertions/NSAssert_example.m, test1, 1, MEMORY_LEAK, [start of procedure test1(),Condition is false,Condition is true,Condition is true,Condition is true] -codetoanalyze/objc/shared/assertions/NSAssert_example.m, test2, 1, MEMORY_LEAK, [start of procedure test2(),Condition is false,Condition is true,Condition is true] codetoanalyze/objc/shared/block/BlockVar.m, BlockVar_blockPostBad, 5, NULL_DEREFERENCE, [start of procedure blockPostBad,start of procedure block,return from a call to objc_blockBlockVar_blockPostBad_2] codetoanalyze/objc/shared/block/BlockVar.m, BlockVar_capturedNullDeref, 5, NULL_DEREFERENCE, [start of procedure capturedNullDeref,start of procedure block] codetoanalyze/objc/shared/block/BlockVar.m, BlockVar_navigateToURLInBackground, 8, NULL_DEREFERENCE, [start of procedure navigateToURLInBackground,start of procedure block,start of procedure test,return from a call to BlockVar_test,return from a call to objc_blockBlockVar_navigateToURLInBackground_1,Condition is true]