diff --git a/infer/src/clang/CType_decl.ml b/infer/src/clang/CType_decl.ml index 6f4367752..421564c10 100644 --- a/infer/src/clang/CType_decl.ml +++ b/infer/src/clang/CType_decl.ml @@ -182,14 +182,6 @@ let get_record_definition decl = decl -(** Global counter for anonymous block*) -let block_counter = ref 0 - -let get_fresh_block_index () = - block_counter := !block_counter + 1 ; - !block_counter - - let mk_objc_method class_typename method_name method_kind = Typ.Procname.ObjC_Cpp (Typ.Procname.ObjC_Cpp.make class_typename method_name method_kind Typ.NoTemplate) @@ -442,7 +434,17 @@ and objc_method_procname ?tenv decl_info method_name mdi = mk_objc_method class_typename method_name method_kind -and from_decl ?tenv ~is_cpp meth_decl = +and objc_block_procname outer_proc_opt = + let outer_proc_string = Option.value_map ~f:Typ.Procname.to_string outer_proc_opt ~default:"" in + let block_procname_with_index i = + Printf.sprintf "%s%s%s%d" Config.anonymous_block_prefix outer_proc_string + Config.anonymous_block_num_sep i + in + let name = block_procname_with_index (CFrontend_config.get_fresh_block_index ()) in + Typ.Procname.mangled_objc_block name + + +and from_decl ?tenv ~is_cpp ?outer_proc meth_decl = let open Clang_ast_t in match meth_decl with | FunctionDecl (decl_info, name_info, _, fdi) -> @@ -460,11 +462,7 @@ and from_decl ?tenv ~is_cpp meth_decl = | ObjCMethodDecl (decl_info, name_info, mdi) -> objc_method_procname ?tenv decl_info name_info.Clang_ast_t.ni_name mdi | BlockDecl _ -> - let name = - Config.anonymous_block_prefix ^ Config.anonymous_block_num_sep - ^ string_of_int (get_fresh_block_index ()) - in - Typ.Procname.mangled_objc_block name + objc_block_procname outer_proc | _ -> Logging.die InternalError "Expected method decl, but got %s." (Clang_ast_proj.get_decl_kind_string meth_decl) @@ -531,20 +529,6 @@ and get_record_struct_type tenv definition_decl : Typ.desc = module CProcname = struct let from_decl = from_decl - (* silly, but required to avoid circular dependencies *) - - let reset_block_counter () = block_counter := 0 - - let block_procname_with_index defining_proc i = - Config.anonymous_block_prefix ^ Typ.Procname.to_string defining_proc - ^ Config.anonymous_block_num_sep ^ string_of_int i - - - let mk_fresh_block_procname defining_proc = - let name = block_procname_with_index defining_proc (get_fresh_block_index ()) in - Typ.Procname.mangled_objc_block name - - module NoAstDecl = struct let c_function_of_string ~is_cpp tenv name = let qual_name = QualifiedCppName.of_qual_string name in diff --git a/infer/src/clang/CType_decl.mli b/infer/src/clang/CType_decl.mli index e9e7d3ced..03f744d16 100644 --- a/infer/src/clang/CType_decl.mli +++ b/infer/src/clang/CType_decl.mli @@ -10,7 +10,8 @@ open! IStd module CProcname : sig - val from_decl : ?tenv:Tenv.t -> is_cpp:bool -> Clang_ast_t.decl -> Typ.Procname.t + val from_decl : + ?tenv:Tenv.t -> is_cpp:bool -> ?outer_proc:Typ.Procname.t -> Clang_ast_t.decl -> Typ.Procname.t (** Given decl, return its procname. This function should be used for all procedures present in original AST *) @@ -29,12 +30,6 @@ module CProcname : sig val objc_method_of_string_kind : Typ.Name.t -> string -> Typ.Procname.ObjC_Cpp.kind -> Typ.Procname.t end - - val mk_fresh_block_procname : Typ.Procname.t -> Typ.Procname.t - (** Makes a fresh name for a block defined inside the defining procedure. - It updates the global block_counter *) - - val reset_block_counter : unit -> unit end (** Processes types and record declarations by adding them to the tenv *) diff --git a/infer/src/clang/cFrontend.ml b/infer/src/clang/cFrontend.ml index f0fc0855a..690503d10 100644 --- a/infer/src/clang/cFrontend.ml +++ b/infer/src/clang/cFrontend.ml @@ -41,7 +41,7 @@ let compute_icfg trans_unit_ctx tenv ast = let init_global_state_capture () = Ident.NameGenerator.reset () ; CFrontend_config.global_translation_unit_decls := [] ; - CType_decl.CProcname.reset_block_counter () + CFrontend_config.reset_block_counter () let do_source_file (translation_unit_context: CFrontend_config.translation_unit_context) ast = diff --git a/infer/src/clang/cFrontend_config.ml b/infer/src/clang/cFrontend_config.ml index 14aafb6a9..925f129d5 100644 --- a/infer/src/clang/cFrontend_config.ml +++ b/infer/src/clang/cFrontend_config.ml @@ -141,6 +141,16 @@ let procedures_attempted = ref 0 let procedures_failed = ref 0 +(** Global counter for anonymous block*) +let block_counter = ref 0 + +let get_fresh_block_index () = + block_counter := !block_counter + 1 ; + !block_counter + + +let reset_block_counter () = block_counter := 0 + let reset_global_state () = enum_map := ClangPointers.Map.empty ; global_translation_unit_decls := [] ; diff --git a/infer/src/clang/cFrontend_config.mli b/infer/src/clang/cFrontend_config.mli index d5626dd78..e5b0ccc4f 100644 --- a/infer/src/clang/cFrontend_config.mli +++ b/infer/src/clang/cFrontend_config.mli @@ -137,6 +137,10 @@ val procedures_attempted : int ref val procedures_failed : int ref +val get_fresh_block_index : unit -> int + +val reset_block_counter : unit -> unit + val reset_global_state : unit -> unit val tableaux_evaluation : bool diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 29c32b338..160f43277 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -2639,11 +2639,14 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s and blockExpr_trans trans_state stmt_info expr_info decl = let context = trans_state.context in - let procname = Procdesc.get_proc_name context.CContext.procdesc in + let outer_proc = Procdesc.get_proc_name context.CContext.procdesc in + let is_cpp = CGeneral_utils.is_cpp_translation context.translation_unit_context in match decl with | Clang_ast_t.BlockDecl (_, block_decl_info) -> let open CContext in - let block_pname = CType_decl.CProcname.mk_fresh_block_procname procname in + let block_pname = + CType_decl.CProcname.from_decl decl ~tenv:context.tenv ~is_cpp ~outer_proc + in let captured_pvars = CVar_decl.captured_vars_from_block_info context stmt_info.Clang_ast_t.si_source_range block_decl_info.Clang_ast_t.bdi_captured_variables