Add is_static_local_var predicate

Reviewed By: ddino

Differential Revision: D8775628

fbshipit-source-id: c41798d
master
Kai Yang 6 years ago committed by Facebook Github Bot
parent d4a9c6f81a
commit 2d73494e87

@ -500,6 +500,10 @@ let is_global_var an =
match an with Ctl_parser_types.Decl d -> CAst_utils.is_syntactically_global_var d | _ -> false match an with Ctl_parser_types.Decl d -> CAst_utils.is_syntactically_global_var d | _ -> false
let is_static_local_var an =
match an with Ctl_parser_types.Decl d -> CAst_utils.is_static_local_var d | _ -> false
let is_const_expr_var an = let is_const_expr_var an =
match an with Ctl_parser_types.Decl d -> CAst_utils.is_const_expr_var d | _ -> false match an with Ctl_parser_types.Decl d -> CAst_utils.is_const_expr_var d | _ -> false

@ -36,6 +36,9 @@ val is_enum_constant_of_enum : Ctl_parser_types.ast_node -> ALVar.alexp -> bool
val is_global_var : Ctl_parser_types.ast_node -> bool val is_global_var : Ctl_parser_types.ast_node -> bool
(** 'is_global_var an' is true iff an is a global variable (but not a static local) *) (** 'is_global_var an' is true iff an is a global variable (but not a static local) *)
val is_static_local_var : Ctl_parser_types.ast_node -> bool
(** 'is_static_local_var an' is true iff an is a static local variable *)
val is_const_expr_var : Ctl_parser_types.ast_node -> bool val is_const_expr_var : Ctl_parser_types.ast_node -> bool
(** 'is_const_expr_var an' is true iff an is a 'const' variable declaration *) (** 'is_const_expr_var an' is true iff an is a 'const' variable declaration *)

@ -1004,6 +1004,8 @@ let rec eval_Atomic pred_name_ args an lcxt =
CPredicates.is_enum_constant_of_enum an name CPredicates.is_enum_constant_of_enum an name
| "is_global_var", [], an -> | "is_global_var", [], an ->
CPredicates.is_global_var an CPredicates.is_global_var an
| "is_static_local_var", [], an ->
CPredicates.is_static_local_var an
| "is_in_block", [], _ -> | "is_in_block", [], _ ->
CPredicates.is_in_block lcxt CPredicates.is_in_block lcxt
| "is_in_cxx_constructor", [name], _ -> | "is_in_cxx_constructor", [name], _ ->

@ -1 +1,2 @@
codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, f, 12, FIND_STATIC_LOCAL_VAR, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, g, 17, FIND_CXX_COPY_CONSTRUCTOR, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, g, 17, FIND_CXX_COPY_CONSTRUCTOR, no_bucket, WARNING, []

@ -16,3 +16,14 @@ SET report_when =
SET message = "Found Copy Constructor"; SET message = "Found Copy Constructor";
}; };
DEFINE-CHECKER FIND_STATIC_LOCAL_VAR = {
SET report_when =
WHEN is_static_local_var
HOLDS-IN-NODE VarDecl;
SET message = "Found static local var";
};

Loading…
Cancel
Save