]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaOpenCL/sampler_t.cl
Vendor import of clang trunk r302418:
[FreeBSD/FreeBSD.git] / test / SemaOpenCL / sampler_t.cl
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
4
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}} 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}}
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'}}
33
34 void foo(sampler_t); // expected-note{{passing argument to parameter here}}
35
36 constant struct sampler_s {
37   sampler_t smp; // expected-error{{the 'sampler_t' type cannot be used to declare a structure or union field}}
38 } sampler_str = {0};
39
40 sampler_t bad(void); //expected-error{{declaring function return value of type 'sampler_t' is not allowed}}
41
42 sampler_t global_nonconst_smp = 0; // expected-error {{global sampler requires a const or constant address space qualifier}}
43
44 const sampler_t glb_smp10 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
45 const constant sampler_t glb_smp11 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
46
47 void kernel ker(sampler_t argsmp) {
48   local sampler_t smp; // expected-error{{sampler type cannot be used with the __local and __global address space qualifiers}}
49   const sampler_t const_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
50   const sampler_t const_smp2;
51   const sampler_t const_smp3 = const_smp;
52   const sampler_t const_smp4 = f();
53   const sampler_t const_smp5 = 1.0f; // expected-error{{initializing 'const sampler_t' with an expression of incompatible type 'float'}}
54   const sampler_t const_smp6 = 0x100000000LL; // expected-error{{sampler_t initialization requires 32-bit integer, not 'long long'}}
55
56   foo(glb_smp);
57   foo(glb_smp2);
58   foo(glb_smp3);
59   foo(glb_smp4);
60   foo(glb_smp5);
61   foo(glb_smp6);
62   foo(glb_smp7);
63   foo(glb_smp8);
64   foo(glb_smp9);
65   foo(smp);
66   foo(sampler_str.smp);
67   foo(const_smp);
68   foo(const_smp2);
69   foo(const_smp3);
70   foo(const_smp4);
71   foo(const_smp5);
72   foo(const_smp6);
73   foo(argsmp);
74   foo(5);
75   foo(5.0f); // expected-error {{passing 'float' to parameter of incompatible type 'sampler_t'}}
76   sampler_t sa[] = {argsmp, const_smp}; // expected-error {{array of 'sampler_t' type is invalid in OpenCL}}
77   foo(sa[0]);
78   foo(bad());
79 }
80
81 void bad(sampler_t*); // expected-error{{pointer to type 'sampler_t' is invalid in OpenCL}}
82
83 void bar() {
84   sampler_t smp1 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
85   sampler_t smp2 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_NEAREST;
86   smp1=smp2; //expected-error{{invalid operands to binary expression ('sampler_t' and 'sampler_t')}}
87   smp1+1; //expected-error{{invalid operands to binary expression ('sampler_t' and 'int')}}
88   &smp1; //expected-error{{invalid argument type 'sampler_t' to unary expression}}
89   *smp2; //expected-error{{invalid argument type 'sampler_t' to unary expression}}
90   foo(smp1+1); //expected-error{{invalid operands to binary expression ('sampler_t' and 'int')}}
91 }
92