Skip to content

Commit

Permalink
[OpenCL] Enables passing sampler initializer to function argument
Browse files Browse the repository at this point in the history
Reviewers: Anastasia, cfe-commits

Reviewed By: Anastasia

Subscribers: yaxunl, bader

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

llvm-svn: 299524
  • Loading branch information
echuraev committed Apr 5, 2017
1 parent 2641a52 commit a8d2451
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaInit.cpp
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions clang/test/CodeGenOpenCL/sampler.cl
Expand Up @@ -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]])
}
5 changes: 3 additions & 2 deletions clang/test/SemaOpenCL/sampler_t.cl
Expand Up @@ -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}}
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit a8d2451

Please sign in to comment.