[AL] Add new predicate is_extern

Summary: Adding new predicate for checking whether a variable is defined as extern. May be useful in AL rules.

Reviewed By: jvillard

Differential Revision: D16961690

fbshipit-source-id: 0677077dc
master
Dulma Churchill 5 years ago committed by Facebook Github Bot
parent f76ed88741
commit d0bfb856ed

@ -509,6 +509,10 @@ let is_static_local_var an =
match an with Ctl_parser_types.Decl d -> CAst_utils.is_static_local_var d | _ -> false
let is_extern_var an =
match an with Ctl_parser_types.Decl (VarDecl (_, _, _, vdi)) -> vdi.vdi_is_extern | _ -> false
let is_const_expr_var an =
match an with Ctl_parser_types.Decl d -> CAst_utils.is_const_expr_var d | _ -> false

@ -45,6 +45,9 @@ val is_global_var : Ctl_parser_types.ast_node -> bool
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_extern_var : Ctl_parser_types.ast_node -> bool
(** 'is_extern_var an' is true iff an is a extern variable *)
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 *)

@ -1052,6 +1052,8 @@ let rec eval_Atomic pred_name_ args an lcxt =
CPredicates.is_global_var an
| "is_static_local_var", [], an ->
CPredicates.is_static_local_var an
| "is_extern_var", [], an ->
CPredicates.is_extern_var an
| "adhere_to_protocol", [], an ->
CPredicates.adhere_to_protocol an
| "is_in_block", [], _ ->

@ -1,5 +1,6 @@
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, Linters_dummy_method, 11, FIND_EXTERN_VAR, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, f, 14, FIND_STATIC_LOCAL_VAR, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, g, 19, FIND_CXX_COPY_CONSTRUCTOR, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar::Bar, 26, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar::f, 30, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar::f, 32, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, []

@ -27,6 +27,13 @@ SET message = "Found static local var";
};
DEFINE-CHECKER FIND_EXTERN_VAR = {
SET report_when =
WHEN is_extern_var
HOLDS-IN-NODE VarDecl;
SET message = "Found extern var";
};
DEFINE-CHECKER FIND_CXX_METHOD_OVERRIDES = {
SET report_when = is_cxx_method_overriding;
SET message = "%decl_name% overrides";

@ -8,6 +8,8 @@ struct A {
int a, b, c, d;
};
extern A a2;
const A& f() {
static A a;
return a;

Loading…
Cancel
Save