From 1d3ad8d791657e8b3ad2bc59f8f28530f1db2fb5 Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Thu, 30 May 2024 00:11:32 +0200 Subject: [PATCH] mem_host_flags: check returned pointer for NULL (#1924) The specification states that `clEnqueueMapImage` and `clEnqueueMapBuffer` should return NULL on error. Ensure this is checked. This testing gap was caught by a compiler warning about `dataPtr` being written but not read. With this fix, there are no more Wunused-but-set-variable warnings in this test, so reenable the warning. Signed-off-by: Sven van Haastregt --- test_conformance/mem_host_flags/CMakeLists.txt | 2 -- .../checker_image_mem_host_no_access.hpp | 16 ++++++++++++++++ .../checker_mem_host_no_access.hpp | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/test_conformance/mem_host_flags/CMakeLists.txt b/test_conformance/mem_host_flags/CMakeLists.txt index 4f2b960d6b..73a36f0d42 100644 --- a/test_conformance/mem_host_flags/CMakeLists.txt +++ b/test_conformance/mem_host_flags/CMakeLists.txt @@ -6,6 +6,4 @@ set(${MODULE_NAME}_SOURCES mem_host_image.cpp ) -set_gnulike_module_compile_flags("-Wno-unused-but-set-variable") - include(../CMakeCommon.txt) diff --git a/test_conformance/mem_host_flags/checker_image_mem_host_no_access.hpp b/test_conformance/mem_host_flags/checker_image_mem_host_no_access.hpp index a6f90d068b..ddcf6adad5 100644 --- a/test_conformance/mem_host_flags/checker_image_mem_host_no_access.hpp +++ b/test_conformance/mem_host_flags/checker_image_mem_host_no_access.hpp @@ -135,6 +135,14 @@ cl_int cImage_check_mem_host_no_access::verify_RW_Image_Mapping() err = FAILURE; return err; } + else if (dataPtr != nullptr) + { + log_error("Calling clEnqueueMapImage (CL_MAP_WRITE) on a memory object " + "created with the CL_MEM_HOST_NO_ACCESS flag should fail " + "and return NULL\n"); + err = FAILURE; + return err; + } else { log_info("Test succeeded\n\n"); @@ -154,6 +162,14 @@ cl_int cImage_check_mem_host_no_access::verify_RW_Image_Mapping() err = FAILURE; return err; } + else if (dataPtr != nullptr) + { + log_error("Calling clEnqueueMapImage (CL_MAP_READ) on a memory object " + "created with the CL_MEM_HOST_NO_ACCESS flag should fail " + "and return NULL\n"); + err = FAILURE; + return err; + } else { log_info("Test succeeded\n\n"); diff --git a/test_conformance/mem_host_flags/checker_mem_host_no_access.hpp b/test_conformance/mem_host_flags/checker_mem_host_no_access.hpp index babbeea919..eb3341a8fa 100644 --- a/test_conformance/mem_host_flags/checker_mem_host_no_access.hpp +++ b/test_conformance/mem_host_flags/checker_mem_host_no_access.hpp @@ -190,6 +190,14 @@ cl_int cBuffer_check_mem_host_no_access::verify_RW_Buffer_mapping() err = FAILURE; return FAILURE; } + else if (dataPtr != nullptr) + { + log_error("Calling clEnqueueMapBuffer (CL_MAP_READ) on a memory object " + "created with the CL_MEM_HOST_NO_ACCESS flag should fail " + "and return NULL\n"); + err = FAILURE; + return err; + } else { log_info("Test succeeded\n\n"); @@ -207,6 +215,15 @@ cl_int cBuffer_check_mem_host_no_access::verify_RW_Buffer_mapping() err = FAILURE; return FAILURE; } + else if (dataPtr != nullptr) + { + log_error( + "Calling clEnqueueMapBuffer (CL_MAP_WRITE) on a memory object " + "created with the CL_MEM_HOST_NO_ACCESS flag should fail " + "and return NULL\n"); + err = FAILURE; + return err; + } else { log_info("Test succeeded\n\n");