xref: /llvm-project/clang/test/SemaOpenCL/half.cl (revision b250cca11d5996ed01d72cb1f933867da0e8d5e0)
1// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -Wno-unused-value -triple spir-unknown-unknown
2// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -Wno-unused-value -triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -DHAVE_BUILTINS
3
4constant float f = 1.0h; // expected-error{{half precision constant requires cl_khr_fp16}}
5
6half half_disabled(half *p, // expected-error{{declaring function return value of type 'half' is not allowed}}
7                   half h)  // expected-error{{declaring function parameter of type '__private half' is not allowed}}
8{
9  half a[2]; // expected-error{{declaring variable of type '__private half[2]' is not allowed}}
10  half b;    // expected-error{{declaring variable of type '__private half' is not allowed}}
11  *p; // expected-error{{loading directly from pointer to type '__private half' requires cl_khr_fp16. Use vector data load builtin functions instead}}
12  *p = 0; // expected-error{{assigning directly to pointer to type 'half' requires cl_khr_fp16. Use vector data store builtin functions instead}}
13  p[1]; // expected-error{{loading directly from pointer to type '__private half' requires cl_khr_fp16. Use vector data load builtin functions instead}}
14  p[1] = 0; // expected-error{{assigning directly to pointer to type 'half' requires cl_khr_fp16. Use vector data store builtin functions instead}}
15
16  float c = 1.0f;
17  b = (half) c;  // expected-error{{casting to type 'half' is not allowed}}
18  c = (float) 1.0h;  // expected-error{{half precision constant requires cl_khr_fp16}}
19  b = 1.0h; // expected-error{{half precision constant requires cl_khr_fp16}}
20
21  half *allowed = &p[1];
22  half *allowed2 = &*p;
23  half *allowed3 = p + 1;
24
25#ifdef HAVE_BUILTINS
26  (void)ilogb(*p); // expected-error{{loading directly from pointer to type '__private half' requires cl_khr_fp16. Use vector data load builtin functions instead}}
27  vstore_half(42.0f, 0, p);
28#endif
29
30  return h;
31}
32
33kernel void half_disabled_kernel(global half *p,
34                                 half h);  // expected-error{{declaring function parameter of type '__private half' is not allowed; did you forget * ?}}
35
36// Exactly the same as above but with the cl_khr_fp16 extension enabled.
37#pragma OPENCL EXTENSION cl_khr_fp16 : enable
38constant half a = 1.0h;
39half half_enabled(half *p, half h)
40{
41  half a[2];
42  half b;
43  *p;
44  *p = 0;
45  p[1];
46  p[1] = 0;
47
48  float c = 1.0f;
49  b = (half) c;
50  c = (float) 1.0h;
51  b = 1.0h;
52
53  half *allowed = &p[1];
54  half *allowed2 = &*p;
55  half *allowed3 = p + 1;
56
57#ifdef HAVE_BUILTINS
58  (void)ilogb(*p);
59  vstore_half(42.0f, 0, p);
60#endif
61
62  return h;
63}
64
65kernel void half_enabled_kernel(global half *p,
66                                half h);
67
68