|
|
|
@ -76,21 +76,17 @@ let while_stmt_checker_list = [CFrontend_checkers.bad_pointer_comparison_warning
|
|
|
|
|
let checker_for_while_stmt stmt_info cond checker context =
|
|
|
|
|
checker context stmt_info cond
|
|
|
|
|
|
|
|
|
|
let get_err_log cfg cg method_decl_opt loc =
|
|
|
|
|
let get_err_log method_decl_opt loc =
|
|
|
|
|
let procname = match method_decl_opt with
|
|
|
|
|
| Some method_decl -> General_utils.procname_of_decl method_decl
|
|
|
|
|
| None -> General_utils.get_procname_for_frontend_checks loc in
|
|
|
|
|
if Config.clang_frontend_action = `Lint then
|
|
|
|
|
LintIssues.get_err_log procname
|
|
|
|
|
else (* TODO (t12740727): Remove this branch once the transition to linters mode is finished *)
|
|
|
|
|
let pdesc = CMethod_trans.get_method_for_frontend_checks cfg cg loc in
|
|
|
|
|
Cfg.Procdesc.get_err_log pdesc
|
|
|
|
|
|
|
|
|
|
(* Add a frontend warning with a description desc at location loc to the errlog of a proc desc *)
|
|
|
|
|
let log_frontend_issue cfg cg method_decl_opt key issue_desc =
|
|
|
|
|
let log_frontend_issue method_decl_opt key issue_desc =
|
|
|
|
|
let issue = issue_desc.CIssue.issue in
|
|
|
|
|
let loc = issue_desc.CIssue.loc in
|
|
|
|
|
let errlog = get_err_log cfg cg method_decl_opt loc in
|
|
|
|
|
let errlog = get_err_log method_decl_opt loc in
|
|
|
|
|
let err_desc = Errdesc.explain_frontend_warning issue_desc.CIssue.description
|
|
|
|
|
issue_desc.CIssue.suggestion loc in
|
|
|
|
|
let name = CIssue.to_string issue in
|
|
|
|
@ -111,14 +107,14 @@ let log_frontend_issue cfg cg method_decl_opt key issue_desc =
|
|
|
|
|
1. f a particular way to apply a checker, it's a partial function
|
|
|
|
|
2. context
|
|
|
|
|
3. the list of checkers to be applied *)
|
|
|
|
|
let invoke_set_of_checkers f context cfg cg key checkers =
|
|
|
|
|
let invoke_set_of_checkers f context key checkers =
|
|
|
|
|
IList.iter (fun checker ->
|
|
|
|
|
match f checker context with
|
|
|
|
|
| Some issue_desc ->
|
|
|
|
|
log_frontend_issue cfg cg context.CLintersContext.current_method key issue_desc
|
|
|
|
|
log_frontend_issue context.CLintersContext.current_method key issue_desc
|
|
|
|
|
| None -> ()) checkers
|
|
|
|
|
|
|
|
|
|
let run_frontend_checkers_on_stmt context cfg cg instr =
|
|
|
|
|
let run_frontend_checkers_on_stmt context instr =
|
|
|
|
|
let open Clang_ast_t in
|
|
|
|
|
match instr with
|
|
|
|
|
| ObjCIvarRefExpr (stmt_info, _, _, obj_c_ivar_ref_expr_info) ->
|
|
|
|
@ -126,40 +122,40 @@ let run_frontend_checkers_on_stmt context cfg cg instr =
|
|
|
|
|
let call_checker_for_ivar = checkers_for_ivar stmt_info dr_ref in
|
|
|
|
|
let key = Ast_utils.generate_key_stmt instr in
|
|
|
|
|
invoke_set_of_checkers
|
|
|
|
|
call_checker_for_ivar context cfg cg key ivar_access_checker_list;
|
|
|
|
|
call_checker_for_ivar context key ivar_access_checker_list;
|
|
|
|
|
context
|
|
|
|
|
| BlockExpr (stmt_info, _ , _, Clang_ast_t.BlockDecl (_, block_decl_info)) ->
|
|
|
|
|
let captured_block_vars = block_decl_info.Clang_ast_t.bdi_captured_variables in
|
|
|
|
|
let call_captured_vars_checker = checkers_for_capture_vars stmt_info captured_block_vars in
|
|
|
|
|
let key = Ast_utils.generate_key_stmt instr in
|
|
|
|
|
invoke_set_of_checkers call_captured_vars_checker context cfg cg key
|
|
|
|
|
invoke_set_of_checkers call_captured_vars_checker context key
|
|
|
|
|
captured_vars_checker_list;
|
|
|
|
|
context
|
|
|
|
|
| IfStmt (stmt_info, _ :: _ :: cond :: _) ->
|
|
|
|
|
let call_checker = checker_for_if_stmt stmt_info [cond] in
|
|
|
|
|
let key = Ast_utils.generate_key_stmt cond in
|
|
|
|
|
invoke_set_of_checkers call_checker context cfg cg key if_stmt_checker_list;
|
|
|
|
|
invoke_set_of_checkers call_checker context key if_stmt_checker_list;
|
|
|
|
|
context
|
|
|
|
|
| ConditionalOperator (stmt_info, first_stmt :: _, _) ->
|
|
|
|
|
let call_checker = checker_for_conditional_op stmt_info [first_stmt] in
|
|
|
|
|
let key = Ast_utils.generate_key_stmt first_stmt in
|
|
|
|
|
invoke_set_of_checkers call_checker context cfg cg key conditional_op_checker_list;
|
|
|
|
|
invoke_set_of_checkers call_checker context key conditional_op_checker_list;
|
|
|
|
|
context
|
|
|
|
|
| ForStmt (stmt_info, [_; _; cond; _; _]) ->
|
|
|
|
|
let call_checker = checker_for_for_stmt stmt_info [cond] in
|
|
|
|
|
let key = Ast_utils.generate_key_stmt cond in
|
|
|
|
|
invoke_set_of_checkers call_checker context cfg cg key for_stmt_checker_list;
|
|
|
|
|
invoke_set_of_checkers call_checker context key for_stmt_checker_list;
|
|
|
|
|
context
|
|
|
|
|
| WhileStmt (stmt_info, [_; cond; _]) ->
|
|
|
|
|
let call_checker = checker_for_while_stmt stmt_info [cond] in
|
|
|
|
|
let key = Ast_utils.generate_key_stmt cond in
|
|
|
|
|
invoke_set_of_checkers call_checker context cfg cg key while_stmt_checker_list;
|
|
|
|
|
invoke_set_of_checkers call_checker context key while_stmt_checker_list;
|
|
|
|
|
context
|
|
|
|
|
| ObjCAtSynchronizedStmt _ ->
|
|
|
|
|
{ context with CLintersContext.in_synchronized_block = true }
|
|
|
|
|
| _ -> context
|
|
|
|
|
|
|
|
|
|
let run_frontend_checkers_on_decl context cfg cg dec =
|
|
|
|
|
let run_frontend_checkers_on_decl context dec =
|
|
|
|
|
let open Clang_ast_t in
|
|
|
|
|
match dec with
|
|
|
|
|
| ObjCImplementationDecl (decl_info, _, decl_list, _, _)
|
|
|
|
@ -169,16 +165,16 @@ let run_frontend_checkers_on_decl context cfg cg dec =
|
|
|
|
|
| _ -> 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;
|
|
|
|
|
invoke_set_of_checkers call_ns_checker context 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;
|
|
|
|
|
invoke_set_of_checkers call_var_checker context 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;
|
|
|
|
|
invoke_set_of_checkers call_property_checker context key property_checkers_list;
|
|
|
|
|
context
|
|
|
|
|
| _ -> context
|
|
|
|
|