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

via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 8 03:15:25 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()) &&
+          (isa<TopBoolValue>(&Val1) ||
+           areEquivalentIndirectionValues(Val1, Val2)));
----------------
martinboehme wrote:

Converting the nested boolean formula into a sequence of early-out checks would make this eaiser to read IMO. It also makes it easier to anchor the comment to the line that it actually refers to.

```suggestion
  if (&Val1 == &Val2) return true;
  if (Val1.getKind() != Val2.getKind()) return false;
  // If values are distinct and have properties, we don't consider them equal,
  // leaving equality up to the user model.
  if (!Val1.properties().empty() || !Val2.properties().empty()) return false;
  if (isa<TopBoolValue>(&Val1)) return true;
  return areEquivalentIndirectionValues(Val1, Val2);
```

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


More information about the cfe-commits mailing list