1 //===--------- ExecutorAddrTest.cpp - Unit tests for ExecutorAddr ---------===//
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 "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
10 #include "OrcTestCommon.h"
13 using namespace llvm::orc
;
17 TEST(ExecutorAddrTest
, DefaultAndNull
) {
18 // Check that default constructed values and isNull behave as expected.
22 ExecutorAddr
NonNull(1);
24 EXPECT_TRUE(Null
.isNull());
25 EXPECT_EQ(Default
, Null
);
27 EXPECT_FALSE(NonNull
.isNull());
28 EXPECT_NE(Default
, NonNull
);
31 TEST(ExecutorAddrTest
, Ordering
) {
32 // Check that ordering operations.
33 ExecutorAddr
A1(1), A2(2);
41 TEST(ExecutorAddrTest
, PtrConversion
) {
42 // Test toPtr / fromPtr round-tripping.
44 auto XAddr
= ExecutorAddr::fromPtr(&X
);
45 int *XPtr
= XAddr
.toPtr
<int *>();
52 TEST(ExecutorAddrTest
, PtrConversionWithFunctionType
) {
53 // Test that function types (as opposed to function pointer types) can be
55 auto FAddr
= ExecutorAddr::fromPtr(F
);
56 void (*FPtr
)() = FAddr
.toPtr
<void()>();
61 TEST(ExecutorAddrTest
, WrappingAndUnwrapping
) {
62 constexpr uintptr_t RawAddr
= 0x123456;
63 int *RawPtr
= (int *)RawAddr
;
65 constexpr uintptr_t TagOffset
= 8 * (sizeof(uintptr_t) - 1);
66 uintptr_t TagVal
= 0xA5;
67 uintptr_t TagBits
= TagVal
<< TagOffset
;
68 void *TaggedPtr
= (void *)((uintptr_t)RawPtr
| TagBits
);
71 ExecutorAddr::fromPtr(TaggedPtr
, ExecutorAddr::Untag(8, TagOffset
));
73 EXPECT_EQ(EA
.getValue(), RawAddr
);
75 void *ReconstitutedTaggedPtr
=
76 EA
.toPtr
<void *>(ExecutorAddr::Tag(TagVal
, TagOffset
));
78 EXPECT_EQ(TaggedPtr
, ReconstitutedTaggedPtr
);
81 TEST(ExecutorAddrTest
, AddrRanges
) {
82 ExecutorAddr
A0(0), A1(1), A2(2), A3(3);
83 ExecutorAddrRange
R0(A0
, A1
), R1(A1
, A2
), R2(A2
, A3
), R3(A0
, A2
), R4(A1
, A3
);
88 // R3: ## -- Overlaps R1 start
89 // R4: ## -- Overlaps R1 end
91 EXPECT_EQ(R1
, ExecutorAddrRange(A1
, A2
));
92 EXPECT_EQ(R1
, ExecutorAddrRange(A1
, ExecutorAddrDiff(1)));
95 EXPECT_TRUE(R1
.contains(A1
));
96 EXPECT_FALSE(R1
.contains(A0
));
97 EXPECT_FALSE(R1
.contains(A2
));
99 EXPECT_FALSE(R1
.overlaps(R0
));
100 EXPECT_FALSE(R1
.overlaps(R2
));
101 EXPECT_TRUE(R1
.overlaps(R3
));
102 EXPECT_TRUE(R1
.overlaps(R4
));