[clang-format] Fix a bug in aligning comments above PPDirective (#72791)
[llvm-project.git] / clang / unittests / Analysis / FlowSensitive / ValueTest.cpp
blobc5d18ba74c3ed6b02dbc8daeebc78b16591d76c8
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 TEST(ValueTest, EquivalentValuesWithDifferentPropsEquivalent) {
49 Arena A;
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) {
61 Arena A;
62 auto L = ScalarStorageLocation(QualType());
63 PointerValue V1(L);
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());
71 PointerValue V1(L1);
72 auto L2 = ScalarStorageLocation(QualType());
73 PointerValue V2(L2);
74 EXPECT_FALSE(areEquivalentValues(V1, V2));
75 EXPECT_FALSE(areEquivalentValues(V2, V1));
78 } // namespace