Skip to content

Commit bed99f8

Browse files
committed
Improve code for edge cases testing.
- Changes to 'asan_hsa_amd_pointer_info' - Initialize status with default value 'HSA_STATUS_ERROR_NOT_INITIALIZE'. - Assure by adding ternary condition to check if ptr_ is not nullptr when calling GetASanChunkByAddr.
1 parent bdabcd4 commit bed99f8

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

compiler-rt/lib/asan/asan_allocator.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,18 +1554,21 @@ hsa_status_t asan_hsa_amd_pointer_info(const void* ptr,
15541554
uint32_t* num_agents_accessible,
15551555
hsa_agent_t** accessible) {
15561556
void* ptr_ = get_allocator().GetBlockBegin(ptr);
1557-
AsanChunk* m = instance.GetAsanChunkByAddr(reinterpret_cast<uptr>(ptr_));
1558-
hsa_status_t status;
1559-
if (ptr_ && m)
1557+
AsanChunk* m = ptr_
1558+
? instance.GetAsanChunkByAddr(reinterpret_cast<uptr>(ptr_))
1559+
: nullptr;
1560+
hsa_status_t status = HSA_STATUS_ERROR_NOT_INITIALIZED;
1561+
if (ptr_ && m) {
15601562
status = REAL(hsa_amd_pointer_info)(ptr, info, alloc, num_agents_accessible,
15611563
accessible);
1562-
if (status == HSA_STATUS_SUCCESS && info && ptr_ && m) {
1563-
static_assert(AP_.kMetadataSize == 0, "Expression below requires this");
1564-
info->agentBaseAddress = reinterpret_cast<void*>(
1565-
reinterpret_cast<uptr>(info->agentBaseAddress) + kPageSize_);
1566-
info->hostBaseAddress = reinterpret_cast<void*>(
1567-
reinterpret_cast<uptr>(info->hostBaseAddress) + kPageSize_);
1568-
info->sizeInBytes = m->UsedSize();
1564+
if (status == HSA_STATUS_SUCCESS && info) {
1565+
static_assert(AP_.kMetadataSize == 0, "Expression below requires this");
1566+
info->agentBaseAddress = reinterpret_cast<void*>(
1567+
reinterpret_cast<uptr>(info->agentBaseAddress) + kPageSize_);
1568+
info->hostBaseAddress = reinterpret_cast<void*>(
1569+
reinterpret_cast<uptr>(info->hostBaseAddress) + kPageSize_);
1570+
info->sizeInBytes = m->UsedSize();
1571+
}
15691572
}
15701573
return status;
15711574
}

0 commit comments

Comments
 (0)