3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00
This commit is contained in:
Jakob Rath 2023-07-17 13:40:52 +02:00
parent 8c17e231ad
commit 82b1f9297b
3 changed files with 20 additions and 4 deletions

View file

@ -43,4 +43,15 @@ Revision History:
#define UNBOXINT(PTR) static_cast<int>(reinterpret_cast<uintptr_t>(PTR) >> PTR_ALIGNMENT)
template <typename U, typename T>
U unbox(T* ptr) {
return static_cast<U>(reinterpret_cast<std::uintptr_t>(ptr) >> PTR_ALIGNMENT);
}
template <typename T, typename U>
T* box(U val) {
static_assert( sizeof(T*) >= sizeof(U) + PTR_ALIGNMENT );
T* ptr = reinterpret_cast<T*>(static_cast<std::uintptr_t>(val) << PTR_ALIGNMENT);
SASSERT_EQ(val, unbox<U>(ptr)); // roundtrip of conversion integer -> pointer -> integer is not actually guaranteed by the C++ standard (but seems fine in practice, as indicated by previous usage of BOXINT/UNBOXINT)
return ptr;
}