Skip to content

Commit 3524e2b

Browse files
committed
[clang][dataflow] Fix bug in Value comparison.
Makes value equivalence require that the values have no properties, except in the case of equivalence by pointer equality (if the pointers are equal, nothing else is checked). Fixes issue #76459.
1 parent 11ac97c commit 3524e2b

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

clang/lib/Analysis/FlowSensitive/Value.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ static bool areEquivalentIndirectionValues(const Value &Val1,
2727
}
2828

2929
bool areEquivalentValues(const Value &Val1, const Value &Val2) {
30-
return &Val1 == &Val2 || (Val1.getKind() == Val2.getKind() &&
31-
(isa<TopBoolValue>(&Val1) ||
32-
areEquivalentIndirectionValues(Val1, Val2)));
30+
// If values are distinct and have properties, we don't consider them equal,
31+
// leaving equality up to the user model.
32+
return &Val1 == &Val2 ||
33+
(Val1.getKind() == Val2.getKind() &&
34+
(Val1.properties().empty() && Val2.properties().empty()) &&
35+
(isa<TopBoolValue>(&Val1) ||
36+
areEquivalentIndirectionValues(Val1, Val2)));
3337
}
3438

3539
raw_ostream &operator<<(raw_ostream &OS, const Value &Val) {

clang/unittests/Analysis/FlowSensitive/ValueTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ TEST(ValueTest, EquivalentValuesWithDifferentPropsEquivalent) {
5353
TopBoolValue V2(A.makeAtomRef(Atom(3)));
5454
V1.setProperty("foo", Prop1);
5555
V2.setProperty("bar", Prop2);
56-
EXPECT_TRUE(areEquivalentValues(V1, V2));
57-
EXPECT_TRUE(areEquivalentValues(V2, V1));
56+
EXPECT_FALSE(areEquivalentValues(V1, V2));
57+
EXPECT_FALSE(areEquivalentValues(V2, V1));
5858
}
5959

6060
TEST(ValueTest, DifferentKindsNotEquivalent) {

0 commit comments

Comments
 (0)