[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
[llvm-project.git] / libcxx / test / support / pointer_comparison_test_helper.h
blob716366afce427977dac7d1dd69cad76f26603af2
1 //===----------------------------------------------------------------------===//
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 #ifndef POINTER_COMPARISON_TEST_HELPER_H
10 #define POINTER_COMPARISON_TEST_HELPER_H
12 #include <cstdint>
13 #include <cassert>
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;
21 #if TEST_STD_VER > 11
22 typedef CompareTemplate<void> VoidCompare;
23 #else
24 typedef Compare VoidCompare;
25 #endif
27 Compare comp;
28 UIntCompare ucomp;
29 VoidCompare vcomp;
30 struct {
31 int a, b;
32 } local;
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));
44 template <class Comp>
45 void do_pointer_comparison_test(Comp comp) {
46 struct {
47 int a, b;
48 } local;
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