From 13858e8d09b5f8f235bdef42706ca0e03340c67b Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 4 May 2021 10:06:04 -0700 Subject: [PATCH] [pulse] make sure we do not lose attributes when merging Summary: Losing attributes is a bug, not sure when it would matter. There's a TODO there that's still valid. Reviewed By: da319 Differential Revision: D28125940 fbshipit-source-id: 923ceedb8 --- infer/src/pulse/PulseBaseAddressAttributes.ml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/infer/src/pulse/PulseBaseAddressAttributes.ml b/infer/src/pulse/PulseBaseAddressAttributes.ml index 14c28ab6f..1e8d82447 100644 --- a/infer/src/pulse/PulseBaseAddressAttributes.ml +++ b/infer/src/pulse/PulseBaseAddressAttributes.ml @@ -174,7 +174,15 @@ let canonicalize ~get_var_repr attrs_map = if Attributes.is_empty attrs then g else let addr' = get_var_repr addr in - add addr' attrs g ) + let attrs' = + Graph.find_opt addr' g + |> Option.fold ~init:attrs ~f:(fun attrs attrs' -> + (* "merge" attributes if two different values ([addr] and [addr']) are found to be + equal after attributes of the same kind were recorded for them. This arbitrarily + keeps one of them, with unclear but likely benign consequences. *) + Attributes.union_prefer_left attrs' attrs ) + in + add addr' attrs' g ) attrs_map Graph.empty