Avoid casting void* to uint64_t.

- Add new wrapper that accepts const void *.

Change-Id: I1cea088b563cf704b6673844b533ce44f388e5fc
Signed-off-by: Michal Mrozek <michal.mrozek@intel.com>
This commit is contained in:
Michal Mrozek
2019-12-03 10:21:33 +01:00
committed by sys_ocldev
parent ee544e2515
commit 83c0f80431
5 changed files with 31 additions and 2 deletions

View File

@@ -45,6 +45,13 @@ TEST(PtrMath, givenCastToUint64FunctionWhenItIsCalledThenProperValueIsReturned)
auto uintAddress = castToUint64(addressWithTrailingBitSet);
EXPECT_EQ(uintAddress, expectedUint64Address);
}
TEST(PtrMath, givenCastToUint64FunctionWhenConstPointerIsPassedItIsCalledThenProperValueIsReturned) {
uintptr_t address = 0xf0000000;
const void *addressWithTrailingBitSet = reinterpret_cast<const void *>(address);
uint64_t expectedUint64Address = 0xf0000000;
auto uintAddress = castToUint64(addressWithTrailingBitSet);
EXPECT_EQ(uintAddress, expectedUint64Address);
}
TEST(ptrOffset, preserve64Bit) {
uint64_t ptrBefore = 0x800000000;