Make the is_global_var not fire for the static local variables

Reviewed By: jberdine, ryanrhee

Differential Revision: D3741764

fbshipit-source-id: 42be7f7
master
Dulma Churchill 9 years ago committed by Facebook Github Bot 4
parent b4f6ea1827
commit 9ae19d01d0

@ -80,7 +80,7 @@ let mutable_local_vars_advice context decl =
let condition = context.CLintersContext.is_ck_translation_unit
&& is_in_main_file decl
&& (is_objc () || is_objcpp ())
&& (not (is_global_var decl))
&& (not (is_syntactically_global_var decl))
&& (not qual_type.qt_is_const) in
if condition then
Some {

@ -200,9 +200,9 @@ let global_var_init_with_calls_warning _ decl =
match Clang_ast_proj.get_named_decl_tuple decl with
| Some (di, ndi) -> di, ndi.ni_name
| None -> assert false (* we cannot be here *) in
let condition = (CFrontend_utils.Ast_utils.is_objc () || CFrontend_utils.Ast_utils.is_objcpp ())
&& CFrontend_utils.Ast_utils.is_global_var decl
&& (not (CFrontend_utils.Ast_utils.is_const_expr_var decl))
let condition = (Ast_utils.is_objc () || Ast_utils.is_objcpp ())
&& Ast_utils.is_syntactically_global_var decl
&& (not (Ast_utils.is_const_expr_var decl))
&& is_initialized_with_expensive_call decl in
if condition then
Some {

@ -409,9 +409,10 @@ struct
let _, st_list = Clang_ast_proj.get_stmt_tuple st in
IList.exists (exists_eventually_st atomic_pred param) st_list
let is_global_var decl =
let is_syntactically_global_var decl =
match decl with
| Clang_ast_t.VarDecl (_, _ ,_, vdi) -> vdi.vdi_is_global
| Clang_ast_t.VarDecl (_, _ ,_, vdi) ->
vdi.vdi_is_global && not vdi.vdi_is_static_local
| _ -> false
let is_const_expr_var decl =

@ -139,7 +139,7 @@ sig
val exists_eventually_st : ('a -> Clang_ast_t.stmt -> bool) -> 'a -> Clang_ast_t.stmt -> bool
(** true if a declaration is a global variable *)
val is_global_var : Clang_ast_t.decl -> bool
val is_syntactically_global_var : Clang_ast_t.decl -> bool
(** true if a declaration is a constexpr variable *)
val is_const_expr_var : Clang_ast_t.decl -> bool

@ -49,11 +49,11 @@ const int dmv = 17;
constexpr double max1 = 1.4 * square(dmv); // OK
void bla() {
static const int kInsets = foo(); // Error
static const int kInsets = foo(); // OK
static float kPadding = [A bar] ? 10.0 : 11.0; // Error
static float kPadding = [A bar] ? 10.0 : 11.0; // OK
static const float kLineSize = 1 / [A scale]; // Error
static const float kLineSize = 1 / [A scale]; // OK
static const float ok = 37;
}

@ -53,7 +53,7 @@ public class GlobalVarTest {
assertThat(
"Results should contain " + GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL,
inferResults,
containsOnlyLines(new int[]{30, 32, 34, 52, 54, 56}));
containsOnlyLines(new int[]{30, 32, 34}));
}
}

Loading…
Cancel
Save