From e96d9a5b935fc7f5fef9c33e5829ed0a6dfd3178 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Wed, 28 May 2025 14:11:40 +0200 Subject: [PATCH 1/2] Rework anon union usage in cl.h We already have helper macros in cl_platform.h we can use instead of the current mess. --- CL/cl.h | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/CL/cl.h b/CL/cl.h index 792e20cc..d5577201 100644 --- a/CL/cl.h +++ b/CL/cl.h @@ -24,6 +24,12 @@ extern "C" { #endif +#if defined(_WIN32) && defined(_MSC_VER) && __CL_HAS_ANON_STRUCT__ + /* Disable warning C4201: nonstandard extension used : nameless struct/union */ + #pragma warning( push ) + #pragma warning( disable : 4201 ) +#endif + /******************************************************************************/ typedef struct _cl_platform_id * cl_platform_id; @@ -133,39 +139,14 @@ typedef struct _cl_image_desc { size_t image_slice_pitch; cl_uint num_mip_levels; cl_uint num_samples; -#ifdef CL_VERSION_2_0 -#if defined(__GNUC__) - __extension__ /* Prevents warnings about anonymous union in -pedantic builds */ -#endif -#if defined(_MSC_VER) && !defined(__STDC__) -#pragma warning( push ) -#pragma warning( disable : 4201 ) /* Prevents warning about nameless struct/union in /W4 builds */ -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wc11-extensions" /* Prevents warning about nameless union being C11 extension*/ -#endif -#if defined(_MSC_VER) && defined(__STDC__) - /* Anonymous unions are not supported in /Za builds */ -#else - union { -#endif +#if defined(CL_VERSION_2_0) && __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ union { #endif cl_mem buffer; -#ifdef CL_VERSION_2_0 -#if defined(_MSC_VER) && defined(__STDC__) - /* Anonymous unions are not supported in /Za builds */ -#else +#if defined(CL_VERSION_2_0) && __CL_HAS_ANON_STRUCT__ cl_mem mem_object; }; #endif -#if defined(_MSC_VER) && !defined(__STDC__) -#pragma warning( pop ) -#endif -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#endif } cl_image_desc; #endif @@ -1932,4 +1913,8 @@ clEnqueueTask(cl_command_queue command_queue, } #endif +#if defined(_WIN32) && defined(_MSC_VER) && __CL_HAS_ANON_STRUCT__ + #pragma warning( pop ) +#endif + #endif /* __OPENCL_CL_H */ From 66265a6fc8565561e841dde4314a809b825ddd50 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Tue, 27 May 2025 20:31:48 +0200 Subject: [PATCH 2/2] Add unions for ICD2 tags in cl_icd_dispatch I need this, because otherwise rustc doesn't let me use a constant in place of a function pointer. But I think being more explicit here would make the code a bit cleaner for loader implementors. --- CL/cl_icd.h | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/CL/cl_icd.h b/CL/cl_icd.h index 435ad483..bce60ea2 100644 --- a/CL/cl_icd.h +++ b/CL/cl_icd.h @@ -22,6 +22,7 @@ #include #include #include +#include #if defined(_WIN32) #include @@ -29,6 +30,12 @@ #include #endif +#if defined(_WIN32) && defined(_MSC_VER) && __CL_HAS_ANON_STRUCT__ + /* Disable warning C4201: nonstandard extension used : nameless struct/union */ + #pragma warning( push ) + #pragma warning( disable : 4201 ) +#endif + #ifdef __cplusplus extern "C" { #endif @@ -37,7 +44,15 @@ extern "C" { typedef struct _cl_icd_dispatch { /* OpenCL 1.0 */ - clGetPlatformIDs_t *clGetPlatformIDs; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ union { +#endif + clGetPlatformIDs_t *clGetPlatformIDs; +#if __CL_HAS_ANON_STRUCT__ + /* Set to CL_ICD2_TAG_KHR for cl_khr_icd 2.0.0 */ + intptr_t clGetPlatformIDs_icd2_tag; + }; +#endif clGetPlatformInfo_t *clGetPlatformInfo; clGetDeviceIDs_t *clGetDeviceIDs; clGetDeviceInfo_t *clGetDeviceInfo; @@ -68,7 +83,15 @@ typedef struct _cl_icd_dispatch { clRetainProgram_t *clRetainProgram; clReleaseProgram_t *clReleaseProgram; clBuildProgram_t *clBuildProgram; - clUnloadCompiler_t *clUnloadCompiler; +#if __CL_HAS_ANON_STRUCT__ + __CL_ANON_STRUCT__ union { +#endif + clUnloadCompiler_t *clUnloadCompiler; +#if __CL_HAS_ANON_STRUCT__ + /* Set to CL_ICD2_TAG_KHR for cl_khr_icd 2.0.0 */ + intptr_t clUnloadCompiler_icd2_tag; + }; +#endif clGetProgramInfo_t *clGetProgramInfo; clGetProgramBuildInfo_t *clGetProgramBuildInfo; clCreateKernel_t *clCreateKernel; @@ -312,4 +335,8 @@ typedef struct _cl_icd_dispatch { } #endif +#if defined(_WIN32) && defined(_MSC_VER) && __CL_HAS_ANON_STRUCT__ + #pragma warning( pop ) +#endif + #endif /* #ifndef OPENCL_CL_ICD_H */