From 2c9e7d3a7f42eac6e6b3bdb9c95f2401188abf9c Mon Sep 17 00:00:00 2001 From: Ellen Norris-Thompson Date: Fri, 12 Feb 2021 11:21:28 +0000 Subject: [PATCH] Fix narrowing errors in compiler and spirv_new Contributes #787 Signed-off-by: Ellen Norris-Thompson --- test_conformance/compiler/CMakeLists.txt | 4 ---- test_conformance/compiler/test_preprocessor.cpp | 8 ++++---- .../cl_khr_command_buffer/command_buffer_printf.cpp | 4 +++- .../negative_command_buffer_create.cpp | 3 +-- .../spirv_new/test_op_composite_construct.cpp | 2 +- test_conformance/spirv_new/test_op_constant.cpp | 4 ++-- test_conformance/spirv_new/test_op_copy_object.cpp | 4 ++-- 7 files changed, 13 insertions(+), 16 deletions(-) diff --git a/test_conformance/compiler/CMakeLists.txt b/test_conformance/compiler/CMakeLists.txt index 5806469a98..e703471d28 100644 --- a/test_conformance/compiler/CMakeLists.txt +++ b/test_conformance/compiler/CMakeLists.txt @@ -1,9 +1,5 @@ set(MODULE_NAME COMPILER) -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_build_helpers.cpp diff --git a/test_conformance/compiler/test_preprocessor.cpp b/test_conformance/compiler/test_preprocessor.cpp index 7308950aee..3c5c2045ea 100644 --- a/test_conformance/compiler/test_preprocessor.cpp +++ b/test_conformance/compiler/test_preprocessor.cpp @@ -89,7 +89,7 @@ int test_preprocessor_define_udef(cl_device_id deviceID, cl_context context, cl_ error = clEnqueueWriteBuffer(queue, buffer[0], CL_TRUE, 0, num_elements*sizeof(cl_int), srcData, 0, NULL, NULL); test_error(error, "clEnqueueWriteBuffer failed"); - size_t threads[3] = {num_elements, 0, 0}; + size_t threads[3] = { (size_t)num_elements, 0, 0 }; error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, threads, NULL, 0, NULL, NULL); test_error(error, "clEnqueueNDRangeKernel failed"); @@ -175,7 +175,7 @@ int test_preprocessor_include(cl_device_id deviceID, cl_context context, cl_comm error = clSetKernelArg(kernel, 1, sizeof(buffer[1]), &buffer[1]); test_error(error, "clSetKernelArg failed"); - size_t threads[3] = {num_elements, 0, 0}; + size_t threads[3] = { (size_t)num_elements, 0, 0 }; error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, threads, NULL, 0, NULL, NULL); test_error(error, "clEnqueueNDRangeKernel failed"); @@ -272,7 +272,7 @@ int test_preprocessor_line_error(cl_device_id deviceID, cl_context context, cl_c error = clSetKernelArg(kernel, 0, sizeof(buffer[0]), &buffer[0]); test_error(error, "clSetKernelArg failed"); - size_t threads[3] = {num_elements, 0, 0}; + size_t threads[3] = { (size_t)num_elements, 0, 0 }; error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, threads, NULL, 0, NULL, NULL); test_error(error, "clEnqueueNDRangeKernel failed"); @@ -313,7 +313,7 @@ int test_preprocessor_pragma(cl_device_id deviceID, cl_context context, cl_comma error = clSetKernelArg(kernel, 0, sizeof(buffer[0]), &buffer[0]); test_error(error, "clSetKernelArg failed"); - size_t threads[3] = {num_elements, 0, 0}; + size_t threads[3] = { (size_t)num_elements, 0, 0 }; error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, threads, NULL, 0, NULL, NULL); test_error(error, "clEnqueueNDRangeKernel failed"); diff --git a/test_conformance/extensions/cl_khr_command_buffer/command_buffer_printf.cpp b/test_conformance/extensions/cl_khr_command_buffer/command_buffer_printf.cpp index f0e4f56770..a20e8d3299 100644 --- a/test_conformance/extensions/cl_khr_command_buffer/command_buffer_printf.cpp +++ b/test_conformance/extensions/cl_khr_command_buffer/command_buffer_printf.cpp @@ -274,7 +274,9 @@ struct CommandBufferPrintfTest : public BasicCommandBufferTest &pattern[0], 0, nullptr, nullptr); test_error(error, "clEnqueueWriteBuffer failed"); - size_t offset[] = { 0, pattern.size() - 1 }; + test_assert_error(pattern.size() - 1 <= CL_UINT_MAX, + "pattern.size() - 1 does not fit in a cl_uint"); + cl_uint offset[] = { 0, static_cast(pattern.size() - 1) }; error = clEnqueueWriteBuffer(queue, off_mem, CL_TRUE, 0, sizeof(offset), offset, 0, nullptr, nullptr); test_error(error, "clEnqueueWriteBuffer failed"); diff --git a/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_create.cpp b/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_create.cpp index 751711f1ba..aa63f4ba2b 100644 --- a/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_create.cpp +++ b/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_create.cpp @@ -115,8 +115,7 @@ struct CreateCommandBufferRepeatedProperties : public BasicCommandBufferTest TEST_FAIL); cl_command_buffer_properties_khr invalid_properties[3] = { - CL_COMMAND_BUFFER_FLAGS_KHR, - (cl_command_buffer_properties_khr)CL_INVALID_PROPERTY, 0 + CL_COMMAND_BUFFER_FLAGS_KHR, (cl_command_buffer_properties_khr)-1, 0 }; command_buffer = diff --git a/test_conformance/spirv_new/test_op_composite_construct.cpp b/test_conformance/spirv_new/test_op_composite_construct.cpp index 7ca8762611..db4a66bf21 100644 --- a/test_conformance/spirv_new/test_op_composite_construct.cpp +++ b/test_conformance/spirv_new/test_op_composite_construct.cpp @@ -68,7 +68,7 @@ TEST_SPIRV_FUNC(op_composite_construct_struct) typedef AbstractStruct2 CustomType1; typedef AbstractStruct2 CustomType2; - CustomType1 value1 = {2100483600, 128}; + CustomType1 value1 = { 2100483600, (char)128 }; cl_int2 intvals = { { 2100480000, 2100480000 } }; CustomType2 value2 = {intvals, value1}; diff --git a/test_conformance/spirv_new/test_op_constant.cpp b/test_conformance/spirv_new/test_op_constant.cpp index c026fd42ff..c3b7c58fbb 100644 --- a/test_conformance/spirv_new/test_op_constant.cpp +++ b/test_conformance/spirv_new/test_op_constant.cpp @@ -122,7 +122,7 @@ TEST_SPIRV_FUNC(op_constant_struct_int_float_simple) TEST_SPIRV_FUNC(op_constant_struct_int_char_simple) { - AbstractStruct2 value = {2100483600, 128}; + AbstractStruct2 value = { 2100483600, (char)128 }; std::vector > results(256, value); return test_constant(deviceID, context, queue, "constant_struct_int_char_simple", results); } @@ -132,7 +132,7 @@ TEST_SPIRV_FUNC(op_constant_struct_struct_simple) typedef AbstractStruct2 CustomType1; typedef AbstractStruct2 CustomType2; - CustomType1 value1 = {2100483600, 128}; + CustomType1 value1 = { 2100483600, (char)128 }; cl_int2 intvals = { { 2100480000, 2100480000 } }; CustomType2 value2 = {intvals, value1}; diff --git a/test_conformance/spirv_new/test_op_copy_object.cpp b/test_conformance/spirv_new/test_op_copy_object.cpp index b012960efc..019b603323 100644 --- a/test_conformance/spirv_new/test_op_copy_object.cpp +++ b/test_conformance/spirv_new/test_op_copy_object.cpp @@ -118,7 +118,7 @@ TEST_SPIRV_FUNC(op_copy_struct_int_float_simple) TEST_SPIRV_FUNC(op_copy_struct_int_char_simple) { - AbstractStruct2 value = {2100483600, 128}; + AbstractStruct2 value = { 2100483600, (char)128 }; std::vector > results(256, value); return test_copy(deviceID, context, queue, "copy_struct_int_char_simple", results); } @@ -128,7 +128,7 @@ TEST_SPIRV_FUNC(op_copy_struct_struct_simple) typedef AbstractStruct2 CustomType1; typedef AbstractStruct2 CustomType2; - CustomType1 value1 = {2100483600, 128}; + CustomType1 value1 = { 2100483600, (char)128 }; cl_int2 intvals = { { 2100480000, 2100480000 } }; CustomType2 value2 = {intvals, value1};