| 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 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "clang/Analysis/FlowSensitive/Value.h" |
| 10 |
#include "clang/Analysis/FlowSensitive/StorageLocation.h" |
| 11 |
#include "gmock/gmock.h" |
| 12 |
#include "gtest/gtest.h" |
| 13 |
#include <memory> |
| 14 |
|
| 15 |
namespace { |
| 16 |
|
| 17 |
using namespace clang; |
| 18 |
using namespace dataflow; |
| 19 |
|
| 20 |
TEST(ValueTest, EquivalenceReflexive) { |
| 21 |
StructValue V; |
| 22 |
EXPECT_TRUE(areEquivalentValues(V, V)); |
| 23 |
} |
| 24 |
|
| 25 |
TEST(ValueTest, AliasedReferencesEquivalent) { |
| 26 |
auto L = ScalarStorageLocation(QualType()); |
| 27 |
ReferenceValue V1(L); |
| 28 |
ReferenceValue V2(L); |
| 29 |
EXPECT_TRUE(areEquivalentValues(V1, V2)); |
| 30 |
EXPECT_TRUE(areEquivalentValues(V2, V1)); |
| 31 |
} |
| 32 |
|
| 33 |
TEST(ValueTest, AliasedPointersEquivalent) { |
| 34 |
auto L = ScalarStorageLocation(QualType()); |
| 35 |
PointerValue V1(L); |
| 36 |
PointerValue V2(L); |
| 37 |
EXPECT_TRUE(areEquivalentValues(V1, V2)); |
| 38 |
EXPECT_TRUE(areEquivalentValues(V2, V1)); |
| 39 |
} |
| 40 |
|
| 41 |
TEST(ValueTest, TopsEquivalent) { |
| 42 |
TopBoolValue V1; |
| 43 |
TopBoolValue V2; |
| 44 |
EXPECT_TRUE(areEquivalentValues(V1, V2)); |
| 45 |
EXPECT_TRUE(areEquivalentValues(V2, V1)); |
| 46 |
} |
| 47 |
|
| 48 |
TEST(ValueTest, EquivalentValuesWithDifferentPropsEquivalent) { |
| 49 |
TopBoolValue Prop1; |
| 50 |
TopBoolValue Prop2; |
| 51 |
TopBoolValue V1; |
| 52 |
TopBoolValue V2; |
| 53 |
V1.setProperty("foo", Prop1); |
| 54 |
V2.setProperty("bar", Prop2); |
| 55 |
EXPECT_TRUE(areEquivalentValues(V1, V2)); |
| 56 |
EXPECT_TRUE(areEquivalentValues(V2, V1)); |
| 57 |
} |
| 58 |
|
| 59 |
TEST(ValueTest, DifferentKindsNotEquivalent) { |
| 60 |
auto L = ScalarStorageLocation(QualType()); |
| 61 |
ReferenceValue V1(L); |
| 62 |
TopBoolValue V2; |
| 63 |
EXPECT_FALSE(areEquivalentValues(V1, V2)); |
| 64 |
EXPECT_FALSE(areEquivalentValues(V2, V1)); |
| 65 |
} |
| 66 |
|
| 67 |
TEST(ValueTest, NotAliasedReferencesNotEquivalent) { |
| 68 |
auto L1 = ScalarStorageLocation(QualType()); |
| 69 |
ReferenceValue V1(L1); |
| 70 |
auto L2 = ScalarStorageLocation(QualType()); |
| 71 |
ReferenceValue V2(L2); |
| 72 |
EXPECT_FALSE(areEquivalentValues(V1, V2)); |
| 73 |
EXPECT_FALSE(areEquivalentValues(V2, V1)); |
| 74 |
} |
| 75 |
|
| 76 |
TEST(ValueTest, NotAliasedPointersNotEquivalent) { |
| 77 |
auto L1 = ScalarStorageLocation(QualType()); |
| 78 |
PointerValue V1(L1); |
| 79 |
auto L2 = ScalarStorageLocation(QualType()); |
| 80 |
PointerValue V2(L2); |
| 81 |
EXPECT_FALSE(areEquivalentValues(V1, V2)); |
| 82 |
EXPECT_FALSE(areEquivalentValues(V2, V1)); |
| 83 |
} |
| 84 |
|
| 85 |
} // namespace |