Make the description of issues specify the error kind

Reviewed By: sblackshear

Differential Revision: D3555460

fbshipit-source-id: e692296
master
Dulma Churchill 9 years ago committed by Facebook Github Bot 1
parent 09e45710d3
commit 694ded4795

@ -178,7 +178,7 @@ let recognize_exception exn =
desc, Some ml_loc, Exn_user, Medium, Some Kwarning, Nocat)
| Frontend_warning (name, desc, ml_loc) ->
(Localise.from_string name,
desc, Some ml_loc, Exn_user, Medium, Some Kwarning, Nocat)
desc, Some ml_loc, Exn_user, Medium, None, Nocat)
| Checkers (kind_s, desc) ->
(Localise.from_string kind_s,
desc, None, Exn_user, High, None, Prover)

@ -33,6 +33,9 @@ val log_warning : log_issue
(** Report an info in the given procedure. *)
val log_info : log_issue
(** Report an issue of a given kind in the given error log. *)
val log_issue_from_errlog : Exceptions.err_kind -> log_issue_from_errlog
(** Report an error in the given error log. *)
val log_error_from_errlog : log_issue_from_errlog

@ -22,11 +22,12 @@ open CFrontend_utils
(* run_frontend_checkers_on_stmt in CFrontend_error module.*)
(* - If it is a declaration invoke it from run_frontend_checkers_on_decl *)
type warning_desc = {
type issue_desc = {
name : string; (* name for the checker, this will be a kind of bug *)
description : string; (* Description in the error message *)
suggestion : string; (* an optional suggestion or correction *)
loc : Location.t; (* location in the code *)
kind : Exceptions.err_kind; (* issue kind *)
}
(* Helper functions *)
@ -183,6 +184,7 @@ let assign_pointer_warning decl_info pname obj_c_property_decl_info =
pname.ni_name;
suggestion = "Use a different attribute like `strong` or `weak`.";
loc = location_from_dinfo decl_info;
kind = Exceptions.Kwarning
}
else None
@ -195,7 +197,9 @@ let strong_delegate_warning decl_info pname obj_c_property_decl_info =
Some { name = "STRONG_DELEGATE_WARNING";
description = "Property or ivar "^pname.Clang_ast_t.ni_name^" declared strong";
suggestion = "In general delegates should be declared weak or assign";
loc = location_from_dinfo decl_info; }
loc = location_from_dinfo decl_info;
kind = Exceptions.Kwarning
}
else None
(* GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL warning: a global variable initialization should not *)
@ -216,7 +220,9 @@ let global_var_init_with_calls_warning decl =
description = "Global variable " ^ gvar ^
" is initialized using a function or method call";
suggestion = "If the function/method call is expensive, it can affect the starting time of the app.";
loc = location_from_dinfo decl_info; }
loc = location_from_dinfo decl_info;
kind = Exceptions.Kwarning
}
else None
(* Direct Atomic Property access:
@ -245,7 +251,8 @@ let direct_atomic_property_access_warning method_decl stmt_info ivar_decl_ref =
description = "Direct access to ivar " ^ ivar_name ^
" of an atomic property";
suggestion = "Accessing an ivar of an atomic property makes the property nonatomic";
loc = location_from_sinfo stmt_info; }
loc = location_from_sinfo stmt_info;
kind = Exceptions.Kwarning }
else None
| _ -> None
@ -267,7 +274,8 @@ let captured_cxx_ref_in_objc_block_warning stmt_info captured_vars =
" captured by Objective-C block";
suggestion = "C++ References are unmanaged and may be invalid " ^
"by the time the block executes.";
loc = location_from_sinfo stmt_info; }
loc = location_from_sinfo stmt_info;
kind = Exceptions.Kwarning}
else None
@ -291,5 +299,6 @@ let checker_NSNotificationCenter decl_info decls =
name = Localise.to_string (Localise.registered_observer_being_deallocated);
description = Localise.registered_observer_being_deallocated_str CFrontend_config.self;
suggestion = "Consider removing the object from the notification center before its deallocation.";
loc = location_from_dinfo decl_info; }
loc = location_from_dinfo decl_info;
kind = Exceptions.Kwarning }
else None

@ -9,38 +9,40 @@
open! Utils
type warning_desc = {
type issue_desc = {
name : string; (* name for the checker, this will be a kind of bug *)
description : string; (* Description in the error message *)
suggestion : string; (* an optional suggestion or correction *)
loc : Location.t; (* location in the code *)
kind : Exceptions.err_kind (* issue kind *)
}
(* === Warnings on properties === *)
(* Strong Delegate Warning: a property with name delegate should not be declared strong *)
val strong_delegate_warning : Clang_ast_t.decl_info -> Clang_ast_t.named_decl_info ->
Clang_ast_t.obj_c_property_decl_info -> warning_desc option
Clang_ast_t.obj_c_property_decl_info -> issue_desc option
(* Assing Pointer Warning: a property with a pointer type should not be declared `assign` *)
val assign_pointer_warning : Clang_ast_t.decl_info -> Clang_ast_t.named_decl_info ->
Clang_ast_t.obj_c_property_decl_info -> warning_desc option
Clang_ast_t.obj_c_property_decl_info -> issue_desc option
(* Direct Atomic Property access:
a property declared atomic should not be accesses directly via its iva *)
val direct_atomic_property_access_warning : Clang_ast_t.decl -> Clang_ast_t.stmt_info ->
Clang_ast_t.decl_ref -> warning_desc option
Clang_ast_t.decl_ref -> issue_desc option
(* CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK: C++ references
should not be captured in blocks. *)
val captured_cxx_ref_in_objc_block_warning : Clang_ast_t.stmt_info ->
Clang_ast_t.block_captured_variable list -> warning_desc option
Clang_ast_t.block_captured_variable list -> issue_desc option
(* REGISTERED_OBSERVER_BEING_DEALLOCATED: an object is registered in a notification center
but not removed before deallocation *)
val checker_NSNotificationCenter : Clang_ast_t.decl_info -> Clang_ast_t.decl list -> warning_desc option
val checker_NSNotificationCenter : Clang_ast_t.decl_info -> Clang_ast_t.decl list ->
issue_desc option
(* GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL warning: a global variable initialization should not *)
(* contain calls to functions or methods as these can be expensive an delay the starting time *)
(* of a program *)
val global_var_init_with_calls_warning : Clang_ast_t.decl -> warning_desc option
val global_var_init_with_calls_warning : Clang_ast_t.decl -> issue_desc option

@ -48,21 +48,21 @@ let checker_for_global_var dec checker =
checker dec
(* Add a frontend warning with a description desc at location loc to the errlog of a proc desc *)
let log_frontend_warning cfg cg warn_desc =
let log_frontend_issue cfg cg issue_desc =
let open CFrontend_checkers in
let loc = warn_desc.loc in
let loc = issue_desc.loc in
let pdesc = CMethod_trans.get_method_for_frontend_checks cfg cg loc in
let errlog = Cfg.Procdesc.get_err_log pdesc in
let err_desc =
Errdesc.explain_frontend_warning warn_desc.description warn_desc.suggestion loc in
Errdesc.explain_frontend_warning issue_desc.description issue_desc.suggestion loc in
let exn = Exceptions.Frontend_warning
(warn_desc.name, err_desc, __POS__) in
(issue_desc.name, err_desc, __POS__) in
let trace = [
{ Errlog.lt_level = 0;
Errlog.lt_loc = warn_desc.loc;
Errlog.lt_loc = issue_desc.loc;
Errlog.lt_description = "";
Errlog.lt_node_tags = []}] in
Reporting.log_error_from_errlog errlog exn ~loc:(Some loc) ~ltr:(Some trace)
Reporting.log_issue_from_errlog issue_desc.kind errlog exn ~loc:(Some loc) ~ltr:(Some trace)
(* General invocation function for checkers
Takes
@ -72,7 +72,7 @@ let log_frontend_warning cfg cg warn_desc =
let invoke_set_of_checkers f cfg cg checkers =
IList.iter (fun checker ->
match f checker with
| Some warning_desc -> log_frontend_warning cfg cg warning_desc
| Some issue_desc -> log_frontend_issue cfg cg issue_desc
| None -> ()) checkers
(* Call all checkers on properties of class c *)

Loading…
Cancel
Save