From fd13e74b8de7799b3190f66dbd47cd09497378ba Mon Sep 17 00:00:00 2001 From: "Sv. Lockal" Date: Wed, 22 May 2024 10:04:00 +0000 Subject: [PATCH] Fix compilation errors with musl libc 1. `error.h` is a GNU extension and is not provided by musl. Replaced with fprintf. 2. NULL is defined to `std::nullptr_t`, reinterpret_cast from `std::nullptr_t` to `void **` is not allowed. But static_cast is allowed.[1] [1] https://en.cppreference.com/w/cpp/language/reinterpret_cast#:~:text=Note%20that%20the%20null%20pointer,be%20used%20for%20this%20purpose. Signed-off-by: Sv. Lockal --- catch/unit/kernel/printf_common.h | 13 ++++++------- catch/unit/memory/hipMemRangeGetAttributes_old.cc | 2 +- .../hipOccupancyMaxActiveBlocksPerMultiprocessor.cc | 2 +- ...OccupancyMaxActiveBlocksPerMultiprocessor_old.cc | 2 +- .../hipOccupancyMaxPotentialBlockSize_old.cc | 2 +- catch/unit/rtc/headers/printf_common.h | 13 ++++++------- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/catch/unit/kernel/printf_common.h b/catch/unit/kernel/printf_common.h index 36c512d2a..2fc4999f5 100644 --- a/catch/unit/kernel/printf_common.h +++ b/catch/unit/kernel/printf_common.h @@ -24,7 +24,6 @@ THE SOFTWARE. #define _STRESSTEST_PRINTF_COMMON_H_ #include -#include #include #include #include @@ -47,17 +46,17 @@ struct CaptureStream { saved_fd = dup(orig_fd); if ((temp_fd = mkstemp(tempname)) == -1) { - error(0, errno, "Error"); + fprintf(stderr, "Error: %s\n", strerror(errno)); assert(false); } fflush(nullptr); if (dup2(temp_fd, orig_fd) == -1) { - error(0, errno, "Error"); + fprintf(stderr, "Error: %s\n", strerror(errno)); assert(false); } if (close(temp_fd) != 0) { - error(0, errno, "Error"); + fprintf(stderr, "Error: %s\n", strerror(errno)); assert(false); } } @@ -67,11 +66,11 @@ struct CaptureStream { return; fflush(nullptr); if (dup2(saved_fd, orig_fd) == -1) { - error(0, errno, "Error"); + fprintf(stderr, "Error: %s\n", strerror(errno)); assert(false); } if (close(saved_fd) != 0) { - error(0, errno, "Error"); + fprintf(stderr, "Error: %s\n", strerror(errno)); assert(false); } saved_fd = -1; @@ -90,7 +89,7 @@ struct CaptureStream { ~CaptureStream() { restoreStream(); if (remove(tempname) != 0) { - error(0, errno, "Error"); + fprintf(stderr, "Error: %s\n", strerror(errno)); assert(false); } } diff --git a/catch/unit/memory/hipMemRangeGetAttributes_old.cc b/catch/unit/memory/hipMemRangeGetAttributes_old.cc index 63952f1bf..f2e3dd5a6 100644 --- a/catch/unit/memory/hipMemRangeGetAttributes_old.cc +++ b/catch/unit/memory/hipMemRangeGetAttributes_old.cc @@ -268,7 +268,7 @@ TEST_CASE("Unit_hipMemRangeGetAttributes_NegativeTst") { // Passing NULL as first parameter SECTION("Passing NULL as first parameter") { if (!CheckError(hipMemRangeGetAttributes( - reinterpret_cast(NULL), + static_cast(NULL), reinterpret_cast(dataSizes), AttrArr, 4, Hmm, MEM_SIZE), __LINE__)) { diff --git a/catch/unit/occupancy/hipOccupancyMaxActiveBlocksPerMultiprocessor.cc b/catch/unit/occupancy/hipOccupancyMaxActiveBlocksPerMultiprocessor.cc index 6199f45c3..58978f440 100644 --- a/catch/unit/occupancy/hipOccupancyMaxActiveBlocksPerMultiprocessor.cc +++ b/catch/unit/occupancy/hipOccupancyMaxActiveBlocksPerMultiprocessor.cc @@ -48,7 +48,7 @@ TEST_CASE("Unit_hipOccupancyMaxActiveBlocksPerMultiprocessor_Negative_Parameters blockSize); SECTION("Kernel function is NULL") { - HIP_CHECK_ERROR(hipOccupancyMaxActiveBlocksPerMultiprocessor(&numBlocks, NULL, blockSize, 0), + HIP_CHECK_ERROR(hipOccupancyMaxActiveBlocksPerMultiprocessor(&numBlocks, static_cast(NULL), blockSize, 0), hipErrorInvalidDeviceFunction); } } diff --git a/catch/unit/occupancy/hipOccupancyMaxActiveBlocksPerMultiprocessor_old.cc b/catch/unit/occupancy/hipOccupancyMaxActiveBlocksPerMultiprocessor_old.cc index e6fdb3ba0..5e800f4b5 100644 --- a/catch/unit/occupancy/hipOccupancyMaxActiveBlocksPerMultiprocessor_old.cc +++ b/catch/unit/occupancy/hipOccupancyMaxActiveBlocksPerMultiprocessor_old.cc @@ -40,7 +40,7 @@ TEST_CASE("Unit_hipOccupancyMaxActiveBlocksPerMultiprocessor_Negative") { ret = hipOccupancyMaxActiveBlocksPerMultiprocessor(NULL, f1, blockSize, 0); REQUIRE(ret != hipSuccess); - ret = hipOccupancyMaxActiveBlocksPerMultiprocessor(&numBlock, NULL, blockSize, 0); + ret = hipOccupancyMaxActiveBlocksPerMultiprocessor(&numBlock, static_cast(NULL), blockSize, 0); REQUIRE(ret != hipSuccess); ret = hipOccupancyMaxActiveBlocksPerMultiprocessor(&numBlock, f1, 0, 0); diff --git a/catch/unit/occupancy/hipOccupancyMaxPotentialBlockSize_old.cc b/catch/unit/occupancy/hipOccupancyMaxPotentialBlockSize_old.cc index e31988a55..e60d98ea2 100644 --- a/catch/unit/occupancy/hipOccupancyMaxPotentialBlockSize_old.cc +++ b/catch/unit/occupancy/hipOccupancyMaxPotentialBlockSize_old.cc @@ -37,7 +37,7 @@ TEST_CASE("Unit_hipOccupancyMaxPotentialBlockSize_Negative") { #ifndef __HIP_PLATFORM_NVIDIA__ // nvcc doesnt support kernelfunc(NULL) for api - ret = hipOccupancyMaxPotentialBlockSize(&gridSize, &blockSize, NULL, 0, 0); + ret = hipOccupancyMaxPotentialBlockSize(&gridSize, &blockSize, static_cast(NULL), 0, 0); REQUIRE(ret != hipSuccess); #endif } diff --git a/catch/unit/rtc/headers/printf_common.h b/catch/unit/rtc/headers/printf_common.h index b42110bab..ee2c2f593 100644 --- a/catch/unit/rtc/headers/printf_common.h +++ b/catch/unit/rtc/headers/printf_common.h @@ -30,7 +30,6 @@ THE SOFTWARE. #if defined(_WIN32) #include #else -#include #include #endif @@ -110,7 +109,7 @@ struct CaptureStream { saved_fd = dup(orig_fd); if ((temp_fd = mkstemp(tempname)) == -1) { - error(0, errno, "Error"); + fprintf(stderr, "Error: %s\n", strerror(errno)); assert(false); } } @@ -118,11 +117,11 @@ struct CaptureStream { void Begin() { fflush(nullptr); if (dup2(temp_fd, orig_fd) == -1) { - error(0, errno, "Error"); + fprintf(stderr, "Error: %s\n", strerror(errno)); assert(false); } if (close(temp_fd) != 0) { - error(0, errno, "Error"); + fprintf(stderr, "Error: %s\n", strerror(errno)); assert(false); } } @@ -130,11 +129,11 @@ struct CaptureStream { void End() { fflush(nullptr); if (dup2(saved_fd, orig_fd) == -1) { - error(0, errno, "Error"); + fprintf(stderr, "Error: %s\n", strerror(errno)); assert(false); } if (close(saved_fd) != 0) { - error(0, errno, "Error"); + fprintf(stderr, "Error: %s\n", strerror(errno)); assert(false); } } @@ -148,7 +147,7 @@ struct CaptureStream { ~CaptureStream() { if (remove(tempname) != 0) { - error(0, errno, "Error"); + fprintf(stderr, "Error: %s\n", strerror(errno)); assert(false); } }