diff --git a/infer/lib/linter_rules/linters.al b/infer/lib/linter_rules/linters.al index 500651d7e..8ea573e0c 100644 --- a/infer/lib/linter_rules/linters.al +++ b/infer/lib/linter_rules/linters.al @@ -148,8 +148,8 @@ DEFINE-CHECKER STRONG_DELEGATE_WARNING = { DEFINE-CHECKER GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL = { - LET is_global_variable = - is_objc_extension() AND is_global_var() AND (NOT is_const_var()); + LET is_global_but_not_const_variable = + is_objc_extension() AND is_global_var() AND (NOT is_const_expr_var()) AND (NOT is_init_integral_constant_expr()); LET makes_an_expensive_call = (is_node("CallExpr") AND NOT call_function("CGPointMake")) @@ -165,7 +165,7 @@ DEFINE-CHECKER GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL = { SET report_when = WHEN - (is_global_variable AND is_initialized_with_expensive_call) + (is_global_but_not_const_variable AND is_initialized_with_expensive_call) HOLDS-IN-NODE VarDecl; SET message = diff --git a/infer/src/clang/cPredicates.ml b/infer/src/clang/cPredicates.ml index 13b698ce5..7ba6c7026 100644 --- a/infer/src/clang/cPredicates.ml +++ b/infer/src/clang/cPredicates.ml @@ -523,6 +523,14 @@ let is_const_expr_var an = match an with Ctl_parser_types.Decl d -> CAst_utils.is_const_expr_var d | _ -> false +let is_init_integral_constant_expr an = + match an with + | Ctl_parser_types.Decl d -> ( + match d with Clang_ast_t.VarDecl (_, _, _, vdi) -> vdi.vdi_is_init_ice | _ -> false ) + | _ -> + false + + let is_qual_type_const an = match an with | Ctl_parser_types.Stmt s -> ( diff --git a/infer/src/clang/cPredicates.mli b/infer/src/clang/cPredicates.mli index c4fc24e09..eaef52594 100644 --- a/infer/src/clang/cPredicates.mli +++ b/infer/src/clang/cPredicates.mli @@ -45,6 +45,9 @@ val is_static_local_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 *) +val is_init_integral_constant_expr : Ctl_parser_types.ast_node -> bool +(** 'is_init_integra_constant_expr an' is true iff it is an initializer and an integral constant expression, or in C++11, whether the initializer is a constant expression. *) + val is_qual_type_const : Ctl_parser_types.ast_node -> bool (** 'is_qual_type_const an' is true iff an is a qual_type 'const' expression *) diff --git a/infer/src/clang/cTL.ml b/infer/src/clang/cTL.ml index 0ec543025..8b8b99614 100644 --- a/infer/src/clang/cTL.ml +++ b/infer/src/clang/cTL.ml @@ -1004,8 +1004,10 @@ let rec eval_Atomic pred_name_ args an lcxt = CPredicates.is_binop_with_kind an kind | "is_class", [cname], an -> CPredicates.is_class an cname - | "is_const_var", [], an -> + | "is_const_expr_var", [], an -> CPredicates.is_const_expr_var an + | "is_init_integral_constant_expr", [], an -> + CPredicates.is_init_integral_constant_expr an | "is_qual_type_const", [], an -> CPredicates.is_qual_type_const an | "has_init_list_const_expr", [], an ->