Guy Benyei | 6105419 | 2013-02-07 10:55:47 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only |
Yaxun Liu | 0bc4b2d | 2016-07-28 19:26:30 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -Wspir-compat -triple amdgcn--amdhsa |
| 3 | // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -triple spir-unknown-unknown |
Guy Benyei | 6105419 | 2013-02-07 10:55:47 +0000 | [diff] [blame] | 4 | |
Yaxun Liu | 0bc4b2d | 2016-07-28 19:26:30 +0000 | [diff] [blame] | 5 | #define CLK_ADDRESS_CLAMP_TO_EDGE 2 |
| 6 | #define CLK_NORMALIZED_COORDS_TRUE 1 |
| 7 | #define CLK_FILTER_NEAREST 0x10 |
| 8 | #define CLK_FILTER_LINEAR 0x20 |
| 9 | |
| 10 | constant sampler_t glb_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR; |
| 11 | constant sampler_t glb_smp2; // expected-error{{variable in constant address space must be initialized}} |
Sven van Haastregt | 511f0b8 | 2017-05-08 09:29:06 +0000 | [diff] [blame] | 12 | 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}} |
| 13 | 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}} |
Yaxun Liu | 0bc4b2d | 2016-07-28 19:26:30 +0000 | [diff] [blame] | 14 | |
| 15 | constant sampler_t glb_smp4 = 0; |
| 16 | #ifdef CHECK_SAMPLER_VALUE |
| 17 | // expected-warning@-2{{sampler initializer has invalid Filter Mode bits}} |
| 18 | #endif |
| 19 | |
| 20 | constant sampler_t glb_smp5 = 0x1f; |
| 21 | #ifdef CHECK_SAMPLER_VALUE |
| 22 | // expected-warning@-2{{sampler initializer has invalid Addressing Mode bits}} |
| 23 | #endif |
| 24 | |
| 25 | constant sampler_t glb_smp6 = glb_smp; // expected-error{{initializer element is not a compile-time constant}} |
| 26 | |
| 27 | int f(void); |
| 28 | constant sampler_t glb_smp7 = f(); // expected-error{{initializer element is not a compile-time constant}} |
| 29 | |
| 30 | constant sampler_t glb_smp8 = 1.0f; // expected-error{{initializing '__constant sampler_t' with an expression of incompatible type 'float'}} |
| 31 | |
| 32 | constant sampler_t glb_smp9 = 0x100000000LL; // expected-error{{sampler_t initialization requires 32-bit integer, not 'long long'}} |
Guy Benyei | 6105419 | 2013-02-07 10:55:47 +0000 | [diff] [blame] | 33 | |
Egor Churaev | a8d2451 | 2017-04-05 09:02:56 +0000 | [diff] [blame] | 34 | void foo(sampler_t); // expected-note{{passing argument to parameter here}} |
Anastasia Stulova | 1f95cc0 | 2016-03-03 13:33:19 +0000 | [diff] [blame] | 35 | |
Sven van Haastregt | 22d57d9 | 2018-08-14 13:56:52 +0000 | [diff] [blame] | 36 | void constant_sampler(constant sampler_t s); // expected-error{{parameter may not be qualified with an address space}} |
| 37 | |
Anastasia Stulova | 1f95cc0 | 2016-03-03 13:33:19 +0000 | [diff] [blame] | 38 | constant struct sampler_s { |
Anastasia Stulova | 4d85003 | 2016-07-11 13:46:02 +0000 | [diff] [blame] | 39 | sampler_t smp; // expected-error{{the 'sampler_t' type cannot be used to declare a structure or union field}} |
Anastasia Stulova | 1f95cc0 | 2016-03-03 13:33:19 +0000 | [diff] [blame] | 40 | } sampler_str = {0}; |
Guy Benyei | 6105419 | 2013-02-07 10:55:47 +0000 | [diff] [blame] | 41 | |
Yaxun Liu | 0bc4b2d | 2016-07-28 19:26:30 +0000 | [diff] [blame] | 42 | sampler_t bad(void); //expected-error{{declaring function return value of type 'sampler_t' is not allowed}} |
| 43 | |
Sven van Haastregt | 511f0b8 | 2017-05-08 09:29:06 +0000 | [diff] [blame] | 44 | sampler_t global_nonconst_smp = 0; // expected-error {{global sampler requires a const or constant address space qualifier}} |
| 45 | |
| 46 | const sampler_t glb_smp10 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR; |
| 47 | const constant sampler_t glb_smp11 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR; |
| 48 | |
Guy Benyei | 6105419 | 2013-02-07 10:55:47 +0000 | [diff] [blame] | 49 | void kernel ker(sampler_t argsmp) { |
Anastasia Stulova | 4d85003 | 2016-07-11 13:46:02 +0000 | [diff] [blame] | 50 | local sampler_t smp; // expected-error{{sampler type cannot be used with the __local and __global address space qualifiers}} |
Yaxun Liu | 0bc4b2d | 2016-07-28 19:26:30 +0000 | [diff] [blame] | 51 | const sampler_t const_smp5 = 1.0f; // expected-error{{initializing 'const sampler_t' with an expression of incompatible type 'float'}} |
| 52 | const sampler_t const_smp6 = 0x100000000LL; // expected-error{{sampler_t initialization requires 32-bit integer, not 'long long'}} |
| 53 | |
Egor Churaev | a8d2451 | 2017-04-05 09:02:56 +0000 | [diff] [blame] | 54 | foo(5.0f); // expected-error {{passing 'float' to parameter of incompatible type 'sampler_t'}} |
Alexey Bader | bed4009 | 2017-11-15 11:38:17 +0000 | [diff] [blame] | 55 | sampler_t sa[] = {argsmp, glb_smp}; // expected-error {{array of 'sampler_t' type is invalid in OpenCL}} |
Guy Benyei | 6105419 | 2013-02-07 10:55:47 +0000 | [diff] [blame] | 56 | } |
Xiuli Pan | 379554a | 2016-02-25 03:34:20 +0000 | [diff] [blame] | 57 | |
Anastasia Stulova | 4d85003 | 2016-07-11 13:46:02 +0000 | [diff] [blame] | 58 | void bad(sampler_t*); // expected-error{{pointer to type 'sampler_t' is invalid in OpenCL}} |
| 59 | |
| 60 | void bar() { |
Yaxun Liu | 0bc4b2d | 2016-07-28 19:26:30 +0000 | [diff] [blame] | 61 | sampler_t smp1 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR; |
| 62 | sampler_t smp2 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_NEAREST; |
Anastasia Stulova | 4d85003 | 2016-07-11 13:46:02 +0000 | [diff] [blame] | 63 | smp1=smp2; //expected-error{{invalid operands to binary expression ('sampler_t' and 'sampler_t')}} |
| 64 | smp1+1; //expected-error{{invalid operands to binary expression ('sampler_t' and 'int')}} |
| 65 | &smp1; //expected-error{{invalid argument type 'sampler_t' to unary expression}} |
| 66 | *smp2; //expected-error{{invalid argument type 'sampler_t' to unary expression}} |
Yaxun Liu | 0bc4b2d | 2016-07-28 19:26:30 +0000 | [diff] [blame] | 67 | foo(smp1+1); //expected-error{{invalid operands to binary expression ('sampler_t' and 'int')}} |
Anastasia Stulova | 4d85003 | 2016-07-11 13:46:02 +0000 | [diff] [blame] | 68 | } |
| 69 | |