diff --git a/infer/src/IR/Fieldname.re b/infer/src/IR/Fieldname.re index 0c41ec3a4..9633521db 100644 --- a/infer/src/IR/Fieldname.re +++ b/infer/src/IR/Fieldname.re @@ -99,6 +99,16 @@ let java_get_field fn => { }; +/** Equality for field names ignoring the struct or class which contains the field. */ +let equal_modulo_parent x y => + switch (x, y) { + | (Hidden, Hidden) => true + | (Clang a, Clang b) => Int.equal 0 (compare_clang_field_info a b) + | (Java _, Java _) => String.equal (java_get_field x) (java_get_field y) + | _ => false + }; + + /** Check if the field is the synthetic this$n of a nested class, used to access the n-th outher instance. */ let java_is_outer_instance fn => { let fn = to_string fn; diff --git a/infer/src/IR/Fieldname.rei b/infer/src/IR/Fieldname.rei index d8a7e71cf..9b398ed48 100644 --- a/infer/src/IR/Fieldname.rei +++ b/infer/src/IR/Fieldname.rei @@ -17,6 +17,10 @@ type t [@@deriving compare]; let equal: t => t => bool; +/** Equality for field names ignoring the struct or class which contains the field. */ +let equal_modulo_parent: t => t => bool; + + /** Set for fieldnames */ module Set: Caml.Set.S with type elt = t; diff --git a/infer/src/checkers/ThreadSafety.ml b/infer/src/checkers/ThreadSafety.ml index 127a4afd4..15d65d1fb 100644 --- a/infer/src/checkers/ThreadSafety.ml +++ b/infer/src/checkers/ThreadSafety.ml @@ -1219,8 +1219,7 @@ let may_alias p1 p2 = match List.last_exn (snd p1), List.last_exn (snd p2) with | FieldAccess _, ArrayAccess _ | ArrayAccess _, FieldAccess _ -> false (* fields in Infer contain class name *) - | FieldAccess f1, FieldAccess f2 -> - String.equal (Fieldname.java_get_field f1) (Fieldname.java_get_field f2) + | FieldAccess f1, FieldAccess f2 -> Fieldname.equal_modulo_parent f1 f2 | ArrayAccess _, ArrayAccess _ -> true (*FIXME*) (* take a results table and quotient it by the may_alias relation *)