[AL] Add a is_static predicate

Summary: With this predicate we are able to check for static global variables in AL.

Reviewed By: ddino

Differential Revision: D17164848

fbshipit-source-id: a3d10598c
master
Dulma Churchill 5 years ago committed by Facebook Github Bot
parent 0904be07aa
commit d04e098eb1

@ -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_static_var an =
match an with Ctl_parser_types.Decl (VarDecl (_, _, _, vdi)) -> vdi.vdi_is_static | _ -> false
let is_extern_var an =
match an with Ctl_parser_types.Decl (VarDecl (_, _, _, vdi)) -> vdi.vdi_is_extern | _ -> 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_static_var : Ctl_parser_types.ast_node -> bool
(** 'is_static_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 *)

@ -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_static_var", [], an ->
CPredicates.is_static_var an
| "is_extern_var", [], an ->
CPredicates.is_extern_var an
| "adhere_to_protocol", [], an ->

@ -1,6 +1,7 @@
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_constructor.cpp, Linters_dummy_method, 13, FIND_STATIC_GLOBAL_VAR, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, f, 16, FIND_STATIC_LOCAL_VAR, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, g, 21, 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, []
@ -10,6 +11,7 @@ codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar
codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 23, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 25, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 28, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 28, FIND_STATIC_GLOBAL_VAR, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 39, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_included.h, Bazoo::fibble, 11, FIND_CXX_METHODS_FROM_HEADER_FILE, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_includer.cpp, Bazowey::frazzle, 11, FIND_REF_FROM_SRC_FILE, no_bucket, WARNING, []

@ -27,6 +27,13 @@ SET message = "Found static local var";
};
DEFINE-CHECKER FIND_STATIC_GLOBAL_VAR = {
SET report_when =
WHEN is_static_var AND is_global_var
HOLDS-IN-NODE VarDecl;
SET message = "Found a static global var";
};
DEFINE-CHECKER FIND_EXTERN_VAR = {
SET report_when =
WHEN is_extern_var

@ -10,6 +10,8 @@ struct A {
extern A a2;
static A a3;
const A& f() {
static A a;
return a;

Loading…
Cancel
Save