1 //===- unittests/Analysis/FlowSensitive/ValueTest.cpp ---===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "clang/Analysis/FlowSensitive/Value.h"
10 #include "clang/Analysis/FlowSensitive/Arena.h"
11 #include "clang/Analysis/FlowSensitive/StorageLocation.h"
12 #include "gmock/gmock.h"
13 #include "gtest/gtest.h"
18 using namespace clang
;
19 using namespace dataflow
;
21 TEST(ValueTest
, EquivalenceReflexive
) {
23 EXPECT_TRUE(areEquivalentValues(V
, V
));
26 TEST(ValueTest
, DifferentIntegerValuesNotEquivalent
) {
29 EXPECT_FALSE(areEquivalentValues(V1
, V2
));
32 TEST(ValueTest
, AliasedPointersEquivalent
) {
33 auto L
= ScalarStorageLocation(QualType());
36 EXPECT_TRUE(areEquivalentValues(V1
, V2
));
37 EXPECT_TRUE(areEquivalentValues(V2
, V1
));
40 TEST(ValueTest
, TopsEquivalent
) {
42 TopBoolValue
V1(A
.makeAtomRef(Atom(0)));
43 TopBoolValue
V2(A
.makeAtomRef(Atom(1)));
44 EXPECT_TRUE(areEquivalentValues(V1
, V2
));
45 EXPECT_TRUE(areEquivalentValues(V2
, V1
));
48 TEST(ValueTest
, EquivalentValuesWithDifferentPropsEquivalent
) {
50 TopBoolValue
Prop1(A
.makeAtomRef(Atom(0)));
51 TopBoolValue
Prop2(A
.makeAtomRef(Atom(1)));
52 TopBoolValue
V1(A
.makeAtomRef(Atom(2)));
53 TopBoolValue
V2(A
.makeAtomRef(Atom(3)));
54 V1
.setProperty("foo", Prop1
);
55 V2
.setProperty("bar", Prop2
);
56 EXPECT_TRUE(areEquivalentValues(V1
, V2
));
57 EXPECT_TRUE(areEquivalentValues(V2
, V1
));
60 TEST(ValueTest
, DifferentKindsNotEquivalent
) {
62 auto L
= ScalarStorageLocation(QualType());
64 TopBoolValue
V2(A
.makeAtomRef(Atom(0)));
65 EXPECT_FALSE(areEquivalentValues(V1
, V2
));
66 EXPECT_FALSE(areEquivalentValues(V2
, V1
));
69 TEST(ValueTest
, NotAliasedPointersNotEquivalent
) {
70 auto L1
= ScalarStorageLocation(QualType());
72 auto L2
= ScalarStorageLocation(QualType());
74 EXPECT_FALSE(areEquivalentValues(V1
, V2
));
75 EXPECT_FALSE(areEquivalentValues(V2
, V1
));