# Changeset View

Changeset View

# Standalone View

Standalone View

# cfe/trunk/test/SemaOpenCL/sampler_t.cl

1 | // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only | 1 | // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only | ||
---|---|---|---|---|---|

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 | ||||

2 | 4 | | |||

3 | constant sampler_t glb_smp = 5; | 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}} | ||||

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}} | ||||

13 | | ||||

14 | constant sampler_t glb_smp4 = 0; | ||||

15 | #ifdef CHECK_SAMPLER_VALUE | ||||

16 | // expected-warning@-2{{sampler initializer has invalid Filter Mode bits}} | ||||

17 | #endif | ||||

18 | | ||||

19 | constant sampler_t glb_smp5 = 0x1f; | ||||

20 | #ifdef CHECK_SAMPLER_VALUE | ||||

21 | // expected-warning@-2{{sampler initializer has invalid Addressing Mode bits}} | ||||

22 | #endif | ||||

23 | | ||||

24 | constant sampler_t glb_smp6 = glb_smp; // expected-error{{initializer element is not a compile-time constant}} | ||||

25 | | ||||

26 | int f(void); | ||||

27 | constant sampler_t glb_smp7 = f(); // expected-error{{initializer element is not a compile-time constant}} | ||||

28 | | ||||

29 | constant sampler_t glb_smp8 = 1.0f; // expected-error{{initializing '__constant sampler_t' with an expression of incompatible type 'float'}} | ||||

30 | | ||||

31 | constant sampler_t glb_smp9 = 0x100000000LL; // expected-error{{sampler_t initialization requires 32-bit integer, not 'long long'}} | ||||

4 | 32 | | |||

5 | void foo(sampler_t); | 33 | void foo(sampler_t); | ||

6 | 34 | | |||

7 | constant struct sampler_s { | 35 | constant struct sampler_s { | ||

8 | sampler_t smp; // expected-error{{the 'sampler_t' type cannot be used to declare a structure or union field}} | 36 | sampler_t smp; // expected-error{{the 'sampler_t' type cannot be used to declare a structure or union field}} | ||

9 | } sampler_str = {0}; | 37 | } sampler_str = {0}; | ||

10 | 38 | | |||

39 | sampler_t bad(void); //expected-error{{declaring function return value of type 'sampler_t' is not allowed}} | ||||

40 | | ||||

11 | void kernel ker(sampler_t argsmp) { | 41 | void kernel ker(sampler_t argsmp) { | ||

12 | local sampler_t smp; // expected-error{{sampler type cannot be used with the __local and __global address space qualifiers}} | 42 | local sampler_t smp; // expected-error{{sampler type cannot be used with the __local and __global address space qualifiers}} | ||

13 | const sampler_t const_smp = 7; | 43 | const sampler_t const_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR; | ||

44 | const sampler_t const_smp2; | ||||

45 | const sampler_t const_smp3 = const_smp; | ||||

46 | const sampler_t const_smp4 = f(); | ||||

47 | const sampler_t const_smp5 = 1.0f; // expected-error{{initializing 'const sampler_t' with an expression of incompatible type 'float'}} | ||||

48 | const sampler_t const_smp6 = 0x100000000LL; // expected-error{{sampler_t initialization requires 32-bit integer, not 'long long'}} | ||||

49 | | ||||

14 | foo(glb_smp); | 50 | foo(glb_smp); | ||

51 | foo(glb_smp2); | ||||

52 | foo(glb_smp3); | ||||

53 | foo(glb_smp4); | ||||

54 | foo(glb_smp5); | ||||

55 | foo(glb_smp6); | ||||

56 | foo(glb_smp7); | ||||

57 | foo(glb_smp8); | ||||

58 | foo(glb_smp9); | ||||

59 | foo(smp); | ||||

60 | foo(sampler_str.smp); | ||||

15 | foo(const_smp); | 61 | foo(const_smp); | ||

62 | foo(const_smp2); | ||||

63 | foo(const_smp3); | ||||

64 | foo(const_smp4); | ||||

65 | foo(const_smp5); | ||||

66 | foo(const_smp6); | ||||

67 | foo(argsmp); | ||||

16 | foo(5); // expected-error{{sampler_t variable required - got 'int'}} | 68 | foo(5); // expected-error{{sampler_t variable required - got 'int'}} | ||

17 | sampler_t sa[] = {argsmp, const_smp}; // expected-error {{array of 'sampler_t' type is invalid in OpenCL}} | 69 | sampler_t sa[] = {argsmp, const_smp}; // expected-error {{array of 'sampler_t' type is invalid in OpenCL}} | ||

70 | foo(sa[0]); | ||||

71 | foo(bad()); | ||||

18 | } | 72 | } | ||

19 | 73 | | |||

20 | void bad(sampler_t*); // expected-error{{pointer to type 'sampler_t' is invalid in OpenCL}} | 74 | void bad(sampler_t*); // expected-error{{pointer to type 'sampler_t' is invalid in OpenCL}} | ||

21 | 75 | | |||

22 | void bar() { | 76 | void bar() { | ||

23 | sampler_t smp1 = 7; | 77 | sampler_t smp1 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR; | ||

24 | sampler_t smp2 = 2; | 78 | sampler_t smp2 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_NEAREST; | ||

25 | smp1=smp2; //expected-error{{invalid operands to binary expression ('sampler_t' and 'sampler_t')}} | 79 | smp1=smp2; //expected-error{{invalid operands to binary expression ('sampler_t' and 'sampler_t')}} | ||

26 | smp1+1; //expected-error{{invalid operands to binary expression ('sampler_t' and 'int')}} | 80 | smp1+1; //expected-error{{invalid operands to binary expression ('sampler_t' and 'int')}} | ||

27 | &smp1; //expected-error{{invalid argument type 'sampler_t' to unary expression}} | 81 | &smp1; //expected-error{{invalid argument type 'sampler_t' to unary expression}} | ||

28 | *smp2; //expected-error{{invalid argument type 'sampler_t' to unary expression}} | 82 | *smp2; //expected-error{{invalid argument type 'sampler_t' to unary expression}} | ||

83 | foo(smp1+1); //expected-error{{invalid operands to binary expression ('sampler_t' and 'int')}} | ||||

29 | } | 84 | } | ||

30 | 85 | | |||

31 | sampler_t bad(); //expected-error{{declaring function return value of type 'sampler_t' is not allowed}} | |