1 //===----------------------------------------------------------------------===//
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 #ifndef POINTER_COMPARISON_TEST_HELPER_H
10 #define POINTER_COMPARISON_TEST_HELPER_H
15 #include "test_macros.h"
17 template <template <class> class CompareTemplate
>
18 void do_pointer_comparison_test() {
19 typedef CompareTemplate
<int*> Compare
;
20 typedef CompareTemplate
<std::uintptr_t> UIntCompare
;
22 typedef CompareTemplate
<void> VoidCompare
;
24 typedef Compare VoidCompare
;
33 int* pointers
[] = {&local
.a
, &local
.b
, nullptr, &local
.a
+ 1};
34 for (int* lhs
: pointers
) {
35 for (int* rhs
: pointers
) {
36 std::uintptr_t lhs_uint
= reinterpret_cast<std::uintptr_t>(lhs
);
37 std::uintptr_t rhs_uint
= reinterpret_cast<std::uintptr_t>(rhs
);
38 assert(comp(lhs
, rhs
) == ucomp(lhs_uint
, rhs_uint
));
39 assert(vcomp(lhs
, rhs
) == ucomp(lhs_uint
, rhs_uint
));
45 void do_pointer_comparison_test(Comp comp
) {
49 int* pointers
[] = {&local
.a
, &local
.b
, nullptr, &local
.a
+ 1};
50 for (int* lhs
: pointers
) {
51 for (int* rhs
: pointers
) {
52 std::uintptr_t lhs_uint
= reinterpret_cast<std::uintptr_t>(lhs
);
53 std::uintptr_t rhs_uint
= reinterpret_cast<std::uintptr_t>(rhs
);
54 void* lhs_void
= static_cast<void*>(lhs
);
55 void* rhs_void
= static_cast<void*>(rhs
);
56 assert(comp(lhs
, rhs
) == comp(lhs_uint
, rhs_uint
));
57 assert(comp(lhs_void
, rhs_void
) == comp(lhs_uint
, rhs_uint
));
62 #endif // POINTER_COMPARISON_TEST_HELPER_H