From 2d73494e87f8cacfd4f2ee80104e6baab3c8b356 Mon Sep 17 00:00:00 2001 From: Kai Yang Date: Tue, 10 Jul 2018 00:47:04 -0700 Subject: [PATCH] Add is_static_local_var predicate Reviewed By: ddino Differential Revision: D8775628 fbshipit-source-id: c41798d --- infer/src/clang/cPredicates.ml | 4 ++++ infer/src/clang/cPredicates.mli | 3 +++ infer/src/clang/cTL.ml | 2 ++ .../cpp/linters-for-test-only/issues.exp | 1 + .../cpp/linters-for-test-only/linters_example.al | 11 +++++++++++ 5 files changed, 21 insertions(+) diff --git a/infer/src/clang/cPredicates.ml b/infer/src/clang/cPredicates.ml index fdc504255..17bda73ad 100644 --- a/infer/src/clang/cPredicates.ml +++ b/infer/src/clang/cPredicates.ml @@ -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 +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 = match an with Ctl_parser_types.Decl d -> CAst_utils.is_const_expr_var d | _ -> false diff --git a/infer/src/clang/cPredicates.mli b/infer/src/clang/cPredicates.mli index 3e151d6ad..b87d764c4 100644 --- a/infer/src/clang/cPredicates.mli +++ b/infer/src/clang/cPredicates.mli @@ -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 (** '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 (** 'is_const_expr_var an' is true iff an is a 'const' variable declaration *) diff --git a/infer/src/clang/cTL.ml b/infer/src/clang/cTL.ml index 4fa67c9cd..cdbcf1d99 100644 --- a/infer/src/clang/cTL.ml +++ b/infer/src/clang/cTL.ml @@ -1004,6 +1004,8 @@ let rec eval_Atomic pred_name_ args an lcxt = CPredicates.is_enum_constant_of_enum an name | "is_global_var", [], an -> CPredicates.is_global_var an + | "is_static_local_var", [], an -> + CPredicates.is_static_local_var an | "is_in_block", [], _ -> CPredicates.is_in_block lcxt | "is_in_cxx_constructor", [name], _ -> diff --git a/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp b/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp index 4e6a7c5a2..1a5e20035 100644 --- a/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp +++ b/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp @@ -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, [] diff --git a/infer/tests/codetoanalyze/cpp/linters-for-test-only/linters_example.al b/infer/tests/codetoanalyze/cpp/linters-for-test-only/linters_example.al index 38bf4b060..8b8abf920 100644 --- a/infer/tests/codetoanalyze/cpp/linters-for-test-only/linters_example.al +++ b/infer/tests/codetoanalyze/cpp/linters-for-test-only/linters_example.al @@ -16,3 +16,14 @@ SET report_when = 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"; + +}; +