[RISCV] Fix the cost of `llvm.vector.reduce.and` (#119160)
[llvm-project.git] / clang / unittests / Analysis / FlowSensitive / ValueTest.cpp
blobb07328d2a5621537b83ca0020610422775ede04d
1 //===- unittests/Analysis/FlowSensitive/ValueTest.cpp ---===//
2 //
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
6 //
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"
14 #include <memory>
16 namespace {
18 using namespace clang;
19 using namespace dataflow;
21 TEST(ValueTest, EquivalenceReflexive) {
22 IntegerValue V;
23 EXPECT_TRUE(areEquivalentValues(V, V));
26 TEST(ValueTest, DifferentIntegerValuesNotEquivalent) {
27 IntegerValue V1;
28 IntegerValue V2;
29 EXPECT_FALSE(areEquivalentValues(V1, V2));
32 TEST(ValueTest, AliasedPointersEquivalent) {
33 auto L = ScalarStorageLocation(QualType());
34 PointerValue V1(L);
35 PointerValue V2(L);
36 EXPECT_TRUE(areEquivalentValues(V1, V2));
37 EXPECT_TRUE(areEquivalentValues(V2, V1));
40 TEST(ValueTest, TopsEquivalent) {
41 Arena A;
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 // The framework does not (currently) consider equivalence for values with
49 // properties, leaving such to individual analyses.
50 TEST(ValueTest, ValuesWithSamePropsDifferent) {
51 Arena A;
52 TopBoolValue Prop(A.makeAtomRef(Atom(0)));
53 TopBoolValue V1(A.makeAtomRef(Atom(2)));
54 TopBoolValue V2(A.makeAtomRef(Atom(3)));
55 V1.setProperty("foo", Prop);
56 V2.setProperty("foo", Prop);
57 EXPECT_FALSE(areEquivalentValues(V1, V2));
58 EXPECT_FALSE(areEquivalentValues(V2, V1));
61 TEST(ValueTest, ValuesWithDifferentPropsDifferent) {
62 Arena A;
63 TopBoolValue Prop1(A.makeAtomRef(Atom(0)));
64 TopBoolValue Prop2(A.makeAtomRef(Atom(1)));
65 TopBoolValue V1(A.makeAtomRef(Atom(2)));
66 TopBoolValue V2(A.makeAtomRef(Atom(3)));
67 V1.setProperty("foo", Prop1);
68 V2.setProperty("bar", Prop2);
69 EXPECT_FALSE(areEquivalentValues(V1, V2));
70 EXPECT_FALSE(areEquivalentValues(V2, V1));
73 TEST(ValueTest, ValuesWithDifferentNumberPropsDifferent) {
74 Arena A;
75 TopBoolValue Prop(A.makeAtomRef(Atom(0)));
76 TopBoolValue V1(A.makeAtomRef(Atom(2)));
77 TopBoolValue V2(A.makeAtomRef(Atom(3)));
78 // Only set a property on `V1`.
79 V1.setProperty("foo", Prop);
80 EXPECT_FALSE(areEquivalentValues(V1, V2));
81 EXPECT_FALSE(areEquivalentValues(V2, V1));
84 TEST(ValueTest, DifferentKindsNotEquivalent) {
85 Arena A;
86 auto L = ScalarStorageLocation(QualType());
87 PointerValue V1(L);
88 TopBoolValue V2(A.makeAtomRef(Atom(0)));
89 EXPECT_FALSE(areEquivalentValues(V1, V2));
90 EXPECT_FALSE(areEquivalentValues(V2, V1));
93 TEST(ValueTest, NotAliasedPointersNotEquivalent) {
94 auto L1 = ScalarStorageLocation(QualType());
95 PointerValue V1(L1);
96 auto L2 = ScalarStorageLocation(QualType());
97 PointerValue V2(L2);
98 EXPECT_FALSE(areEquivalentValues(V1, V2));
99 EXPECT_FALSE(areEquivalentValues(V2, V1));
102 } // namespace