From 044e0be65321690ae18cae555b84ccf0c163e5a7 Mon Sep 17 00:00:00 2001 From: Ahmed Hesham <117350656+ahesham-arm@users.noreply.github.com> Date: Thu, 31 Jul 2025 12:24:03 +0100 Subject: [PATCH] Enable -Wnarrowing for the basic test suite (#2467) Fixes #1156 --------- Signed-off-by: Ahmed Hesham --- test_conformance/basic/CMakeLists.txt | 4 --- test_conformance/basic/test_arraycopy.cpp | 2 +- .../basic/test_arrayimagecopy.cpp | 6 ++-- test_conformance/basic/test_hostptr.cpp | 4 +-- test_conformance/basic/test_if.cpp | 5 +-- .../basic/test_image_multipass.cpp | 8 ++--- .../basic/test_imagearraycopy.cpp | 6 ++-- test_conformance/basic/test_imagecopy.cpp | 15 ++++---- test_conformance/basic/test_imagecopy3d.cpp | 6 ++-- test_conformance/basic/test_imagenpot.cpp | 4 +-- .../basic/test_imagerandomcopy.cpp | 10 +++--- .../basic/test_imagereadwrite.cpp | 21 ++++++----- .../basic/test_imagereadwrite3d.cpp | 35 ++++++++++++------- .../test_kernel_call_kernel_function.cpp | 2 +- .../basic/test_multireadimagemultifmt.cpp | 4 +-- .../basic/test_multireadimageonefmt.cpp | 4 +-- 16 files changed, 73 insertions(+), 63 deletions(-) diff --git a/test_conformance/basic/CMakeLists.txt b/test_conformance/basic/CMakeLists.txt index 7292bc9d..bf1f3bd6 100644 --- a/test_conformance/basic/CMakeLists.txt +++ b/test_conformance/basic/CMakeLists.txt @@ -1,9 +1,5 @@ set(MODULE_NAME BASIC) -if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang") - add_cxx_flag_if_supported(-Wno-narrowing) -endif() - set(${MODULE_NAME}_SOURCES main.cpp test_fpmath.cpp diff --git a/test_conformance/basic/test_arraycopy.cpp b/test_conformance/basic/test_arraycopy.cpp index a981cd02..332b10e2 100644 --- a/test_conformance/basic/test_arraycopy.cpp +++ b/test_conformance/basic/test_arraycopy.cpp @@ -161,7 +161,7 @@ REGISTER_TEST(arraycopy) err |= clSetKernelArg(kernel, 1, sizeof results, &results); test_error(err, "clSetKernelArg failed"); - size_t threads[3] = { num_elements, 0, 0 }; + size_t threads[3] = { static_cast(num_elements), 0, 0 }; err = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, NULL, 0, NULL, NULL ); test_error(err, "clEnqueueNDRangeKernel failed"); diff --git a/test_conformance/basic/test_arrayimagecopy.cpp b/test_conformance/basic/test_arrayimagecopy.cpp index 8a8f9381..bb44abff 100644 --- a/test_conformance/basic/test_arrayimagecopy.cpp +++ b/test_conformance/basic/test_arrayimagecopy.cpp @@ -35,9 +35,9 @@ static int test_arrayimagecopy_single_format( std::unique_ptr bufptr{ nullptr, free }, imgptr{ nullptr, free }; clMemWrapper buffer, image; - int img_width = 512; - int img_height = 512; - int img_depth = (image_type == CL_MEM_OBJECT_IMAGE3D) ? 32 : 1; + size_t img_width = 512; + size_t img_height = 512; + size_t img_depth = (image_type == CL_MEM_OBJECT_IMAGE3D) ? 32 : 1; size_t elem_size; size_t buffer_size; cl_int err; diff --git a/test_conformance/basic/test_hostptr.cpp b/test_conformance/basic/test_hostptr.cpp index e58b636e..9f3f700e 100644 --- a/test_conformance/basic/test_hostptr.cpp +++ b/test_conformance/basic/test_hostptr.cpp @@ -100,8 +100,8 @@ REGISTER_TEST(hostptr) cl_image_format img_format; cl_uchar *rgba8_inptr, *rgba8_outptr; void *lock_buffer; - int img_width = 512; - int img_height = 512; + size_t img_width = 512; + size_t img_height = 512; cl_int err; MTdata d; RoundingMode oldRoundMode; diff --git a/test_conformance/basic/test_if.cpp b/test_conformance/basic/test_if.cpp index a0640879..b6b8c449 100644 --- a/test_conformance/basic/test_if.cpp +++ b/test_conformance/basic/test_if.cpp @@ -56,8 +56,9 @@ __kernel void test_if(__global int *src, __global int *dst) int verify_if(std::vector input, std::vector output) { const cl_int results[] = { - 0x12345678, 0x23456781, 0x34567812, 0x45678123, - 0x56781234, 0x67812345, 0x78123456, 0x81234567, + (cl_int)0x12345678, (cl_int)0x23456781, (cl_int)0x34567812, + (cl_int)0x45678123, (cl_int)0x56781234, (cl_int)0x67812345, + (cl_int)0x78123456, (cl_int)0x81234567, }; auto predicate = [&results](cl_int a, cl_int b) { diff --git a/test_conformance/basic/test_image_multipass.cpp b/test_conformance/basic/test_image_multipass.cpp index 5d8ae993..e7af8726 100644 --- a/test_conformance/basic/test_image_multipass.cpp +++ b/test_conformance/basic/test_image_multipass.cpp @@ -144,8 +144,8 @@ verify_byte_image(unsigned char *image, unsigned char *outptr, int w, int h, int REGISTER_TEST(image_multipass_integer_coord) { - int img_width = 512; - int img_height = 512; + size_t img_width = 512; + size_t img_height = 512; cl_image_format img_format; int num_input_streams = 8; @@ -397,8 +397,8 @@ REGISTER_TEST(image_multipass_integer_coord) REGISTER_TEST(image_multipass_float_coord) { - int img_width = 512; - int img_height = 512; + size_t img_width = 512; + size_t img_height = 512; cl_image_format img_format; int num_input_streams = 8; diff --git a/test_conformance/basic/test_imagearraycopy.cpp b/test_conformance/basic/test_imagearraycopy.cpp index 7f177ff4..a400c460 100644 --- a/test_conformance/basic/test_imagearraycopy.cpp +++ b/test_conformance/basic/test_imagearraycopy.cpp @@ -35,9 +35,9 @@ static int test_imagearraycopy_single_format( std::unique_ptr bufptr{ nullptr, free }, imgptr{ nullptr, free }; clMemWrapper buffer, image; - const int img_width = 512; - const int img_height = 512; - const int img_depth = (image_type == CL_MEM_OBJECT_IMAGE3D) ? 32 : 1; + const size_t img_width = 512; + const size_t img_height = 512; + const size_t img_depth = (image_type == CL_MEM_OBJECT_IMAGE3D) ? 32 : 1; size_t elem_size; size_t buffer_size; cl_int err; diff --git a/test_conformance/basic/test_imagecopy.cpp b/test_conformance/basic/test_imagecopy.cpp index 22bdea11..5e888594 100644 --- a/test_conformance/basic/test_imagecopy.cpp +++ b/test_conformance/basic/test_imagecopy.cpp @@ -111,8 +111,8 @@ static int test_imagecopy_impl(cl_device_id device, cl_context context, std::unique_ptr rgba16_inptr, rgba16_outptr; std::unique_ptr rgbafp_inptr, rgbafp_outptr; clMemWrapper streams[6]; - int img_width = 512; - int img_height = 512; + size_t img_width = 512; + size_t img_height = 512; int i, err; MTdataHolder d(gRandomSeed); @@ -153,7 +153,7 @@ static int test_imagecopy_impl(cl_device_id device, cl_context context, for (i = 0; i < 3; i++) { void *p, *outp; - int x, y, delta_w = img_width / 8, delta_h = img_height / 16; + size_t x, y, delta_w = img_width / 8, delta_h = img_height / 16; switch (i) { @@ -197,10 +197,11 @@ static int test_imagecopy_impl(cl_device_id device, cl_context context, copy_origin, copy_region, 0, NULL, NULL); if (err) { - log_error("Copy %d (origin [%d, %d], size [%d, %d], image " - "size [%d x %d]) Failed\n", - copy_number, x, y, delta_w, delta_h, img_width, - img_height); + log_error( + "Copy %d (origin [%zu, %zu], size [%zu, %zu], image " + "size [%zu x %zu]) Failed\n", + copy_number, x, y, delta_w, delta_h, img_width, + img_height); } test_error(err, "clEnqueueCopyImage failed"); } diff --git a/test_conformance/basic/test_imagecopy3d.cpp b/test_conformance/basic/test_imagecopy3d.cpp index 5de2e3ae..53a88bd5 100644 --- a/test_conformance/basic/test_imagecopy3d.cpp +++ b/test_conformance/basic/test_imagecopy3d.cpp @@ -115,9 +115,9 @@ static int test_imagecopy3d_impl(cl_device_id device, cl_context context, std::unique_ptr rgba16_inptr, rgba16_outptr; std::unique_ptr rgbafp_inptr, rgbafp_outptr; clMemWrapper streams[6]; - int img_width = 128; - int img_height = 128; - int img_depth = 64; + size_t img_width = 128; + size_t img_height = 128; + size_t img_depth = 64; int i; cl_int err; unsigned num_elements = img_width * img_height * img_depth * 4; diff --git a/test_conformance/basic/test_imagenpot.cpp b/test_conformance/basic/test_imagenpot.cpp index 1e2c213e..566cb9c3 100644 --- a/test_conformance/basic/test_imagenpot.cpp +++ b/test_conformance/basic/test_imagenpot.cpp @@ -82,8 +82,8 @@ REGISTER_TEST(imagenpot) cl_kernel kernel; size_t global_threads[3], local_threads[3]; size_t local_workgroup_size; - int img_width; - int img_height; + size_t img_width; + size_t img_height; int err; cl_uint m; size_t max_local_workgroup_size[3]; diff --git a/test_conformance/basic/test_imagerandomcopy.cpp b/test_conformance/basic/test_imagerandomcopy.cpp index 79e6b749..748da6fb 100644 --- a/test_conformance/basic/test_imagerandomcopy.cpp +++ b/test_conformance/basic/test_imagerandomcopy.cpp @@ -123,15 +123,15 @@ REGISTER_TEST(imagerandomcopy) unsigned short *rgba16_inptr, *rgba16_outptr; float *rgbafp_inptr, *rgbafp_outptr; clMemWrapper streams[6]; - int img_width = 512; - int img_height = 512; + size_t img_width = 512; + size_t img_height = 512; int i, j; cl_int err; MTdata d; PASSIVE_REQUIRE_IMAGE_SUPPORT( device ) - log_info("Testing with image %d x %d.\n", img_width, img_height); + log_info("Testing with image %zu x %zu.\n", img_width, img_height); d = init_genrand( gRandomSeed ); rgba8_inptr = (unsigned char *)generate_rgba8_image(img_width, img_height, d); @@ -191,8 +191,8 @@ REGISTER_TEST(imagerandomcopy) } size_t origin[3]={0,0,0}, region[3]={img_width, img_height,1}; - err = clEnqueueWriteImage(queue, streams[i*2], CL_TRUE, origin, region, 0, 0, p, 0, NULL, NULL); -// err = clWriteImage(context, streams[i*2], false, 0, 0, 0, img_width, img_height, 0, NULL, 0, 0, p, NULL); + err = clEnqueueWriteImage(queue, streams[i * 2], CL_TRUE, origin, + region, 0, 0, p, 0, NULL, NULL); test_error(err, "clEnqueueWriteImage failed"); for (j=0; j rgba16_inptr, rgba16_outptr; std::unique_ptr rgbafp_inptr, rgbafp_outptr; clMemWrapper streams[3]; - int img_width = 512; - int img_height = 512; + size_t img_width = 512; + size_t img_height = 512; int num_tries = 200; int i, j, err; MTdataHolder d(gRandomSeed); @@ -242,10 +242,10 @@ REGISTER_TEST(imagereadwrite) for (i = 0, j = 0; i < num_tries * image_formats_count; i++, j++) { - int x = (int)get_random_float(0, img_width, d); - int y = (int)get_random_float(0, img_height, d); - int w = (int)get_random_float(1, (img_width - x), d); - int h = (int)get_random_float(1, (img_height - y), d); + size_t x = (size_t)get_random_float(0, img_width, d); + size_t y = (size_t)get_random_float(0, img_height, d); + size_t w = (size_t)get_random_float(1, (img_width - x), d); + size_t h = (size_t)get_random_float(1, (img_height - y), d); size_t input_pitch; int set_input_pitch = (int)(genrand_int32(d) & 0x01); int packed_update = (int)(genrand_int32(d) & 0x01); @@ -386,7 +386,8 @@ REGISTER_TEST(imagereadwrite) img_width, img_height); if (err) { - log_error("x=%d y=%d w=%d h=%d, pitch=%d, try=%d\n", x, y, w, h, (int)input_pitch, (int)i); + log_error("x=%zu y=%zu w=%zu h=%zu, pitch=%d, try=%d\n", x, + y, w, h, (int)input_pitch, (int)i); log_error("IMAGE RGBA8 read, write %s test failed\n", update_packed_pitch_name); } break; @@ -396,7 +397,8 @@ REGISTER_TEST(imagereadwrite) img_width, img_height); if (err) { - log_error("x=%d y=%d w=%d h=%d, pitch=%d, try=%d\n", x, y, w, h, (int)input_pitch, (int)i); + log_error("x=%zu y=%zu w=%zu h=%zu, pitch=%d, try=%d\n", x, + y, w, h, (int)input_pitch, (int)i); log_error("IMAGE RGBA16 read, write %s test failed\n", update_packed_pitch_name); } break; @@ -406,7 +408,8 @@ REGISTER_TEST(imagereadwrite) img_width, img_height); if (err) { - log_error("x=%d y=%d w=%d h=%d, pitch=%d, try=%d\n", x, y, w, h, (int)input_pitch, (int)i); + log_error("x=%zu y=%zu w=%zu h=%zu, pitch=%d, try=%d\n", x, + y, w, h, (int)input_pitch, (int)i); log_error("IMAGE RGBA FP read, write %s test failed\n", update_packed_pitch_name); } break; diff --git a/test_conformance/basic/test_imagereadwrite3d.cpp b/test_conformance/basic/test_imagereadwrite3d.cpp index f384c339..6fb220b8 100644 --- a/test_conformance/basic/test_imagereadwrite3d.cpp +++ b/test_conformance/basic/test_imagereadwrite3d.cpp @@ -205,10 +205,10 @@ REGISTER_TEST(imagereadwrite3d) std::unique_ptr rgba16_inptr, rgba16_outptr; std::unique_ptr rgbafp_inptr, rgbafp_outptr; clMemWrapper streams[3]; - int img_width = 64; - int img_height = 64; - int img_depth = 32; - int img_slice = img_width * img_height; + size_t img_width = 64; + size_t img_height = 64; + size_t img_depth = 32; + size_t img_slice = img_width * img_height; int num_tries = 30; int i, j, err; MTdataHolder mtData(gRandomSeed); @@ -257,12 +257,12 @@ REGISTER_TEST(imagereadwrite3d) for (i = 0, j = 0; i < num_tries * image_formats_count; i++, j++) { - int x = (int)get_random_float(0, (float)img_width - 1, mtData); - int y = (int)get_random_float(0, (float)img_height - 1, mtData); - int z = (int)get_random_float(0, (float)img_depth - 1, mtData); - int w = (int)get_random_float(1, (float)(img_width - x), mtData); - int h = (int)get_random_float(1, (float)(img_height - y), mtData); - int d = (int)get_random_float(1, (float)(img_depth - z), mtData); + size_t x = (size_t)get_random_float(0, (float)img_width - 1, mtData); + size_t y = (size_t)get_random_float(0, (float)img_height - 1, mtData); + size_t z = (size_t)get_random_float(0, (float)img_depth - 1, mtData); + size_t w = (size_t)get_random_float(1, (float)(img_width - x), mtData); + size_t h = (size_t)get_random_float(1, (float)(img_height - y), mtData); + size_t d = (size_t)get_random_float(1, (float)(img_depth - z), mtData); size_t input_pitch, input_slice_pitch; int set_input_pitch = (int)(genrand_int32(mtData) & 0x01); int packed_update = (int)(genrand_int32(mtData) & 0x01); @@ -401,7 +401,10 @@ REGISTER_TEST(imagereadwrite3d) img_width, img_height, img_depth); if (err) { - log_error("x=%d y=%d z=%d w=%d h=%d d=%d pitch=%d, slice_pitch=%d, try=%d\n", x, y, z, w, h, d, (int)input_pitch, (int)input_slice_pitch, (int)i); + log_error("x=%zu y=%zu z=%zu w=%zu h=%zu d=%zu pitch=%d, " + "slice_pitch=%d, try=%d\n", + x, y, z, w, h, d, (int)input_pitch, + (int)input_slice_pitch, (int)i); log_error("IMAGE RGBA8 read, write %s test failed\n", update_packed_pitch_name); } break; @@ -411,7 +414,10 @@ REGISTER_TEST(imagereadwrite3d) img_width, img_height, img_depth); if (err) { - log_error("x=%d y=%d z=%d w=%d h=%d d=%d pitch=%d, slice_pitch=%d, try=%d\n", x, y, z, w, h, d, (int)input_pitch, (int)input_slice_pitch, (int)i); + log_error("x=%zu y=%zu z=%zu w=%zu h=%zu d=%zu pitch=%d, " + "slice_pitch=%d, try=%d\n", + x, y, z, w, h, d, (int)input_pitch, + (int)input_slice_pitch, (int)i); log_error("IMAGE RGBA16 read, write %s test failed\n", update_packed_pitch_name); } break; @@ -421,7 +427,10 @@ REGISTER_TEST(imagereadwrite3d) img_width, img_height, img_depth); if (err) { - log_error("x=%d y=%d z=%d w=%d h=%d d=%d pitch=%d, slice_pitch=%d, try=%d\n", x, y, z, w, h, d, (int)input_pitch, (int)input_slice_pitch, (int)i); + log_error("x=%zu y=%zu z=%zu w=%zu h=%zu d=%zu pitch=%d, " + "slice_pitch=%d, try=%d\n", + x, y, z, w, h, d, (int)input_pitch, + (int)input_slice_pitch, (int)i); log_error("IMAGE RGBA FP read, write %s test failed\n", update_packed_pitch_name); } break; diff --git a/test_conformance/basic/test_kernel_call_kernel_function.cpp b/test_conformance/basic/test_kernel_call_kernel_function.cpp index 0669ee24..82cb1a65 100644 --- a/test_conformance/basic/test_kernel_call_kernel_function.cpp +++ b/test_conformance/basic/test_kernel_call_kernel_function.cpp @@ -66,7 +66,7 @@ REGISTER_TEST(kernel_call_kernel_function) clKernelWrapper kernel1, kernel2, kernel_to_call; clMemWrapper streams[2]; - size_t threads[] = {num_elements,1,1}; + size_t threads[] = { static_cast(num_elements), 1, 1 }; cl_int *input, *output, *expected; cl_int times = 4; int pass = 0; diff --git a/test_conformance/basic/test_multireadimagemultifmt.cpp b/test_conformance/basic/test_multireadimagemultifmt.cpp index b92daf88..8a16ca85 100644 --- a/test_conformance/basic/test_multireadimagemultifmt.cpp +++ b/test_conformance/basic/test_multireadimagemultifmt.cpp @@ -117,8 +117,8 @@ REGISTER_TEST(mri_multiple) cl_program program; cl_kernel kernel; size_t threads[2]; - int img_width = 512; - int img_height = 512; + size_t img_width = 512; + size_t img_height = 512; int i, err; MTdata d; diff --git a/test_conformance/basic/test_multireadimageonefmt.cpp b/test_conformance/basic/test_multireadimageonefmt.cpp index 1d0b5b8d..8a37e29b 100644 --- a/test_conformance/basic/test_multireadimageonefmt.cpp +++ b/test_conformance/basic/test_multireadimageonefmt.cpp @@ -100,8 +100,8 @@ REGISTER_TEST(mri_one) cl_program program; cl_kernel kernel; size_t threads[2]; - int img_width = 512; - int img_height = 512; + size_t img_width = 512; + size_t img_height = 512; int i, err; size_t origin[3] = {0, 0, 0}; size_t region[3] = {img_width, img_height, 1};