]> granicus.if.org Git - clang/commitdiff
[OpenCL] Enables passing sampler initializer to function argument
authorEgor Churaev <egor.churaev@gmail.com>
Wed, 5 Apr 2017 09:02:56 +0000 (09:02 +0000)
committerEgor Churaev <egor.churaev@gmail.com>
Wed, 5 Apr 2017 09:02:56 +0000 (09:02 +0000)
Reviewers: Anastasia, cfe-commits

Reviewed By: Anastasia

Subscribers: yaxunl, bader

Differential Revision: https://reviews.llvm.org/D31594

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299524 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/CodeGenOpenCL/sampler.cl
test/SemaOpenCL/sampler_t.cl

index 08631a1051f6043803e2df9facf1dc1d6c822121..a50244e51c0b72d951f9aaee99765c105c382b51 100644 (file)
@@ -7174,7 +7174,7 @@ InitializationSequence::Perform(Sema &S,
       QualType SourceType = Init->getType();
       // Case 1
       if (Entity.isParameterKind()) {
-        if (!SourceType->isSamplerT()) {
+        if (!SourceType->isSamplerT() && !SourceType->isIntegerType()) {
           S.Diag(Kind.getLocation(), diag::err_sampler_argument_required)
             << SourceType;
           break;
index 6fc8c2c68446999bf753dd997cd4c7214a1964cc..3a7319cd78d29cdff0def97fab12e65f1d8239e7 100644 (file)
@@ -54,4 +54,8 @@ kernel void foo(sampler_t smp_par) {
   fnc4smp(smp_par);
   // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** [[smp_par_ptr]]
   // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
+
+  fnc4smp(5);
+  // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 5)
+  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
 }
index c87b6da7c7e129eba1fd37b48840417445838939..0dddeeb39013ac103a4df10d44e2bb8631af3dbd 100644 (file)
@@ -30,7 +30,7 @@ constant sampler_t glb_smp8 = 1.0f; // expected-error{{initializing '__constant
 
 constant sampler_t glb_smp9 = 0x100000000LL; // expected-error{{sampler_t initialization requires 32-bit integer, not 'long long'}}
 
-void foo(sampler_t);
+void foo(sampler_t); // expected-note{{passing argument to parameter here}}
 
 constant struct sampler_s {
   sampler_t smp; // expected-error{{the 'sampler_t' type cannot be used to declare a structure or union field}}
@@ -65,7 +65,8 @@ void kernel ker(sampler_t argsmp) {
   foo(const_smp5);
   foo(const_smp6);
   foo(argsmp);
-  foo(5); // expected-error{{sampler_t variable required - got 'int'}}
+  foo(5);
+  foo(5.0f); // expected-error {{passing 'float' to parameter of incompatible type 'sampler_t'}}
   sampler_t sa[] = {argsmp, const_smp}; // expected-error {{array of 'sampler_t' type is invalid in OpenCL}}
   foo(sa[0]);
   foo(bad());