summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNagy-Egri Máté Ferenc <nagy-egri.mate@wigner.mta.hu>2020-09-30 08:32:57 +0200
committerGitHub <noreply@github.com>2020-09-30 08:32:57 +0200
commitd65bcc5123f93ce7c6b2a3c164fed35c423fc83d (patch)
treec13e21fe09cfd1d6d8d4ed4bb07db2a0d12de783
parent9d17180a33566500551ff98e9eba62b0867a6f64 (diff)
downloadOpenCL-Headers-d65bcc5123f93ce7c6b2a3c164fed35c423fc83d.tar.gz
OpenCL-Headers-d65bcc5123f93ce7c6b2a3c164fed35c423fc83d.tar.bz2
OpenCL-Headers-d65bcc5123f93ce7c6b2a3c164fed35c423fc83d.zip
Avoid anon structs when MSVC uses /Za (#116)
* Avoid anon structs when MSVC uses /Za * Add popping warning for /Za builds * reuse __CL_HAS_ANON_STRUCT__ * refine MSVC flags * Fix preprocessor predicates * Remove MSVC warning C4224 * Remove MSVC warning C4244 * Revamp warning flags based on compilers * Guard system headers from warnings of extensions * Remove commented code * Remove redundant checks of _WIN32 * Rename param instead of comment
-rw-r--r--CL/cl.h12
-rw-r--r--CL/cl_d3d10.h11
-rw-r--r--CL/cl_d3d11.h11
-rw-r--r--CL/cl_gl_ext.h2
-rw-r--r--CL/cl_half.h6
-rw-r--r--CL/cl_platform.h6
-rw-r--r--tests/CMakeLists.txt20
7 files changed, 51 insertions, 17 deletions
diff --git a/CL/cl.h b/CL/cl.h
index eb9e6b0..fa3bd0e 100644
--- a/CL/cl.h
+++ b/CL/cl.h
@@ -134,23 +134,29 @@ typedef struct _cl_image_desc {
cl_uint num_mip_levels;
cl_uint num_samples;
#ifdef CL_VERSION_2_0
-#ifdef __GNUC__
- __extension__ /* Prevents warnings about anonymous union in -pedantic builds */
-#endif
+#if __CL_HAS_ANON_STRUCT__
#ifdef _MSC_VER
+#if _MSC_VER >= 1500
#pragma warning( push )
#pragma warning( disable : 4201 ) /* Prevents warning about nameless struct/union in /W4 /Za builds */
#endif
+#endif
+ __CL_ANON_STRUCT__
union {
#endif
+#endif
cl_mem buffer;
#ifdef CL_VERSION_2_0
+#if __CL_HAS_ANON_STRUCT__
cl_mem mem_object;
};
#ifdef _MSC_VER
+#if _MSC_VER >= 1500
#pragma warning( pop )
#endif
#endif
+#endif
+#endif
} cl_image_desc;
#endif
diff --git a/CL/cl_d3d10.h b/CL/cl_d3d10.h
index cda5469..2b80d90 100644
--- a/CL/cl_d3d10.h
+++ b/CL/cl_d3d10.h
@@ -17,7 +17,18 @@
#ifndef __OPENCL_CL_D3D10_H
#define __OPENCL_CL_D3D10_H
+#if defined(_MSC_VER)
+#if _MSC_VER >=1500
+#pragma warning( push )
+#pragma warning( disable : 4201 )
+#endif
+#endif
#include <d3d10.h>
+#if defined(_MSC_VER)
+#if _MSC_VER >=1500
+#pragma warning( pop )
+#endif
+#endif
#include <CL/cl.h>
#include <CL/cl_platform.h>
diff --git a/CL/cl_d3d11.h b/CL/cl_d3d11.h
index 6b7e2e9..10023dd 100644
--- a/CL/cl_d3d11.h
+++ b/CL/cl_d3d11.h
@@ -17,7 +17,18 @@
#ifndef __OPENCL_CL_D3D11_H
#define __OPENCL_CL_D3D11_H
+#if defined(_MSC_VER)
+#if _MSC_VER >=1500
+#pragma warning( push )
+#pragma warning( disable : 4201 )
+#endif
+#endif
#include <d3d11.h>
+#if defined(_MSC_VER)
+#if _MSC_VER >=1500
+#pragma warning( pop )
+#endif
+#endif
#include <CL/cl.h>
#include <CL/cl_platform.h>
diff --git a/CL/cl_gl_ext.h b/CL/cl_gl_ext.h
index 9bb7540..52107b1 100644
--- a/CL/cl_gl_ext.h
+++ b/CL/cl_gl_ext.h
@@ -30,7 +30,7 @@ extern "C" {
extern CL_API_ENTRY cl_event CL_API_CALL
clCreateEventFromGLsyncKHR(cl_context context,
- cl_GLsync cl_GLsync,
+ cl_GLsync sync,
cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1;
#ifdef __cplusplus
diff --git a/CL/cl_half.h b/CL/cl_half.h
index f748d9e..ecc4223 100644
--- a/CL/cl_half.h
+++ b/CL/cl_half.h
@@ -127,7 +127,7 @@ static inline cl_half cl_half_from_float(cl_float f, cl_half_rounding_mode round
int32_t exp = f_exp - CL_FLT_MAX_EXP + 1;
// Add FP16 exponent bias
- uint16_t h_exp = exp + CL_HALF_MAX_EXP - 1;
+ uint16_t h_exp = (uint16_t)(exp + CL_HALF_MAX_EXP - 1);
// Position of the bit that will become the FP16 mantissa LSB
uint32_t lsb_pos = CL_FLT_MANT_DIG - CL_HALF_MANT_DIG;
@@ -138,7 +138,7 @@ static inline cl_half cl_half_from_float(cl_float f, cl_half_rounding_mode round
if (f_mant)
{
// NaN -> propagate mantissa and silence it
- uint16_t h_mant = f_mant >> lsb_pos;
+ uint16_t h_mant = (uint16_t)(f_mant >> lsb_pos);
h_mant |= 0x200;
return (sign << 15) | CL_HALF_EXP_MASK | h_mant;
}
@@ -179,7 +179,7 @@ static inline cl_half cl_half_from_float(cl_float f, cl_half_rounding_mode round
}
// Generate FP16 mantissa by shifting FP32 mantissa
- uint16_t h_mant = f_mant >> lsb_pos;
+ uint16_t h_mant = (uint16_t)(f_mant >> lsb_pos);
// Check whether we need to round
uint32_t halfway = 1 << (lsb_pos - 1);
diff --git a/CL/cl_platform.h b/CL/cl_platform.h
index 3f7d4da..8ba168a 100644
--- a/CL/cl_platform.h
+++ b/CL/cl_platform.h
@@ -484,7 +484,7 @@ typedef unsigned int cl_GLenum;
#elif defined( __GNUC__) && ! defined( __STRICT_ANSI__ )
#define __CL_HAS_ANON_STRUCT__ 1
#define __CL_ANON_STRUCT__ __extension__
-#elif defined( _WIN32) && defined(_MSC_VER)
+#elif defined( _WIN32) && defined(_MSC_VER) && ! defined(__STDC__)
#if _MSC_VER >= 1500
/* Microsoft Developer Studio 2008 supports anonymous structs, but
* complains by default. */
@@ -1375,9 +1375,7 @@ typedef union
}
#endif
-#undef __CL_HAS_ANON_STRUCT__
-#undef __CL_ANON_STRUCT__
-#if defined( _WIN32) && defined(_MSC_VER)
+#if defined( _WIN32) && defined(_MSC_VER) && ! defined(__STDC__)
#if _MSC_VER >=1500
#pragma warning( pop )
#endif
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 682a9f5..32d8312 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -6,18 +6,26 @@ enable_testing()
include_directories(${PROJECT_SOURCE_DIR}/..)
-# Make sure headers do not produce warnings
-if (NOT MSVC)
-add_compile_options(-Wall -Wextra -Werror -pedantic -Wno-format)
-endif ()
-
# Add a test for a given source file for each version of OpenCL
function(add_header_test NAME SOURCE)
foreach(VERSION 100 110 120 200 210 220 300)
set(TEST_EXE ${NAME}_${VERSION})
add_executable(${TEST_EXE} ${SOURCE})
target_compile_definitions(${TEST_EXE}
- PUBLIC -DCL_TARGET_OPENCL_VERSION=${VERSION}
+ PUBLIC
+ -DCL_TARGET_OPENCL_VERSION=${VERSION}
+ )
+ # ICD on Windows uses system headers, which aren't strictly ANSI conformant
+ # and trigger warnings
+ if(${NAME} STREQUAL cl_icd_h)
+ set(MSVC_COMPILE_DEFS /W4 /WX)
+ else()
+ set(MSVC_COMPILE_DEFS /W4 /WX /Za)
+ endif()
+ target_compile_options(${TEST_EXE}
+ PUBLIC
+ $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Werror -pedantic -Wno-format>
+ $<$<CXX_COMPILER_ID:MSVC>:${MSVC_COMPILE_DEFS}>
)
add_test(NAME ${TEST_EXE} COMMAND ${TEST_EXE})
endforeach(VERSION)