Author: Sven van Haastregt Date: 2021-01-28T11:14:19Z New Revision: 526c42e76c12d9cfe83dfa5957fe1715ab8d1faf
URL: https://github.com/llvm/llvm-project/commit/526c42e76c12d9cfe83dfa5957fe1715ab8d1faf DIFF: https://github.com/llvm/llvm-project/commit/526c42e76c12d9cfe83dfa5957fe1715ab8d1faf.diff LOG: [OpenCL] Hide sampler-less read_image builtins before CL1.2 Ensure sampler-less image read functions are not available with `-fdeclare-opencl-builtins` before OpenCL 1.2. Added: Modified: clang/lib/Sema/OpenCLBuiltins.td clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl Removed: ################################################################################ diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td index 745363a6b43f..fd9e24cfc31e 100644 --- a/clang/lib/Sema/OpenCLBuiltins.td +++ b/clang/lib/Sema/OpenCLBuiltins.td @@ -1092,24 +1092,26 @@ foreach coordTy = [Int, Float] in { } // --- Table 23: Sampler-less Read Functions --- -foreach aQual = ["RO", "RW"] in { - foreach imgTy = [Image2d, Image1dArray] in { - def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; - def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; - def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; - } - foreach imgTy = [Image3d, Image2dArray] in { - def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; - def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; - def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; - } - foreach imgTy = [Image1d, Image1dBuffer] in { - def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; - def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; - def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; +let MinVersion = CL12 in { + foreach aQual = ["RO", "RW"] in { + foreach imgTy = [Image2d, Image1dArray] in { + def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; + def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; + def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; + } + foreach imgTy = [Image3d, Image2dArray] in { + def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; + def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; + def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; + } + foreach imgTy = [Image1d, Image1dBuffer] in { + def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; + def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; + def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; + } + def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>; + def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>; } - def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>; - def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>; } // --- Table 24: Image Write Functions --- @@ -1187,16 +1189,18 @@ foreach aQual = ["RO"] in { } // OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions // --- Table 9 --- -foreach aQual = ["RO", "RW"] in { - foreach name = ["read_imageh"] in { - foreach imgTy = [Image2d, Image1dArray] in { - def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; - } - foreach imgTy = [Image3d, Image2dArray] in { - def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; - } - foreach imgTy = [Image1d, Image1dBuffer] in { - def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; +let MinVersion = CL12 in { + foreach aQual = ["RO", "RW"] in { + foreach name = ["read_imageh"] in { + foreach imgTy = [Image2d, Image1dArray] in { + def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; + } + foreach imgTy = [Image3d, Image2dArray] in { + def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; + } + foreach imgTy = [Image1d, Image1dBuffer] in { + def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; + } } } } diff --git a/clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl b/clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl index 64f2d89c5818..e4f4db0cd174 100644 --- a/clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl +++ b/clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -emit-llvm -o - -O0 -triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header %s | FileCheck %s +// RUN: %clang_cc1 -emit-llvm -o - -O0 -triple spir-unknown-unknown -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header %s | FileCheck %s // Test that Attr.Const from OpenCLBuiltins.td is lowered to a readnone attribute. // CHECK-LABEL: @test_const_attr diff --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl index d1dcdfe8cb35..3cf963eb2fba 100644 --- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl +++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl @@ -113,6 +113,12 @@ kernel void basic_image_readonly(read_only image2d_t image_read_only_image2d) { resf = read_imagef(image_read_only_image2d, i2); res = read_imageh(image_read_only_image2d, i2); +#if __OPENCL_C_VERSION__ < CL_VERSION_1_2 && !defined(__OPENCL_CPP_VERSION__) + // expected-error@-3{{no matching function for call to 'read_imagef'}} + // expected-note@-4 + {{candidate function not viable}} + // expected-error@-4{{no matching function for call to 'read_imageh'}} + // expected-note@-5 + {{candidate function not viable}} +#endif res = read_imageh(image_read_only_image2d, sampler, i2); int imgWidth = get_image_width(image_read_only_image2d); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits