2013-02-07 18:55:47 +08:00
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
2016-07-29 03:26:30 +08:00
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -Wspir-compat -triple amdgcn--amdhsa
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -triple spir-unknown-unknown
2019-05-27 19:19:07 +08:00
// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -Wspir-compat -triple amdgcn--amdhsa
// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -triple spir-unknown-unknown
2013-02-07 18:55:47 +08:00
2016-07-29 03:26:30 +08:00
# define CLK_ADDRESS_CLAMP_TO_EDGE 2
# define CLK_NORMALIZED_COORDS_TRUE 1
# define CLK_FILTER_NEAREST 0x10
# define CLK_FILTER_LINEAR 0x20
2019-08-12 20:44:26 +08:00
typedef float float4 __attribute__ ( ( ext_vector_type ( 4 ) ) ) ;
float4 read_imagef ( read_only image1d_t, sampler_t, float ) ;
2016-07-29 03:26:30 +08:00
constant sampler_t glb_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR ;
constant sampler_t glb_smp2 ; // expected-error{{variable in constant address space must be initialized}}
2017-05-08 17:29:06 +08:00
global sampler_t glb_smp3 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_NEAREST ; // expected-error{{sampler type cannot be used with the __local and __global address space qualifiers}} expected-error {{global sampler requires a const or constant address space qualifier}}
const global sampler_t glb_smp3_const = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR ; // expected-error{{sampler type cannot be used with the __local and __global address space qualifiers}}
2016-07-29 03:26:30 +08:00
constant sampler_t glb_smp4 = 0 ;
# ifdef CHECK_SAMPLER_VALUE
// expected-warning@-2{{sampler initializer has invalid Filter Mode bits}}
# endif
constant sampler_t glb_smp5 = 0x1f ;
# ifdef CHECK_SAMPLER_VALUE
// expected-warning@-2{{sampler initializer has invalid Addressing Mode bits}}
# endif
constant sampler_t glb_smp6 = glb_smp ; // expected-error{{initializer element is not a compile-time constant}}
int f ( void ) ;
constant sampler_t glb_smp7 = f ( ) ; // expected-error{{initializer element is not a compile-time constant}}
constant sampler_t glb_smp8 = 1.0f ; // expected-error{{initializing '__constant sampler_t' with an expression of incompatible type 'float'}}
constant sampler_t glb_smp9 = 0x100000000LL ; // expected-error{{sampler_t initialization requires 32-bit integer, not 'long long'}}
2013-02-07 18:55:47 +08:00
2017-04-05 17:02:56 +08:00
void foo ( sampler_t ) ; // expected-note{{passing argument to parameter here}}
2016-03-03 21:33:19 +08:00
2018-08-14 21:56:52 +08:00
void constant_sampler ( constant sampler_t s ) ; // expected-error{{parameter may not be qualified with an address space}}
2016-03-03 21:33:19 +08:00
constant struct sampler_s {
2016-07-11 21:46:02 +08:00
sampler_t smp ; // expected-error{{the 'sampler_t' type cannot be used to declare a structure or union field}}
2016-03-03 21:33:19 +08:00
} sampler_str = {0} ;
2013-02-07 18:55:47 +08:00
2016-07-29 03:26:30 +08:00
sampler_t bad ( void ) ; //expected-error{{declaring function return value of type 'sampler_t' is not allowed}}
2017-05-08 17:29:06 +08:00
sampler_t global_nonconst_smp = 0 ; // expected-error {{global sampler requires a const or constant address space qualifier}}
2019-11-27 19:03:11 +08:00
# ifdef CHECK_SAMPLER_VALUE
// expected-warning@-2{{sampler initializer has invalid Filter Mode bits}}
# endif
2017-05-08 17:29:06 +08:00
const sampler_t glb_smp10 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR ;
const constant sampler_t glb_smp11 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR ;
2013-02-07 18:55:47 +08:00
void kernel ker ( sampler_t argsmp ) {
2016-07-11 21:46:02 +08:00
local sampler_t smp ; // expected-error{{sampler type cannot be used with the __local and __global address space qualifiers}}
2016-07-29 03:26:30 +08:00
const sampler_t const_smp5 = 1.0f ; // expected-error{{initializing 'const sampler_t' with an expression of incompatible type 'float'}}
const sampler_t const_smp6 = 0x100000000LL ; // expected-error{{sampler_t initialization requires 32-bit integer, not 'long long'}}
2017-04-05 17:02:56 +08:00
foo ( 5.0f ) ; // expected-error {{passing 'float' to parameter of incompatible type 'sampler_t'}}
2017-11-15 19:38:17 +08:00
sampler_t sa[] = {argsmp, glb_smp} ; // expected-error {{array of 'sampler_t' type is invalid in OpenCL}}
2013-02-07 18:55:47 +08:00
}
2016-02-25 11:34:20 +08:00
2019-05-27 19:19:07 +08:00
# if __OPENCL_C_VERSION__ == 200
2019-11-27 19:03:11 +08:00
void bad ( sampler_t * ) ; // expected-error{{pointer to type 'sampler_t' is invalid in OpenCL}}
2019-05-27 19:19:07 +08:00
# else
2016-07-11 21:46:02 +08:00
void bad ( sampler_t* ) ; // expected-error{{pointer to type 'sampler_t' is invalid in OpenCL}}
2019-05-27 19:19:07 +08:00
# endif
2016-07-11 21:46:02 +08:00
void bar ( ) {
2016-07-29 03:26:30 +08:00
sampler_t smp1 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR ;
sampler_t smp2 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_NEAREST ;
2016-07-11 21:46:02 +08:00
smp1=smp2 ; //expected-error{{invalid operands to binary expression ('sampler_t' and 'sampler_t')}}
smp1+1 ; //expected-error{{invalid operands to binary expression ('sampler_t' and 'int')}}
&smp1 ; //expected-error{{invalid argument type 'sampler_t' to unary expression}}
*smp2 ; //expected-error{{invalid argument type 'sampler_t' to unary expression}}
2016-07-29 03:26:30 +08:00
foo ( smp1+1 ) ; //expected-error{{invalid operands to binary expression ('sampler_t' and 'int')}}
2016-07-11 21:46:02 +08:00
}
2019-08-12 20:44:26 +08:00
void smp_args ( read_only image1d_t image ) {
// Test that parentheses around sampler arguments are ignored.
float4 res = read_imagef ( image, ( glb_smp10 ) , 0.0f ) ;
}