From 5a7764c9ff5db8c460b52bc2dec95d19df44d4c8 Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Tue, 13 Sep 2022 10:10:48 +0100 Subject: [PATCH] [OpenCL] Guard depth image builtins Ensure any uses of `image2d_depth_t` and `image2d_array_depth_t` are guarded behind the `cl_khr_depth_images` extension in `OpenCLBuiltins.td`. Fix a few missing guards in `opencl-c.h`. --- clang/lib/Headers/opencl-c.h | 14 ++++++++++++++ clang/lib/Sema/OpenCLBuiltins.td | 1 + 2 files changed, 15 insertions(+) diff --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h index 8499ee0..2afe023 100644 --- a/clang/lib/Headers/opencl-c.h +++ b/clang/lib/Headers/opencl-c.h @@ -15257,13 +15257,17 @@ float4 __ovld __purefn read_imagef(read_only image2d_t, sampler_t, float2, float int4 __ovld __purefn read_imagei(read_only image2d_t, sampler_t, float2, float); uint4 __ovld __purefn read_imageui(read_only image2d_t, sampler_t, float2, float); +#ifdef cl_khr_depth_images float __ovld __purefn read_imagef(read_only image2d_depth_t, sampler_t, float2, float); +#endif // cl_khr_depth_images float4 __ovld __purefn read_imagef(read_only image2d_array_t, sampler_t, float4, float); int4 __ovld __purefn read_imagei(read_only image2d_array_t, sampler_t, float4, float); uint4 __ovld __purefn read_imageui(read_only image2d_array_t, sampler_t, float4, float); +#ifdef cl_khr_depth_images float __ovld __purefn read_imagef(read_only image2d_array_depth_t, sampler_t, float4, float); +#endif // cl_khr_depth_images float4 __ovld __purefn read_imagef(read_only image3d_t, sampler_t, float4, float); int4 __ovld __purefn read_imagei(read_only image3d_t, sampler_t, float4, float); @@ -15281,13 +15285,17 @@ float4 __ovld __purefn read_imagef(read_only image2d_t, sampler_t, float2, float int4 __ovld __purefn read_imagei(read_only image2d_t, sampler_t, float2, float2, float2); uint4 __ovld __purefn read_imageui(read_only image2d_t, sampler_t, float2, float2, float2); +#ifdef cl_khr_depth_images float __ovld __purefn read_imagef(read_only image2d_depth_t, sampler_t, float2, float2, float2); +#endif // cl_khr_depth_images float4 __ovld __purefn read_imagef(read_only image2d_array_t, sampler_t, float4, float2, float2); int4 __ovld __purefn read_imagei(read_only image2d_array_t, sampler_t, float4, float2, float2); uint4 __ovld __purefn read_imageui(read_only image2d_array_t, sampler_t, float4, float2, float2); +#ifdef cl_khr_depth_images float __ovld __purefn read_imagef(read_only image2d_array_depth_t, sampler_t, float4, float2, float2); +#endif // cl_khr_depth_images float4 __ovld __purefn read_imagef(read_only image3d_t, sampler_t, float4, float4, float4); int4 __ovld __purefn read_imagei(read_only image3d_t, sampler_t, float4, float4, float4); @@ -15829,19 +15837,25 @@ int __ovld get_image_num_mip_levels(read_write image3d_t); int __ovld get_image_num_mip_levels(read_only image1d_array_t); int __ovld get_image_num_mip_levels(read_only image2d_array_t); +#ifdef cl_khr_depth_images int __ovld get_image_num_mip_levels(read_only image2d_array_depth_t); int __ovld get_image_num_mip_levels(read_only image2d_depth_t); +#endif // cl_khr_depth_images int __ovld get_image_num_mip_levels(write_only image1d_array_t); int __ovld get_image_num_mip_levels(write_only image2d_array_t); +#ifdef cl_khr_depth_images int __ovld get_image_num_mip_levels(write_only image2d_array_depth_t); int __ovld get_image_num_mip_levels(write_only image2d_depth_t); +#endif // cl_khr_depth_images #if defined(__opencl_c_read_write_images) int __ovld get_image_num_mip_levels(read_write image1d_array_t); int __ovld get_image_num_mip_levels(read_write image2d_array_t); +#ifdef cl_khr_depth_images int __ovld get_image_num_mip_levels(read_write image2d_array_depth_t); int __ovld get_image_num_mip_levels(read_write image2d_depth_t); +#endif // cl_khr_depth_images #endif //defined(__opencl_c_read_write_images) #endif //cl_khr_mipmap_image diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td index dc15845..0cceba0 100644 --- a/clang/lib/Sema/OpenCLBuiltins.td +++ b/clang/lib/Sema/OpenCLBuiltins.td @@ -246,6 +246,7 @@ class ImageType : let Extension = !cond( !and(!eq(_Ty.Name, "image3d_t"), !eq(_AccessQualifier, "WO")) : TypeExtension<"cl_khr_3d_image_writes">, !and(!eq(_Ty.Name, "image3d_t"), !eq(_AccessQualifier, "RW")) : TypeExtension<"cl_khr_3d_image_writes __opencl_c_read_write_images">, + !or(!eq(_Ty.Name, "image2d_depth_t"), !eq(_Ty.Name, "image2d_array_depth_t")) : TypeExtension<"cl_khr_depth_images">, !eq(_AccessQualifier, "RW") : TypeExtension<"__opencl_c_read_write_images">, true : _Ty.Extension); } -- 2.7.4