From e31460efa8fa2102f8137538c2f07e9d7fbdf9d1 Mon Sep 17 00:00:00 2001 From: Antonios Christidis Date: Wed, 22 Jan 2025 13:50:46 -0600 Subject: [PATCH 1/2] Fix Build Warnings for AArch64 This commit links to issue (#2234). When cross-compiling for AArch64, using gcc 13.3, you encounter three warnings types that turn into errors: - maybe-uninitialized - stringop-truncation - strict-aliasing This commit fixes all the warnings found, in regards to the first two rules. To resolve the warnigns due to strict-aliasing, I am editing the CMake build system. Signed-off-by: Antonios Christidis --- CMakeLists.txt | 1 + test_common/harness/imageHelpers.cpp | 16 ++++++++++++++++ test_common/harness/typeWrappers.cpp | 2 +- test_conformance/SVM/test_enqueue_api.cpp | 4 ++-- .../api/test_wg_suggested_local_work_size.cpp | 2 +- test_conformance/basic/test_imagereadwrite.cpp | 6 ++++++ test_conformance/basic/test_imagereadwrite3d.cpp | 6 ++++++ test_conformance/buffers/test_buffer_write.cpp | 4 ++-- test_conformance/contractions/contractions.cpp | 10 ++++++---- .../conversions/basic_test_conversions.cpp | 14 ++++++++++---- .../conversions/test_conversions.cpp | 7 ++++--- .../events/test_event_dependencies.cpp | 2 +- test_conformance/half/Test_vStoreHalf.cpp | 8 ++++---- test_conformance/half/main.cpp | 5 +++-- .../images/clCopyImage/test_copy_1D.cpp | 2 +- .../images/clCopyImage/test_copy_1D_array.cpp | 2 +- .../images/clCopyImage/test_copy_2D.cpp | 2 +- .../images/clCopyImage/test_copy_2D_2D_array.cpp | 2 +- .../images/clCopyImage/test_copy_2D_3D.cpp | 2 +- .../images/clCopyImage/test_loops.cpp | 5 +++++ .../images/clFillImage/test_fill_generic.cpp | 5 +++++ test_conformance/images/clGetInfo/test_2D.cpp | 12 ++++++++++++ .../test_cl_ext_image_buffer.hpp | 2 +- .../test_cl_ext_image_from_buffer.cpp | 2 +- .../images/kernel_read_write/test_iterations.cpp | 2 +- .../kernel_read_write/test_write_image.cpp | 4 ++-- test_conformance/integer_ops/test_unary_ops.cpp | 2 +- test_conformance/printf/test_printf.cpp | 3 ++- test_conformance/select/test_select.cpp | 12 ++++++++---- test_conformance/subgroups/subhelpers.h | 2 +- 30 files changed, 107 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40deed8cd3..d353760a8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang" add_cxx_flag_if_supported(-Wno-error=cpp) # Allow #warning directive add_cxx_flag_if_supported(-Wno-unknown-pragmas) # Issue #785 add_cxx_flag_if_supported(-Wno-error=asm-operand-widths) # Issue #784 + add_cxx_flag_if_supported(-Wno-strict-aliasing) # Issue 2234 # -msse -mfpmath=sse to force gcc to use sse for float math, # avoiding excess precision problems that cause tests like int2float diff --git a/test_common/harness/imageHelpers.cpp b/test_common/harness/imageHelpers.cpp index b354baebe3..3de7e94827 100644 --- a/test_common/harness/imageHelpers.cpp +++ b/test_common/harness/imageHelpers.cpp @@ -2415,6 +2415,12 @@ int debug_find_vector_in_image(void *imagePtr, image_descriptor *imageInfo, (imageInfo->height >> lod) ? (imageInfo->height >> lod) : 1; depth = (imageInfo->depth >> lod) ? (imageInfo->depth >> lod) : 1; break; + default: + log_error("ERROR: Invalid imageInfo->type = %d\n", imageInfo->type); + width = 0; + depth = 0; + height = 0; + break; } row_pitch = width * get_pixel_size(imageInfo->format); @@ -3661,6 +3667,11 @@ void copy_image_data(image_descriptor *srcImageInfo, ? (srcImageInfo->height >> src_lod) : 1; break; + default: + log_error("ERROR: Invalid srcImageInfo->type = %d\n", + srcImageInfo->type); + src_lod = 0; + break; } src_mip_level_offset = compute_mip_level_offset(srcImageInfo, src_lod); src_row_pitch_lod = @@ -3707,6 +3718,11 @@ void copy_image_data(image_descriptor *srcImageInfo, ? (dstImageInfo->height >> dst_lod) : 1; break; + default: + log_error("ERROR: Invalid dstImageInfo->num_mip_levels = %d\n", + dstImageInfo->num_mip_levels); + dst_lod = 0; + break; } dst_mip_level_offset = compute_mip_level_offset(dstImageInfo, dst_lod); dst_row_pitch_lod = diff --git a/test_common/harness/typeWrappers.cpp b/test_common/harness/typeWrappers.cpp index e6520b1c08..ed7d3ce394 100644 --- a/test_common/harness/typeWrappers.cpp +++ b/test_common/harness/typeWrappers.cpp @@ -348,7 +348,7 @@ cl_int clProtectedImage::Create(cl_context context, const cl_image_format *fmt, size_t width, size_t height, size_t depth, size_t arraySize) { - cl_int error; + cl_int error = 0; #if defined(__APPLE__) int protect_pages = 1; cl_device_id devices[16]; diff --git a/test_conformance/SVM/test_enqueue_api.cpp b/test_conformance/SVM/test_enqueue_api.cpp index 20fa4432e5..83e0b9afd4 100644 --- a/test_conformance/SVM/test_enqueue_api.cpp +++ b/test_conformance/SVM/test_enqueue_api.cpp @@ -160,8 +160,8 @@ REGISTER_TEST(svm_enqueue_api) error = clSetUserEventStatus(userEvent, CL_COMPLETE); test_error(error, "clSetUserEventStatus failed"); - cl_uchar *src_ptr; - cl_uchar *dst_ptr; + cl_uchar *src_ptr = nullptr; + cl_uchar *dst_ptr = nullptr; if (test_case.srcAlloc == host) { src_ptr = srcHostData.data(); diff --git a/test_conformance/api/test_wg_suggested_local_work_size.cpp b/test_conformance/api/test_wg_suggested_local_work_size.cpp index f84646380c..9b4a0b5e1a 100644 --- a/test_conformance/api/test_wg_suggested_local_work_size.cpp +++ b/test_conformance/api/test_wg_suggested_local_work_size.cpp @@ -208,7 +208,7 @@ int do_test_work_group_suggested_local_size( bool (*skip_cond)(size_t), size_t start, size_t end, size_t incr, cl_ulong max_local_mem_size, size_t global_work_offset[], num_dims dim) { - int err; + int err = 0; size_t test_values[] = { 1, 1, 1 }; std::string kernel_names[6] = { "test_wg_scan_local_work_group_size", diff --git a/test_conformance/basic/test_imagereadwrite.cpp b/test_conformance/basic/test_imagereadwrite.cpp index c074238dea..fee73ea388 100644 --- a/test_conformance/basic/test_imagereadwrite.cpp +++ b/test_conformance/basic/test_imagereadwrite.cpp @@ -314,6 +314,12 @@ test_imagereadwrite(cl_device_id device, cl_context context, cl_command_queue qu } outp = (void *)rgbafp_outptr; break; + default: + log_error("ERROR Invalid j = %d\n", j); + elem_size = 0; + p = nullptr; + outp = nullptr; + break; } const char* update_packed_pitch_name = ""; diff --git a/test_conformance/basic/test_imagereadwrite3d.cpp b/test_conformance/basic/test_imagereadwrite3d.cpp index 66f64e0921..d52f16d0ec 100644 --- a/test_conformance/basic/test_imagereadwrite3d.cpp +++ b/test_conformance/basic/test_imagereadwrite3d.cpp @@ -320,6 +320,12 @@ test_imagereadwrite3d(cl_device_id device, cl_context context, cl_command_queue } outp = (void *)rgbafp_outptr; break; + default: + log_error("ERROR Invalid j = %d\n", j); + elem_size = 0; + p = nullptr; + outp = nullptr; + break; } const char* update_packed_pitch_name = ""; diff --git a/test_conformance/buffers/test_buffer_write.cpp b/test_conformance/buffers/test_buffer_write.cpp index e57e1c18fe..bf41e48c66 100644 --- a/test_conformance/buffers/test_buffer_write.cpp +++ b/test_conformance/buffers/test_buffer_write.cpp @@ -852,8 +852,8 @@ int test_buffer_write_struct( cl_device_id deviceID, cl_context context, cl_comm buffers[0] = clCreateBuffer(context, flag_set[src_flag_id], ptrSizes[i] * num_elements, NULL, &err); - if ( err ){ - align_free( outptr[i] ); + if (err) + { print_error(err, " clCreateBuffer failed\n" ); free_mtdata(d); return -1; diff --git a/test_conformance/contractions/contractions.cpp b/test_conformance/contractions/contractions.cpp index 880a23ab5d..abe95af549 100644 --- a/test_conformance/contractions/contractions.cpp +++ b/test_conformance/contractions/contractions.cpp @@ -365,16 +365,18 @@ static int ParseArgs( int argc, const char **argv ) int length_of_seed = 0; { // Extract the app name - strncpy( appName, argv[0], MAXPATHLEN ); + strncpy(appName, argv[0], MAXPATHLEN - 1); + appName[MAXPATHLEN - 1] = '\0'; #if (defined( __APPLE__ ) || defined(__linux__) || defined(__MINGW32__)) char baseName[MAXPATHLEN]; char *base = NULL; - strncpy( baseName, argv[0], MAXPATHLEN ); + strncpy(baseName, argv[0], MAXPATHLEN - 1); + baseName[MAXPATHLEN - 1] = '\0'; base = basename( baseName ); if( NULL != base ) { - strncpy( appName, base, sizeof( appName ) ); + strncpy(appName, base, sizeof(appName) - 1); appName[ sizeof( appName ) -1 ] = '\0'; } #elif defined (_WIN32) @@ -385,7 +387,7 @@ static int ParseArgs( int argc, const char **argv ) fname, _MAX_FNAME, ext, _MAX_EXT ); if (err == 0) { // no error strcat (fname, ext); //just cat them, size of frame can keep both - strncpy (appName, fname, sizeof(appName)); + strncpy(appName, fname, sizeof(appName) - 1); appName[ sizeof( appName ) -1 ] = '\0'; } #endif diff --git a/test_conformance/conversions/basic_test_conversions.cpp b/test_conformance/conversions/basic_test_conversions.cpp index 3880c820c4..edad671b3c 100644 --- a/test_conformance/conversions/basic_test_conversions.cpp +++ b/test_conformance/conversions/basic_test_conversions.cpp @@ -1448,7 +1448,9 @@ cl_program MakeProgram(Type outType, Type inType, SaturationMode sat, char inName[32]; char outName[32]; strncpy(inName, gTypeNames[inType], sizeof(inName)); + inName[sizeof(inName) - 1] = '\0'; strncpy(outName, gTypeNames[outType], sizeof(outName)); + outName[sizeof(outName) - 1] = '\0'; sprintf(testName, "test_implicit_%s_%s", outName, inName); source << "__kernel void " << testName << "( __global " << inName @@ -1473,8 +1475,10 @@ cl_program MakeProgram(Type outType, Type inType, SaturationMode sat, switch (vectorSizetmp) { case 1: - strncpy(inName, gTypeNames[inType], sizeof(inName)); - strncpy(outName, gTypeNames[outType], sizeof(outName)); + strncpy(inName, gTypeNames[inType], sizeof(inName) - 1); + inName[sizeof(inName) - 1] = '\0'; + strncpy(outName, gTypeNames[outType], sizeof(outName) - 1); + outName[sizeof(outName) - 1] = '\0'; snprintf(convertString, sizeof(convertString), "convert_%s%s%s", outName, gSaturationNames[sat], gRoundingModeNames[round]); @@ -1482,8 +1486,10 @@ cl_program MakeProgram(Type outType, Type inType, SaturationMode sat, vlog("Building %s( %s ) test\n", convertString, inName); break; case 3: - strncpy(inName, gTypeNames[inType], sizeof(inName)); - strncpy(outName, gTypeNames[outType], sizeof(outName)); + strncpy(inName, gTypeNames[inType], sizeof(inName) - 1); + inName[sizeof(inName) - 1] = '\0'; + strncpy(outName, gTypeNames[outType], sizeof(outName) - 1); + outName[sizeof(outName) - 1] = '\0'; snprintf(convertString, sizeof(convertString), "convert_%s3%s%s", outName, gSaturationNames[sat], gRoundingModeNames[round]); diff --git a/test_conformance/conversions/test_conversions.cpp b/test_conformance/conversions/test_conversions.cpp index 8225769ef9..c63572c3e4 100644 --- a/test_conformance/conversions/test_conversions.cpp +++ b/test_conformance/conversions/test_conversions.cpp @@ -182,11 +182,12 @@ static int ParseArgs(int argc, const char **argv) #if (defined(__APPLE__) || defined(__linux__) || defined(__MINGW32__)) { // Extract the app name char baseName[MAXPATHLEN]; - strncpy(baseName, argv[0], MAXPATHLEN); + strncpy(baseName, argv[0], MAXPATHLEN - 1); + baseName[sizeof(baseName) - 1] = '\0'; char *base = basename(baseName); if (NULL != base) { - strncpy(appName, base, sizeof(appName)); + strncpy(appName, base, sizeof(appName) - 1); appName[sizeof(appName) - 1] = '\0'; } } @@ -200,7 +201,7 @@ static int ParseArgs(int argc, const char **argv) if (err == 0) { // no error strcat(fname, ext); // just cat them, size of frame can keep both - strncpy(appName, fname, sizeof(appName)); + strncpy(appName, fname, sizeof(appName) - 1); appName[sizeof(appName) - 1] = '\0'; } } diff --git a/test_conformance/events/test_event_dependencies.cpp b/test_conformance/events/test_event_dependencies.cpp index b40a69dd81..72e0f8e4b6 100644 --- a/test_conformance/events/test_event_dependencies.cpp +++ b/test_conformance/events/test_event_dependencies.cpp @@ -89,7 +89,7 @@ int test_event_enqueue_wait_for_events_run_test( // If we are to use two devices, then get them and create a context with // both. - cl_device_id *two_device_ids; + cl_device_id *two_device_ids = nullptr; if (two_devices) { two_device_ids = (cl_device_id *)malloc(sizeof(cl_device_id) * 2); diff --git a/test_conformance/half/Test_vStoreHalf.cpp b/test_conformance/half/Test_vStoreHalf.cpp index e5a425b0b6..cf914a9afc 100644 --- a/test_conformance/half/Test_vStoreHalf.cpp +++ b/test_conformance/half/Test_vStoreHalf.cpp @@ -341,8 +341,8 @@ int Test_vStoreHalf_private(cl_device_id device, f2h referenceFunc, int vectorSize, error; cl_program programs[kVectorSizeCount + kStrangeVectorSizeCount][3]; cl_kernel kernels[kVectorSizeCount + kStrangeVectorSizeCount][3]; - cl_program resetProgram; - cl_kernel resetKernel; + cl_program resetProgram = nullptr; + cl_kernel resetKernel = nullptr; uint64_t time[kVectorSizeCount + kStrangeVectorSizeCount] = { 0 }; uint64_t min_time[kVectorSizeCount + kStrangeVectorSizeCount] = { 0 }; @@ -1225,8 +1225,8 @@ int Test_vStoreaHalf_private(cl_device_id device, f2h referenceFunc, int vectorSize, error; cl_program programs[kVectorSizeCount + kStrangeVectorSizeCount][3]; cl_kernel kernels[kVectorSizeCount + kStrangeVectorSizeCount][3]; - cl_program resetProgram; - cl_kernel resetKernel; + cl_program resetProgram = nullptr; + cl_kernel resetKernel = nullptr; uint64_t time[kVectorSizeCount + kStrangeVectorSizeCount] = { 0 }; uint64_t min_time[kVectorSizeCount + kStrangeVectorSizeCount] = { 0 }; diff --git a/test_conformance/half/main.cpp b/test_conformance/half/main.cpp index ee44fb2dea..82b2d76992 100644 --- a/test_conformance/half/main.cpp +++ b/test_conformance/half/main.cpp @@ -144,11 +144,12 @@ static int ParseArgs( int argc, const char **argv ) #if (defined( __APPLE__ ) || defined(__linux__) || defined(__MINGW32__)) { // Extract the app name char baseName[ MAXPATHLEN ]; - strncpy( baseName, argv[0], MAXPATHLEN ); + strncpy(baseName, argv[0], MAXPATHLEN - 1); + baseName[MAXPATHLEN - 1] = '\0'; char *base = basename( baseName ); if( NULL != base ) { - strncpy( appName, base, sizeof( appName ) ); + strncpy(appName, base, sizeof(appName) - 1); appName[ sizeof( appName ) -1 ] = '\0'; } } diff --git a/test_conformance/images/clCopyImage/test_copy_1D.cpp b/test_conformance/images/clCopyImage/test_copy_1D.cpp index b4ae830850..7d13eaabd8 100644 --- a/test_conformance/images/clCopyImage/test_copy_1D.cpp +++ b/test_conformance/images/clCopyImage/test_copy_1D.cpp @@ -25,7 +25,7 @@ int test_copy_image_size_1D( cl_context context, cl_command_queue queue, image_d size_t src_lod = 0, src_width_lod = imageInfo->width, src_row_pitch_lod; size_t dst_lod = 0, dst_width_lod = imageInfo->width, dst_row_pitch_lod; size_t width_lod = imageInfo->width; - size_t max_mip_level; + size_t max_mip_level = 0; if( gTestMipmaps ) { diff --git a/test_conformance/images/clCopyImage/test_copy_1D_array.cpp b/test_conformance/images/clCopyImage/test_copy_1D_array.cpp index f0b610bbe8..d94ba8efef 100644 --- a/test_conformance/images/clCopyImage/test_copy_1D_array.cpp +++ b/test_conformance/images/clCopyImage/test_copy_1D_array.cpp @@ -25,7 +25,7 @@ int test_copy_image_size_1D_array( cl_context context, cl_command_queue queue, i size_t src_lod = 0, src_width_lod = imageInfo->width, src_row_pitch_lod; size_t dst_lod = 0, dst_width_lod = imageInfo->width, dst_row_pitch_lod; size_t width_lod = imageInfo->width; - size_t max_mip_level; + size_t max_mip_level = 0; if( gTestMipmaps ) { diff --git a/test_conformance/images/clCopyImage/test_copy_2D.cpp b/test_conformance/images/clCopyImage/test_copy_2D.cpp index 448b47f08c..97cca26c01 100644 --- a/test_conformance/images/clCopyImage/test_copy_2D.cpp +++ b/test_conformance/images/clCopyImage/test_copy_2D.cpp @@ -27,7 +27,7 @@ int test_copy_image_size_2D( cl_context context, cl_command_queue queue, image_d size_t dst_lod = 0, dst_width_lod = imageInfo->width, dst_row_pitch_lod; size_t dst_height_lod = imageInfo->height; size_t width_lod = imageInfo->width, height_lod = imageInfo->height; - size_t max_mip_level; + size_t max_mip_level = 0; if( gTestMipmaps ) { diff --git a/test_conformance/images/clCopyImage/test_copy_2D_2D_array.cpp b/test_conformance/images/clCopyImage/test_copy_2D_2D_array.cpp index 1819d87c25..9ba8718a4b 100644 --- a/test_conformance/images/clCopyImage/test_copy_2D_2D_array.cpp +++ b/test_conformance/images/clCopyImage/test_copy_2D_2D_array.cpp @@ -72,7 +72,7 @@ int test_copy_image_size_2D_2D_array( cl_context context, cl_command_queue queue size_t threeImage_lod = 0, threeImage_width_lod = threeImage->width, threeImage_row_pitch_lod, threeImage_slice_pitch_lod; size_t threeImage_height_lod = threeImage->height; size_t width_lod, height_lod; - size_t twoImage_max_mip_level,threeImage_max_mip_level; + size_t twoImage_max_mip_level = 0, threeImage_max_mip_level = 0; if( gTestMipmaps ) { diff --git a/test_conformance/images/clCopyImage/test_copy_2D_3D.cpp b/test_conformance/images/clCopyImage/test_copy_2D_3D.cpp index 4ab6b42a61..5f522e3e65 100644 --- a/test_conformance/images/clCopyImage/test_copy_2D_3D.cpp +++ b/test_conformance/images/clCopyImage/test_copy_2D_3D.cpp @@ -68,7 +68,7 @@ int test_copy_image_size_2D_3D( cl_context context, cl_command_queue queue, imag size_t threeImage_lod = 0, threeImage_width_lod = threeImage->width, threeImage_row_pitch_lod, threeImage_slice_pitch_lod; size_t threeImage_height_lod = threeImage->height, depth_lod = threeImage->depth; size_t width_lod, height_lod; - size_t twoImage_max_mip_level,threeImage_max_mip_level; + size_t twoImage_max_mip_level = 0, threeImage_max_mip_level = 0; if( gTestMipmaps ) { diff --git a/test_conformance/images/clCopyImage/test_loops.cpp b/test_conformance/images/clCopyImage/test_loops.cpp index ea60d3560e..ad19463249 100644 --- a/test_conformance/images/clCopyImage/test_loops.cpp +++ b/test_conformance/images/clCopyImage/test_loops.cpp @@ -111,6 +111,11 @@ int test_image_type( cl_device_id device, cl_context context, cl_command_queue q name = "1D buffer -> 1D"; imageType = CL_MEM_OBJECT_IMAGE1D_BUFFER; break; + default: + log_error("ERROR Invalid testMethod = %d", testMethod); + name = nullptr; + imageType = 0; + break; } if(gTestMipmaps) diff --git a/test_conformance/images/clFillImage/test_fill_generic.cpp b/test_conformance/images/clFillImage/test_fill_generic.cpp index 17b6182ed4..24c9181356 100644 --- a/test_conformance/images/clFillImage/test_fill_generic.cpp +++ b/test_conformance/images/clFillImage/test_fill_generic.cpp @@ -277,6 +277,11 @@ cl_mem create_image( cl_context context, cl_command_queue queue, BufferOwningPtr depth = imageInfo->depth; imageSize = imageInfo->slicePitch * imageInfo->depth; break; + default: + log_error("ERROR Invalid imageInfo->type = %d\n", imageInfo->type); + height = 0; + depth = 0; + break; } size_t origin[ 3 ] = { 0, 0, 0 }; diff --git a/test_conformance/images/clGetInfo/test_2D.cpp b/test_conformance/images/clGetInfo/test_2D.cpp index 49631bf491..76588a0932 100644 --- a/test_conformance/images/clGetInfo/test_2D.cpp +++ b/test_conformance/images/clGetInfo/test_2D.cpp @@ -181,6 +181,10 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo, case CL_MEM_OBJECT_IMAGE3D: required_height = imageInfo->height; break; + default: + log_error("ERROR: Invalid imageInfo->type = %d\n", imageInfo->type); + required_height = 0; + break; } size_t outHeight; @@ -204,6 +208,10 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo, case CL_MEM_OBJECT_IMAGE3D: required_depth = imageInfo->depth; break; + default: + log_error("ERROR: Invalid imageInfo->type = %d\n", imageInfo->type); + required_depth = 0; + break; } size_t outDepth; @@ -227,6 +235,10 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo, case CL_MEM_OBJECT_IMAGE2D_ARRAY: required_array_size = imageInfo->arraySize; break; + default: + log_error("ERROR: Invalid imageInfo->type = %d\n", imageInfo->type); + required_array_size = 0; + break; } size_t outArraySize; diff --git a/test_conformance/images/kernel_read_write/test_cl_ext_image_buffer.hpp b/test_conformance/images/kernel_read_write/test_cl_ext_image_buffer.hpp index 887c9dca73..77784b20f1 100644 --- a/test_conformance/images/kernel_read_write/test_cl_ext_image_buffer.hpp +++ b/test_conformance/images/kernel_read_write/test_cl_ext_image_buffer.hpp @@ -69,7 +69,7 @@ static inline size_t get_format_size(cl_context context, } cl_int error = 0; - cl_mem buffer; + cl_mem buffer = nullptr; if (imageType == CL_MEM_OBJECT_IMAGE1D_BUFFER) { buffer = clCreateBuffer(context, flags, diff --git a/test_conformance/images/kernel_read_write/test_cl_ext_image_from_buffer.cpp b/test_conformance/images/kernel_read_write/test_cl_ext_image_from_buffer.cpp index 2dcc1827e4..8b82b9f951 100644 --- a/test_conformance/images/kernel_read_write/test_cl_ext_image_from_buffer.cpp +++ b/test_conformance/images/kernel_read_write/test_cl_ext_image_from_buffer.cpp @@ -769,7 +769,7 @@ int image_from_buffer_fill_positive(cl_device_id device, cl_context context, err = clFinish(queue); test_error(err, "Error clFinish"); - cl_mem image1d_buffer; + cl_mem image1d_buffer = nullptr; if (imageType == CL_MEM_OBJECT_IMAGE1D_BUFFER) { image1d_buffer = clCreateBuffer(context, flag, buffer_size, diff --git a/test_conformance/images/kernel_read_write/test_iterations.cpp b/test_conformance/images/kernel_read_write/test_iterations.cpp index 0c87d87dc7..9c4e332ad7 100644 --- a/test_conformance/images/kernel_read_write/test_iterations.cpp +++ b/test_conformance/images/kernel_read_write/test_iterations.cpp @@ -1191,7 +1191,7 @@ int test_read_image_2D( cl_context context, cl_command_queue queue, cl_kernel ke { int error; static int initHalf = 0; - cl_mem imageBuffer; + cl_mem imageBuffer = nullptr; cl_mem_flags image_read_write_flags = CL_MEM_READ_ONLY; size_t threads[2]; diff --git a/test_conformance/images/kernel_read_write/test_write_image.cpp b/test_conformance/images/kernel_read_write/test_write_image.cpp index 32f7c22fe9..ab73e6e15d 100644 --- a/test_conformance/images/kernel_read_write/test_write_image.cpp +++ b/test_conformance/images/kernel_read_write/test_write_image.cpp @@ -223,7 +223,7 @@ int test_write_image( cl_device_id device, cl_context context, cl_command_queue clProtectedImage protImage; clMemWrapper unprotImage; cl_mem image; - cl_mem imageBuffer; + cl_mem imageBuffer = nullptr; if( gMemFlagsToUse == CL_MEM_USE_HOST_PTR ) { @@ -910,7 +910,7 @@ int test_write_image_formats(cl_device_id device, cl_context context, gTestCount++; print_write_header( &imageFormat, false ); - int retCode; + int retCode = 0; switch (imageType) { case CL_MEM_OBJECT_IMAGE1D: diff --git a/test_conformance/integer_ops/test_unary_ops.cpp b/test_conformance/integer_ops/test_unary_ops.cpp index da3de6d1c4..1f7fe855fe 100644 --- a/test_conformance/integer_ops/test_unary_ops.cpp +++ b/test_conformance/integer_ops/test_unary_ops.cpp @@ -97,7 +97,7 @@ int test_unary_op( cl_command_queue queue, cl_context context, OpKonstants which get_explicit_type_size(vecType) * vecSize * TEST_SIZE, inData, &error); test_error( error, "Creating input data array failed" ); - cl_uint bits; + cl_uint bits = 0; for( i = 0; i < TEST_SIZE; i++ ) { size_t which = i & 7; diff --git a/test_conformance/printf/test_printf.cpp b/test_conformance/printf/test_printf.cpp index 0d5dfa7bf3..ef52f0447a 100644 --- a/test_conformance/printf/test_printf.cpp +++ b/test_conformance/printf/test_printf.cpp @@ -1151,7 +1151,8 @@ int main(int argc, const char* argv[]) char* pcTempFname = get_temp_filename(); if (pcTempFname != nullptr) { - strncpy(gFileName, pcTempFname, sizeof(gFileName)); + strncpy(gFileName, pcTempFname, sizeof(gFileName) - 1); + gFileName[sizeof(gFileName) - 1] = '\0'; } free(pcTempFname); diff --git a/test_conformance/select/test_select.cpp b/test_conformance/select/test_select.cpp index 9cf4727ade..20f5bd5e03 100644 --- a/test_conformance/select/test_select.cpp +++ b/test_conformance/select/test_select.cpp @@ -261,14 +261,18 @@ static cl_program makeSelectProgram(cl_kernel *kernel_ptr, switch( vec_len ) { case 1: - strncpy(stypename, type_name[srctype], sizeof(stypename)); - strncpy(ctypename, type_name[cmptype], sizeof(ctypename)); + strncpy(stypename, type_name[srctype], sizeof(stypename) - 1); + stypename[sizeof(stypename) - 1] = '\0'; + strncpy(ctypename, type_name[cmptype], sizeof(ctypename) - 1); + ctypename[sizeof(ctypename) - 1] = '\0'; snprintf(testname, sizeof(testname), "select_%s_%s", stypename, ctypename ); log_info("Building %s(%s, %s, %s)\n", testname, stypename, stypename, ctypename); break; case 3: - strncpy(stypename, type_name[srctype], sizeof(stypename)); - strncpy(ctypename, type_name[cmptype], sizeof(ctypename)); + strncpy(stypename, type_name[srctype], sizeof(stypename) - 1); + stypename[sizeof(stypename) - 1] = '\0'; + strncpy(ctypename, type_name[cmptype], sizeof(ctypename) - 1); + ctypename[sizeof(ctypename) - 1] = '\0'; snprintf(testname, sizeof(testname), "select_%s3_%s3", stypename, ctypename ); log_info("Building %s(%s3, %s3, %s3)\n", testname, stypename, stypename, ctypename); break; diff --git a/test_conformance/subgroups/subhelpers.h b/test_conformance/subgroups/subhelpers.h index a081bd098c..ab8ee797a8 100644 --- a/test_conformance/subgroups/subhelpers.h +++ b/test_conformance/subgroups/subhelpers.h @@ -1611,7 +1611,7 @@ template struct subgroup_test test_params.subgroup_size = subgroup_size; Fns::gen(idata.data(), mapin.data(), sgmap.data(), test_params); - test_status status; + test_status status = TEST_FAIL; if (test_params.divergence_mask_arg != -1) { From 4b88219a8fc0f5bb3496f9afc68a83d976d97ddc Mon Sep 17 00:00:00 2001 From: Antonios Christidis Date: Thu, 23 Jan 2025 11:26:15 -0600 Subject: [PATCH 2/2] Removal of default case when selecting test for clCopyImage Remove the default case, so it will be possible to catch compiler errors when the enum is extended. Signed-off-by: Antonios Christidis --- test_conformance/images/clCopyImage/test_loops.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/test_conformance/images/clCopyImage/test_loops.cpp b/test_conformance/images/clCopyImage/test_loops.cpp index ad19463249..d9c54854d6 100644 --- a/test_conformance/images/clCopyImage/test_loops.cpp +++ b/test_conformance/images/clCopyImage/test_loops.cpp @@ -39,8 +39,8 @@ extern int test_copy_image_set_1D_buffer_1D(cl_device_id device, int test_image_type( cl_device_id device, cl_context context, cl_command_queue queue, MethodsToTest testMethod, cl_mem_flags flags ) { - const char *name; - cl_mem_object_type imageType; + const char *name = nullptr; + cl_mem_object_type imageType = 0; if ( gTestMipmaps ) { @@ -111,11 +111,6 @@ int test_image_type( cl_device_id device, cl_context context, cl_command_queue q name = "1D buffer -> 1D"; imageType = CL_MEM_OBJECT_IMAGE1D_BUFFER; break; - default: - log_error("ERROR Invalid testMethod = %d", testMethod); - name = nullptr; - imageType = 0; - break; } if(gTestMipmaps)