diff --git a/infer/src/al/cPredicates.ml b/infer/src/al/cPredicates.ml index b059239eb..6fca81518 100644 --- a/infer/src/al/cPredicates.ml +++ b/infer/src/al/cPredicates.ml @@ -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 diff --git a/infer/src/al/cPredicates.mli b/infer/src/al/cPredicates.mli index 69bf13665..f2de93ee7 100644 --- a/infer/src/al/cPredicates.mli +++ b/infer/src/al/cPredicates.mli @@ -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 *) diff --git a/infer/src/al/cTL.ml b/infer/src/al/cTL.ml index 303fec23e..c6600377b 100644 --- a/infer/src/al/cTL.ml +++ b/infer/src/al/cTL.ml @@ -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", [], _ -> 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 a65b34531..db40e9484 100644 --- a/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp +++ b/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp @@ -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, [] 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 0fe56e0bd..37d7909be 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 @@ -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"; diff --git a/infer/tests/codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp b/infer/tests/codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp index fbdcd383d..cd398e1bf 100644 --- a/infer/tests/codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp +++ b/infer/tests/codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp @@ -8,6 +8,8 @@ struct A { int a, b, c, d; }; +extern A a2; + const A& f() { static A a; return a;