[linters] Do not lint implicit declarations

Reviewed By: ddino

Differential Revision: D6009056

fbshipit-source-id: e69f566
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent 6f0c4cda4a
commit 21c7b7dda3

@ -254,5 +254,5 @@ DEFINE-CHECKER POINTER_TO_CONST_OBJC_CLASS = {
SET suggestion = "Consider using `%class_name% *const` instead, meaning SET suggestion = "Consider using `%class_name% *const` instead, meaning
the destination of the pointer cannot be changed."; the destination of the pointer cannot be changed.";
SET severity = "WARNING"; SET severity = "WARNING";
SET mode = "OFF"; SET mode = "ON";
}; };

@ -507,3 +507,7 @@ let has_block_attribute decl =
List.exists ~f:(fun attr -> match attr with BlocksAttr _ -> true | _ -> false) attributes List.exists ~f:(fun attr -> match attr with BlocksAttr _ -> true | _ -> false) attributes
| _ | _
-> false -> false
let is_implicit_decl decl =
let decl_info = Clang_ast_proj.get_decl_tuple decl in
decl_info.Clang_ast_t.di_is_implicit

@ -153,3 +153,5 @@ val get_cxx_virtual_base_classes : Clang_ast_t.decl -> Clang_ast_t.type_ptr list
val is_std_vector : Clang_ast_t.qual_type -> bool val is_std_vector : Clang_ast_t.qual_type -> bool
val has_block_attribute : Clang_ast_t.decl -> bool val has_block_attribute : Clang_ast_t.decl -> bool
val is_implicit_decl : Clang_ast_t.decl -> bool

@ -280,41 +280,43 @@ and do_frontend_checks_via_transition context map_active an trans =
and do_frontend_checks_decl (context: CLintersContext.context) and do_frontend_checks_decl (context: CLintersContext.context)
(map_act: Tableaux.context_linter_map) decl = (map_act: Tableaux.context_linter_map) decl =
let open Clang_ast_t in let open Clang_ast_t in
let an = Ctl_parser_types.Decl decl in if CAst_utils.is_implicit_decl decl then () (* do not analyze implicit declarations *)
(* The map should be visited when we enter the node before visiting children *) else
let map_active = Tableaux.update_linter_context_map an map_act in let an = Ctl_parser_types.Decl decl in
match decl with (* The map should be visited when we enter the node before visiting children *)
| FunctionDecl _ let map_active = Tableaux.update_linter_context_map an map_act in
| CXXMethodDecl _ match decl with
| CXXConstructorDecl _ | FunctionDecl _
| CXXConversionDecl _ | CXXMethodDecl _
| CXXDestructorDecl _ | CXXConstructorDecl _
| BlockDecl _ | CXXConversionDecl _
| ObjCMethodDecl _ | CXXDestructorDecl _
-> let context' = CLintersContext.update_current_method context decl in | BlockDecl _
CFrontend_errors.invoke_set_of_checkers_on_node context' an ; | ObjCMethodDecl _
(* We need to visit explicitly nodes reachable via Parameters transitions -> let context' = CLintersContext.update_current_method context decl in
CFrontend_errors.invoke_set_of_checkers_on_node context' an ;
(* We need to visit explicitly nodes reachable via Parameters transitions
because they won't be visited during the evaluation of the formula *) because they won't be visited during the evaluation of the formula *)
do_frontend_checks_via_transition context' map_active an CTL.Parameters ; do_frontend_checks_via_transition context' map_active an CTL.Parameters ;
( match get_method_body_opt decl with ( match get_method_body_opt decl with
| Some stmt | Some stmt
-> do_frontend_checks_stmt context' map_active stmt -> do_frontend_checks_stmt context' map_active stmt
| None | None
-> () ) ; -> () ) ;
call_tableaux context' an map_active call_tableaux context' an map_active
| ObjCImplementationDecl (_, _, decls, _, _) | ObjCInterfaceDecl (_, _, decls, _, _) | ObjCImplementationDecl (_, _, decls, _, _) | ObjCInterfaceDecl (_, _, decls, _, _)
-> CFrontend_errors.invoke_set_of_checkers_on_node context an ; -> CFrontend_errors.invoke_set_of_checkers_on_node context an ;
let context' = {context with current_objc_class= Some decl} in let context' = {context with current_objc_class= Some decl} in
List.iter ~f:(do_frontend_checks_decl context' map_active) decls ; List.iter ~f:(do_frontend_checks_decl context' map_active) decls ;
call_tableaux context' an map_active call_tableaux context' an map_active
| _ | _
-> CFrontend_errors.invoke_set_of_checkers_on_node context an ; -> CFrontend_errors.invoke_set_of_checkers_on_node context an ;
( match Clang_ast_proj.get_decl_context_tuple decl with ( match Clang_ast_proj.get_decl_context_tuple decl with
| Some (decls, _) | Some (decls, _)
-> List.iter ~f:(do_frontend_checks_decl context map_active) decls -> List.iter ~f:(do_frontend_checks_decl context map_active) decls
| None | None
-> () ) ; -> () ) ;
call_tableaux context an map_active call_tableaux context an map_active
let context_with_ck_set context decl_list = let context_with_ck_set context decl_list =
let is_ck = let is_ck =

@ -1,5 +1,3 @@
codetoanalyze/objc/linters/Pointer_to_const_objc_class.m, C_ptr_to_const_objc_bad, 13, POINTER_TO_CONST_OBJC_CLASS, []
codetoanalyze/objc/linters/Pointer_to_const_objc_class.m, C_setPtr_to_const_objc_bad, 13, POINTER_TO_CONST_OBJC_CLASS, []
codetoanalyze/objc/linters/Pointer_to_const_objc_class.m, Linters_dummy_method, 13, POINTER_TO_CONST_OBJC_CLASS, [] codetoanalyze/objc/linters/Pointer_to_const_objc_class.m, Linters_dummy_method, 13, POINTER_TO_CONST_OBJC_CLASS, []
codetoanalyze/objc/linters/assign_pointer.m, Linters_dummy_method, 18, ASSIGN_POINTER_WARNING, [] codetoanalyze/objc/linters/assign_pointer.m, Linters_dummy_method, 18, ASSIGN_POINTER_WARNING, []
codetoanalyze/objc/linters/assign_pointer.m, Linters_dummy_method, 20, ASSIGN_POINTER_WARNING, [] codetoanalyze/objc/linters/assign_pointer.m, Linters_dummy_method, 20, ASSIGN_POINTER_WARNING, []

Loading…
Cancel
Save