[infer] make sure adding or removing parameters does not affect the bug hash on Objective C methods

Summary: As Dulma pointed out, adding or removing paramters in a method in Objective C is changing the name of the method. Such changes should not make pre-exisiting issues reported as introduced. This diff is to prevent this by only keeping in the bug hash the part of the name that is before the first colon.

Reviewed By: dulmarod

Differential Revision: D6491215

fbshipit-source-id: 3c00fae
master
Jeremy Dubreil 7 years ago committed by Facebook Github Bot
parent 6799e7a7fb
commit 75de2006dd

@ -1071,6 +1071,23 @@ module Procname = struct
to_unique_id p to_unique_id p
let hashable_name p =
match p with
| Java pname ->
(* Strip autogenerated anonymous inner class numbers in order to keep the bug hash
invariant when introducing new annonynous classes *)
Str.global_replace (Str.regexp "$[0-9]+") "$_"
(java_to_string ~withclass:true pname Simple)
| ObjC_Cpp _ when is_objc_method p ->
(* In Objective C, the list of parameters is part of the method name. To prevent the bug
hash to change when a parameter is introduced or removed, only the part of the name
before the first colon is used for the bug hash *)
List.hd_exn (String.split_on_chars (to_simplified_string ~withclass:true p) ~on:[':'])
| _ ->
(* Other cases for C and C++ method names *)
to_simplified_string ~withclass:true p
(** Pretty print a proc name *) (** Pretty print a proc name *)
let pp f pn = F.fprintf f "%s" (to_string pn) let pp f pn = F.fprintf f "%s" (to_string pn)

@ -522,6 +522,9 @@ module Procname : sig
val to_simplified_string : ?withclass:bool -> t -> string val to_simplified_string : ?withclass:bool -> t -> string
(** Convert a proc name into a easy string for the user to see in an IDE. *) (** Convert a proc name into a easy string for the user to see in an IDE. *)
val hashable_name : t -> string
(** Print the procedure name in a format suitable for computing the bug hash *)
val to_unique_id : t -> string val to_unique_id : t -> string
(** Convert a proc name into a unique identifier. *) (** Convert a proc name into a unique identifier. *)

@ -48,19 +48,14 @@ let error_desc_to_dotty_string error_desc = Localise.error_desc_get_dotty error_
let compute_hash (kind: string) (type_str: string) (proc_name: Typ.Procname.t) (filename: string) let compute_hash (kind: string) (type_str: string) (proc_name: Typ.Procname.t) (filename: string)
(qualifier: string) = (qualifier: string) =
let base_filename = Filename.basename filename in let base_filename = Filename.basename filename in
let simple_procedure_name = let hashable_procedure_name = Typ.Procname.hashable_name proc_name in
(* Force the anonymous inner class to have the same class by removing the index
in order to make the hash invariant when introducing new annonynous classes *)
Str.global_replace (Str.regexp "[0-9]+") "_"
(Typ.Procname.to_simplified_string ~withclass:true proc_name)
in
let location_independent_qualifier = let location_independent_qualifier =
(* Removing the line and column information from the error message to make the (* Removing the line and column information from the error message to make the
hash invariant when moving the source code in the file *) hash invariant when moving the source code in the file *)
Str.global_replace (Str.regexp "\\(line\\|column\\)\\ [0-9]+") "_" qualifier Str.global_replace (Str.regexp "\\(line\\|column\\)\\ [0-9]+") "_" qualifier
in in
Utils.better_hash Utils.better_hash
(kind, type_str, simple_procedure_name, base_filename, location_independent_qualifier) (kind, type_str, hashable_procedure_name, base_filename, location_independent_qualifier)
|> Digest.to_hex |> Digest.to_hex

@ -10,8 +10,8 @@ codetoanalyze/cpp/siof/siof/siof.cpp, __infer_globals_initializer_initWithGlobal
codetoanalyze/cpp/siof/siof/siof.cpp, __infer_globals_initializer_initWithGlobal_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of initWithGlobal_bad,call to getGlobalNonPOD,access to some_other_global_object2|codetoanalyze/cpp/siof/siof/siof_different_tu.cpp] codetoanalyze/cpp/siof/siof/siof.cpp, __infer_globals_initializer_initWithGlobal_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of initWithGlobal_bad,call to getGlobalNonPOD,access to some_other_global_object2|codetoanalyze/cpp/siof/siof/siof_different_tu.cpp]
codetoanalyze/cpp/siof/siof/siof.cpp, __infer_globals_initializer_pod_accesses_non_pod_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of pod_accesses_non_pod_bad,call to access_to_non_pod,access to global_object2|codetoanalyze/cpp/siof/siof/siof_different_tu.cpp] codetoanalyze/cpp/siof/siof/siof.cpp, __infer_globals_initializer_pod_accesses_non_pod_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of pod_accesses_non_pod_bad,call to access_to_non_pod,access to global_object2|codetoanalyze/cpp/siof/siof/siof_different_tu.cpp]
codetoanalyze/cpp/siof/siof/siof.cpp, __infer_globals_initializer_pod_accesses_non_pod_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of pod_accesses_non_pod_bad,call to access_to_non_pod,access to some_other_global_object2|codetoanalyze/cpp/siof/siof/siof_different_tu.cpp] codetoanalyze/cpp/siof/siof/siof.cpp, __infer_globals_initializer_pod_accesses_non_pod_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of pod_accesses_non_pod_bad,call to access_to_non_pod,access to some_other_global_object2|codetoanalyze/cpp/siof/siof/siof_different_tu.cpp]
codetoanalyze/cpp/siof/siof/siof_templated.cpp, __infer_globals_initializer_another_templated_global_object2_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_templated_global_object2_bad,call to access_to_non_pod,access to some_other_global_object2|codetoanalyze/cpp/siof/siof/siof_different_tu.cpp]
codetoanalyze/cpp/siof/siof/siof_templated.cpp, __infer_globals_initializer_another_templated_global_object2_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_templated_global_object2_bad,call to access_to_non_pod,access to global_object2|codetoanalyze/cpp/siof/siof/siof_different_tu.cpp] codetoanalyze/cpp/siof/siof/siof_templated.cpp, __infer_globals_initializer_another_templated_global_object2_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_templated_global_object2_bad,call to access_to_non_pod,access to global_object2|codetoanalyze/cpp/siof/siof/siof_different_tu.cpp]
codetoanalyze/cpp/siof/siof/siof_templated.cpp, __infer_globals_initializer_another_templated_global_object2_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_templated_global_object2_bad,call to access_to_non_pod,access to some_other_global_object2|codetoanalyze/cpp/siof/siof/siof_different_tu.cpp]
codetoanalyze/cpp/siof/siof/siof_templated.cpp, __infer_globals_initializer_another_templated_global_object3_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_templated_global_object3_bad,call to access_to_templated_non_pod,access to global_object3|codetoanalyze/cpp/siof/siof/siof_different_tu.cpp] codetoanalyze/cpp/siof/siof/siof_templated.cpp, __infer_globals_initializer_another_templated_global_object3_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_templated_global_object3_bad,call to access_to_templated_non_pod,access to global_object3|codetoanalyze/cpp/siof/siof/siof_different_tu.cpp]
codetoanalyze/cpp/siof/siof/siof_templated.cpp, __infer_globals_initializer_another_templated_global_object_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_templated_global_object_bad,call to SomeOtherTemplatedNonPODObject<_Bool>_SomeOtherTemplatedNonPODObject,access to extern_global_object|EXTERN] codetoanalyze/cpp/siof/siof/siof_templated.cpp, __infer_globals_initializer_another_templated_global_object_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_templated_global_object_bad,call to SomeOtherTemplatedNonPODObject<_Bool>_SomeOtherTemplatedNonPODObject,access to extern_global_object|EXTERN]
codetoanalyze/cpp/siof/siof/std_ios_base_init.cpp, __infer_globals_initializer_global_std_cerr_access_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of global_std_cerr_access_bad,call to return_4_SIOF,call to printing_SIOF,access to std::cerr|EXTERN] codetoanalyze/cpp/siof/siof/std_ios_base_init.cpp, __infer_globals_initializer_global_std_cerr_access_bad, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of global_std_cerr_access_bad,call to return_4_SIOF,call to printing_SIOF,access to std::cerr|EXTERN]

Loading…
Cancel
Save