diff --git a/projects/clr/hipamd/src/hip_memory.cpp b/projects/clr/hipamd/src/hip_memory.cpp index 0cfd93f77a..45244291ec 100644 --- a/projects/clr/hipamd/src/hip_memory.cpp +++ b/projects/clr/hipamd/src/hip_memory.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2015 - 2024 Advanced Micro Devices, Inc. +/* Copyright (c) 2015 - 2025 Advanced Micro Devices, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -829,6 +829,11 @@ hipError_t hipMemcpyWithStream(void* dst, const void* src, size_t sizeBytes, hip hipError_t hipMemPtrGetInfo(void* ptr, size_t* size) { HIP_INIT_API(hipMemPtrGetInfo, ptr, size); + if (ptr == nullptr) { + *size = 0; + HIP_RETURN(hipSuccess); + } + size_t offset = 0; amd::Memory* svmMem = getMemoryObject(ptr, offset); diff --git a/projects/hip-tests/catch/unit/memory/hipMemPtrGetInfo.cc b/projects/hip-tests/catch/unit/memory/hipMemPtrGetInfo.cc index c09cdd3d73..5f9a574b35 100644 --- a/projects/hip-tests/catch/unit/memory/hipMemPtrGetInfo.cc +++ b/projects/hip-tests/catch/unit/memory/hipMemPtrGetInfo.cc @@ -1,5 +1,5 @@ /* -Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2021 - 2025 Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -56,3 +56,17 @@ TEST_CASE("Unit_hipMemPtrGetInfo_Basic") { HIP_CHECK(hipFree(fPtr)); HIP_CHECK(hipFree(sPtr)); } + +/* +This testcase verifies the scenario of +hipMemPtrGetInfo API being called on a zero-sized allocation. +*/ +TEST_CASE("Unit_hipMemPtrGetInfo_SizeZeroAllocation") { + int* iPtr; + size_t sSetSize = 0, sGetSize; + HIP_CHECK(hipMalloc(&iPtr, sSetSize)); + HIP_CHECK(hipMemPtrGetInfo(iPtr, &sGetSize)); + REQUIRE(sGetSize == sSetSize); + + HIP_CHECK(hipFree(iPtr)); +}