Skip to content

Commit

Permalink
Re-enabling narrowing errors
Browse files Browse the repository at this point in the history
Fixes narrowing conversion build errors in test_common

Removing disable of narrowing errors in main CMakeLists.txt
and moving it down to test_conformance CMakeLists.txt where
there are many more build errors revealed from this fix

Contributes KhronosGroup#787

Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>
  • Loading branch information
ellnor01 committed Apr 28, 2021
1 parent 01497c4 commit 60125f6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ 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(-Wno-narrowing)
add_cxx_flag_if_supported(-Wno-format)
add_cxx_flag_if_supported(-Werror)
add_cxx_flag_if_supported(-Wno-error=cpp) # Allow #warning directive
Expand Down
14 changes: 7 additions & 7 deletions test_common/harness/kernelHelpers.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2017 The Khronos Group Inc.
// Copyright (c) 2017, 2021 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1730,7 +1730,7 @@ Version get_device_cl_c_version(cl_device_id device)
&opencl_c_version_size_in_bytes);
test_error_ret(error,
"clGetDeviceInfo failed for CL_DEVICE_OPENCL_C_VERSION\n",
(Version{ -1, 0 }));
(Version{ 0, 0 }));

std::string opencl_c_version(opencl_c_version_size_in_bytes, '\0');
error =
Expand All @@ -1739,13 +1739,13 @@ Version get_device_cl_c_version(cl_device_id device)

test_error_ret(error,
"clGetDeviceInfo failed for CL_DEVICE_OPENCL_C_VERSION\n",
(Version{ -1, 0 }));
(Version{ 0, 0 }));

// Scrape out the major, minor pair from the string.
auto major = opencl_c_version[opencl_c_version.find('.') - 1];
auto minor = opencl_c_version[opencl_c_version.find('.') + 1];

return Version{ major - '0', minor - '0' };
return Version{ (uint)(major - '0'), (uint)(minor - '0') };
}

Version get_device_latest_cl_c_version(cl_device_id device)
Expand All @@ -1763,15 +1763,15 @@ Version get_device_latest_cl_c_version(cl_device_id device)
&opencl_c_all_versions_size_in_bytes);
test_error_ret(
error, "clGetDeviceInfo failed for CL_DEVICE_OPENCL_C_ALL_VERSIONS",
(Version{ -1, 0 }));
(Version{ 0, 0 }));
std::vector<cl_name_version> name_versions(
opencl_c_all_versions_size_in_bytes / sizeof(cl_name_version));
error = clGetDeviceInfo(device, CL_DEVICE_OPENCL_C_ALL_VERSIONS,
opencl_c_all_versions_size_in_bytes,
name_versions.data(), nullptr);
test_error_ret(
error, "clGetDeviceInfo failed for CL_DEVICE_OPENCL_C_ALL_VERSIONS",
(Version{ -1, 0 }));
(Version{ 0, 0 }));

Version max_supported_cl_c_version{};
for (const auto &name_version : name_versions)
Expand All @@ -1797,7 +1797,7 @@ Version get_max_OpenCL_C_for_context(cl_context context)
auto error = clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, nullptr,
&devices_size_in_bytes);
test_error_ret(error, "clGetDeviceInfo failed for CL_CONTEXT_DEVICES",
(Version{ -1, 0 }));
(Version{ 0, 0 }));
std::vector<cl_device_id> devices(devices_size_in_bytes
/ sizeof(cl_device_id));
error = clGetContextInfo(context, CL_CONTEXT_DEVICES, devices_size_in_bytes,
Expand Down
6 changes: 3 additions & 3 deletions test_common/harness/rounding_mode.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2017 The Khronos Group Inc.
// Copyright (c) 2017, 2021 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -203,7 +203,7 @@ void *FlushToZero(void)
#if defined(__APPLE__) || defined(__linux__) || defined(_WIN32)
#if defined(__i386__) || defined(__x86_64__) || defined(_MSC_VER)
union {
int i;
uint i;
void *p;
} u = { _mm_getcsr() };
_mm_setcsr(u.i | 0x8040);
Expand Down Expand Up @@ -235,7 +235,7 @@ void UnFlushToZero(void *p)
#if defined(__i386__) || defined(__x86_64__) || defined(_MSC_VER)
union {
void *p;
int i;
uint i;
} u = { p };
_mm_setcsr(u.i);
#elif defined(__arm__) || defined(__aarch64__)
Expand Down
8 changes: 4 additions & 4 deletions test_common/harness/testHarness.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2017-2019 The Khronos Group Inc.
// Copyright (c) 2017-2021 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -26,7 +26,7 @@
class Version {
public:
Version(): m_major(0), m_minor(0) {}
Version(int major, int minor): m_major(major), m_minor(minor) {}
Version(uint major, uint minor): m_major(major), m_minor(minor) {}
bool operator>(const Version &rhs) const { return to_int() > rhs.to_int(); }
bool operator<(const Version &rhs) const { return to_int() < rhs.to_int(); }
bool operator<=(const Version &rhs) const
Expand All @@ -50,8 +50,8 @@ class Version {
}

private:
int m_major;
int m_minor;
uint m_major;
uint m_minor;
};

Version get_device_cl_version(cl_device_id device);
Expand Down
4 changes: 4 additions & 0 deletions test_conformance/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Remember current source directory (`test_conformance').
set( CLConf_Install_Base_Dir "${CMAKE_CURRENT_SOURCE_DIR}" )

if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang")
add_cxx_flag_if_supported(-Wno-narrowing)
endif()

set(HARNESS_LIB harness)

add_subdirectory( allocations )
Expand Down

0 comments on commit 60125f6

Please sign in to comment.