[clang] [clang][dataflow] Fix bug in `Value` comparison. (PR #76746)

Yitzhak Mandelbaum via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 3 07:51:33 PST 2024


================
@@ -27,9 +27,13 @@ static bool areEquivalentIndirectionValues(const Value &Val1,
 }
 
 bool areEquivalentValues(const Value &Val1, const Value &Val2) {
-  return &Val1 == &Val2 || (Val1.getKind() == Val2.getKind() &&
-                            (isa<TopBoolValue>(&Val1) ||
-                             areEquivalentIndirectionValues(Val1, Val2)));
+  // If values are distinct and have properties, we don't consider them equal,
+  // leaving equality up to the user model.
+  return &Val1 == &Val2 ||
+         (Val1.getKind() == Val2.getKind() &&
+          (Val1.properties().empty() && Val2.properties().empty()) &&
----------------
ymand wrote:

I think so, based on our experience with Nullability.  This could arise because a pointer on one branch was (somehow) unannotated with properties while the other branch was modeled fully. So, at the join, we want the analysis to see both and decide how to proceed. If we mark them equivalent, the analysis's join (aka `merge`) doesn't see them and it doesn't even get to choose which one is retained (it will depend arbitrarily on whether it came from the left or right).

https://github.com/llvm/llvm-project/pull/76746


More information about the cfe-commits mailing list