From cdf5a105fcdc32b9203c94e0623e36f64117e6a8 Mon Sep 17 00:00:00 2001 From: Stuart Brady Date: Tue, 2 Aug 2022 18:16:03 +0100 Subject: [PATCH] Fix misleading indentation and enable -Wmisleading-indentation (#1458) Signed-off-by: Stuart Brady --- CMakeLists.txt | 1 + test_conformance/basic/test_arraycopy.cpp | 5 ++-- .../basic/test_multireadimageonefmt.cpp | 24 ++++++++--------- .../basic/test_writeimage_fp32.cpp | 7 ++--- .../basic/test_writeimage_int16.cpp | 7 ++--- test_conformance/commonfns/test_sign.cpp | 13 +++++---- test_conformance/commonfns/test_step.cpp | 27 +++++++++---------- test_conformance/events/test_callbacks.cpp | 25 ++++++++--------- test_conformance/half/Test_vStoreHalf.cpp | 6 ++--- .../images/clReadWriteImage/test_read_1D.cpp | 19 +++++++------ .../test_multiple_devices.cpp | 5 ++-- test_conformance/profiling/execute.cpp | 4 +-- test_conformance/profiling/writeImage.cpp | 4 +-- 13 files changed, 72 insertions(+), 75 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f5f4472..fe56d0fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,7 @@ macro(add_cxx_flag_if_supported flag) endmacro(add_cxx_flag_if_supported) if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang") + add_cxx_flag_if_supported(-Wmisleading-indentation) add_cxx_flag_if_supported(-Wno-narrowing) add_cxx_flag_if_supported(-Wno-format) add_cxx_flag_if_supported(-Werror) diff --git a/test_conformance/basic/test_arraycopy.cpp b/test_conformance/basic/test_arraycopy.cpp index 5a352869..d9dbcc1b 100644 --- a/test_conformance/basic/test_arraycopy.cpp +++ b/test_conformance/basic/test_arraycopy.cpp @@ -181,9 +181,8 @@ test_arraycopy(cl_device_id device, cl_context context, cl_command_queue queue, } } - // Keep track of multiple errors. - if (error_count != 0) - err = error_count; + // Keep track of multiple errors. + if (error_count != 0) err = error_count; if (err) log_error("\tCL_MEM_USE_HOST_PTR buffer with kernel copy FAILED\n"); diff --git a/test_conformance/basic/test_multireadimageonefmt.cpp b/test_conformance/basic/test_multireadimageonefmt.cpp index b37c8414..c230e67a 100644 --- a/test_conformance/basic/test_multireadimageonefmt.cpp +++ b/test_conformance/basic/test_multireadimageonefmt.cpp @@ -153,14 +153,14 @@ int test_mri_one(cl_device_id device, cl_context context, cl_command_queue queue err = clSetKernelArg(kernel, 0, sizeof i, &i); err |= clSetKernelArg(kernel, 1, sizeof err, &err); err |= clSetKernelArg(kernel, 2, sizeof sampler, &sampler); - for (i=0; i<8; i++) - err |= clSetKernelArg(kernel, 3+i, sizeof streams[i], &streams[i]); + for (i = 0; i < 8; i++) + err |= clSetKernelArg(kernel, 3 + i, sizeof streams[i], &streams[i]); - if (err != CL_SUCCESS) - { - log_error("clSetKernelArgs failed\n"); - return -1; - } + if (err != CL_SUCCESS) + { + log_error("clSetKernelArgs failed\n"); + return -1; + } threads[0] = (unsigned int)img_width; threads[1] = (unsigned int)img_height; @@ -182,15 +182,13 @@ int test_mri_one(cl_device_id device, cl_context context, cl_command_queue queue // cleanup clReleaseSampler(sampler); - for (i=0; i<8; i++) - clReleaseMemObject(streams[i]); + for (i = 0; i < 8; i++) clReleaseMemObject(streams[i]); clReleaseKernel(kernel); clReleaseProgram(program); - for (i=0; i<7; i++) - free(input_ptr[i]); - free(output_ptr); + for (i = 0; i < 7; i++) free(input_ptr[i]); + free(output_ptr); - return err; + return err; } diff --git a/test_conformance/basic/test_writeimage_fp32.cpp b/test_conformance/basic/test_writeimage_fp32.cpp index fef71874..c68463ac 100644 --- a/test_conformance/basic/test_writeimage_fp32.cpp +++ b/test_conformance/basic/test_writeimage_fp32.cpp @@ -122,9 +122,10 @@ int test_writeimage_fp32(cl_device_id device, cl_context context, cl_command_que return -1; } - err = create_single_kernel_helper(context, &program, &kernel[0], 1, &rgbaFFFF_write_kernel_code, "test_rgbaFFFF_write" ); - if (err) - return -1; + err = create_single_kernel_helper(context, &program, &kernel[0], 1, + &rgbaFFFF_write_kernel_code, + "test_rgbaFFFF_write"); + if (err) return -1; kernel[1] = clCreateKernel(program, "test_rgbaFFFF_write", NULL); if (!kernel[1]) { diff --git a/test_conformance/basic/test_writeimage_int16.cpp b/test_conformance/basic/test_writeimage_int16.cpp index 8afb77a9..d863a3a3 100644 --- a/test_conformance/basic/test_writeimage_int16.cpp +++ b/test_conformance/basic/test_writeimage_int16.cpp @@ -128,9 +128,10 @@ int test_writeimage_int16(cl_device_id device, cl_context context, cl_command_qu return -1; } - err = create_single_kernel_helper(context, &program, &kernel[0], 1, &rgba16_write_kernel_code, "test_rgba16_write" ); - if (err) - return -1; + err = create_single_kernel_helper(context, &program, &kernel[0], 1, + &rgba16_write_kernel_code, + "test_rgba16_write"); + if (err) return -1; kernel[1] = clCreateKernel(program, "test_rgba16_write", NULL); if (!kernel[1]) { diff --git a/test_conformance/commonfns/test_sign.cpp b/test_conformance/commonfns/test_sign.cpp index 1b842e35..6dba58da 100644 --- a/test_conformance/commonfns/test_sign.cpp +++ b/test_conformance/commonfns/test_sign.cpp @@ -223,14 +223,13 @@ test_sign(cl_device_id device, cl_context context, cl_command_queue queue, int n free(input_ptr[0]); free(output_ptr); - if(err) - return err; + if (err) return err; - if( ! is_extension_available( device, "cl_khr_fp64")) - { - log_info( "skipping double test -- cl_khr_fp64 not supported.\n" ); - return 0; - } + if (!is_extension_available(device, "cl_khr_fp64")) + { + log_info("skipping double test -- cl_khr_fp64 not supported.\n"); + return 0; + } return test_sign_double( device, context, queue, n_elems); } diff --git a/test_conformance/commonfns/test_step.cpp b/test_conformance/commonfns/test_step.cpp index 0e3cfe07..330083b2 100644 --- a/test_conformance/commonfns/test_step.cpp +++ b/test_conformance/commonfns/test_step.cpp @@ -158,23 +158,20 @@ test_step(cl_device_id device, cl_context context, cl_command_queue queue, int n } err = create_single_kernel_helper( context, &program[0], &kernel[0], 1, &step_kernel_code, "test_step" ); - if (err) - return -1; + if (err) return -1; err = create_single_kernel_helper( context, &program[1], &kernel[1], 1, &step2_kernel_code, "test_step2" ); - if (err) - return -1; + if (err) return -1; err = create_single_kernel_helper( context, &program[2], &kernel[2], 1, &step4_kernel_code, "test_step4" ); - if (err) - return -1; - err = create_single_kernel_helper( context, &program[3], &kernel[3], 1, &step8_kernel_code, "test_step8" ); - if (err) - return -1; - err = create_single_kernel_helper( context, &program[4], &kernel[4], 1, &step16_kernel_code, "test_step16" ); - if (err) - return -1; - err = create_single_kernel_helper( context, &program[5], &kernel[5], 1, &step3_kernel_code, "test_step3" ); - if (err) - return -1; + if (err) return -1; + err = create_single_kernel_helper(context, &program[3], &kernel[3], 1, + &step8_kernel_code, "test_step8"); + if (err) return -1; + err = create_single_kernel_helper(context, &program[4], &kernel[4], 1, + &step16_kernel_code, "test_step16"); + if (err) return -1; + err = create_single_kernel_helper(context, &program[5], &kernel[5], 1, + &step3_kernel_code, "test_step3"); + if (err) return -1; values[0] = streams[0]; values[1] = streams[1]; diff --git a/test_conformance/events/test_callbacks.cpp b/test_conformance/events/test_callbacks.cpp index 2ffb9ca7..6025afb7 100644 --- a/test_conformance/events/test_callbacks.cpp +++ b/test_conformance/events/test_callbacks.cpp @@ -110,11 +110,12 @@ int test_callback_event_single( cl_device_id device, cl_context context, cl_comm { usleep( 100000 ); // 1/10th second - int cc=0; - for( int k=0;k< EVENT_CALLBACK_TYPE_TOTAL;k++) - if (sCallbackTriggered_flag[k]) { - cc++; - } + int cc = 0; + for (int k = 0; k < EVENT_CALLBACK_TYPE_TOTAL; k++) + if (sCallbackTriggered_flag[k]) + { + cc++; + } if (cc== EVENT_CALLBACK_TYPE_TOTAL ) { @@ -260,8 +261,8 @@ int test_callbacks_simultaneous( cl_device_id deviceID, cl_context context, cl_c if (actionEvents == NULL) { log_error(" memory error in test_callbacks_simultaneous \n"); - for (size_t i=0;i<(sizeof(actions)/sizeof(actions[0]));++i) - if (actions[i]) delete actions[i]; + for (size_t i = 0; i < (sizeof(actions) / sizeof(actions[0])); ++i) + if (actions[i]) delete actions[i]; return -1; } @@ -317,11 +318,11 @@ int test_callbacks_simultaneous( cl_device_id deviceID, cl_context context, cl_c usleep( 100000 ); // 1/10th second if( ((last_count = sSimultaneousCount)) == total_callbacks ) { - // All of the callbacks were executed - if (actionEvents) delete [] actionEvents; - for (size_t i=0;i<(sizeof(actions)/sizeof(actions[0]));++i) - if (actions[i]) delete actions[i]; - return 0; + // All of the callbacks were executed + if (actionEvents) delete[] actionEvents; + for (size_t i = 0; i < (sizeof(actions) / sizeof(actions[0])); ++i) + if (actions[i]) delete actions[i]; + return 0; } } diff --git a/test_conformance/half/Test_vStoreHalf.cpp b/test_conformance/half/Test_vStoreHalf.cpp index 3ca5920b..b1491025 100644 --- a/test_conformance/half/Test_vStoreHalf.cpp +++ b/test_conformance/half/Test_vStoreHalf.cpp @@ -117,8 +117,7 @@ CheckF(cl_uint jid, cl_uint tid, void *userInfo) return 0; for (j = 0; j < count; j++) { - if (s[j] == r[j]) - continue; + if (s[j] == r[j]) continue; // Pass any NaNs if ((s[j] & 0x7fff) > 0x7c00 && (r[j] & 0x7fff) > 0x7c00 ) @@ -189,8 +188,7 @@ CheckD(cl_uint jid, cl_uint tid, void *userInfo) return 0; for (j = 0; j < count; j++) { - if (s[j] == r[j]) - continue; + if (s[j] == r[j]) continue; // Pass any NaNs if ((s[j] & 0x7fff) > 0x7c00 && (r[j] & 0x7fff) > 0x7c00) diff --git a/test_conformance/images/clReadWriteImage/test_read_1D.cpp b/test_conformance/images/clReadWriteImage/test_read_1D.cpp index eef5bf4e..2a42a70e 100644 --- a/test_conformance/images/clReadWriteImage/test_read_1D.cpp +++ b/test_conformance/images/clReadWriteImage/test_read_1D.cpp @@ -90,14 +90,17 @@ int test_read_image_1D(cl_context context, cl_command_queue queue, region[0] = width_lod; - if ( gDebugTrace ) - if ( gTestMipmaps) { - log_info(" - Working at mipLevel :%llu\n", (unsigned long long)lod); - } - error = clEnqueueWriteImage(queue, image, CL_FALSE, - origin, region, ( gEnablePitch ? row_pitch_lod : 0 ), 0, - (char*)imageValues + imgValMipLevelOffset, 0, NULL, NULL); - if (error != CL_SUCCESS) { + if (gDebugTrace) + if (gTestMipmaps) + { + log_info(" - Working at mipLevel :%llu\n", (unsigned long long)lod); + } + error = clEnqueueWriteImage(queue, image, CL_FALSE, origin, region, + (gEnablePitch ? row_pitch_lod : 0), 0, + (char *)imageValues + imgValMipLevelOffset, 0, + NULL, NULL); + if (error != CL_SUCCESS) + { log_error( "ERROR: Unable to write to 1D image of size %d \n", (int)width_lod ); return -1; } diff --git a/test_conformance/multiple_device_context/test_multiple_devices.cpp b/test_conformance/multiple_device_context/test_multiple_devices.cpp index 59543ade..4f187b9c 100644 --- a/test_conformance/multiple_device_context/test_multiple_devices.cpp +++ b/test_conformance/multiple_device_context/test_multiple_devices.cpp @@ -175,9 +175,8 @@ int test_device_set(size_t deviceCount, size_t queueCount, cl_device_id *devices } /* All done now! */ - if (errors) - return -1; - return 0; + if (errors) return -1; + return 0; } int test_two_devices(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) diff --git a/test_conformance/profiling/execute.cpp b/test_conformance/profiling/execute.cpp index 0541bfa5..44b1bcd4 100644 --- a/test_conformance/profiling/execute.cpp +++ b/test_conformance/profiling/execute.cpp @@ -335,8 +335,8 @@ static int kernelFilter( cl_device_id device, cl_context context, cl_command_que clReleaseMemObject( memobjs[1] ); clReleaseMemObject( memobjs[0] ); - if (check_times(queueStart, submitStart, writeStart, writeEnd, device)) - err = -1; + if (check_times(queueStart, submitStart, writeStart, writeEnd, device)) + err = -1; return err; diff --git a/test_conformance/profiling/writeImage.cpp b/test_conformance/profiling/writeImage.cpp index fbc8fbcd..ec2fbdaf 100644 --- a/test_conformance/profiling/writeImage.cpp +++ b/test_conformance/profiling/writeImage.cpp @@ -628,8 +628,8 @@ int write_image( cl_device_id device, cl_context context, cl_command_queue queue free( dst ); free( inptr ); - if (check_times(queueStart, submitStart, writeStart, writeEnd, device)) - err = -1; + if (check_times(queueStart, submitStart, writeStart, writeEnd, device)) + err = -1; return err;