blob: 50bbd745d2af3780978bf7e7ddbfc67c524e3d54 [file] [log] [blame]
Yaxun Liu39cf40f2016-05-16 17:06:34 +00001// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -Wno-unused-value -triple spir-unknown-unknown
Sven van Haastregtf0c690012020-11-17 12:07:40 +00002// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -Wno-unused-value -triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header
Joey Goulydd7f4562013-01-23 11:56:20 +00003
Anastasia Stulova5c1a2c52016-02-17 11:34:37 +00004constant float f = 1.0h; // expected-error{{half precision constant requires cl_khr_fp16}}
Joey Goulydd7f4562013-01-23 11:56:20 +00005
6half half_disabled(half *p, // expected-error{{declaring function return value of type 'half' is not allowed}}
Anastasia Stulova869d17d2019-12-27 13:38:48 +00007 half h) // expected-error{{declaring function parameter of type '__private half' is not allowed}}
Joey Goulydd7f4562013-01-23 11:56:20 +00008{
Anastasia Stulova869d17d2019-12-27 13:38:48 +00009 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}}
Yaxun Liu6aaa01b2016-09-19 14:54:41 +000012 *p = 0; // expected-error{{assigning directly to pointer to type 'half' requires cl_khr_fp16. Use vector data store builtin functions instead}}
Anastasia Stulova869d17d2019-12-27 13:38:48 +000013 p[1]; // expected-error{{loading directly from pointer to type '__private half' requires cl_khr_fp16. Use vector data load builtin functions instead}}
Yaxun Liu6aaa01b2016-09-19 14:54:41 +000014 p[1] = 0; // expected-error{{assigning directly to pointer to type 'half' requires cl_khr_fp16. Use vector data store builtin functions instead}}
Joey Goulydd7f4562013-01-23 11:56:20 +000015
16 float c = 1.0f;
17 b = (half) c; // expected-error{{casting to type 'half' is not allowed}}
Anastasia Stulova5c1a2c52016-02-17 11:34:37 +000018 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}}
John McCall6ced97a2013-02-12 01:29:43 +000020
21 half *allowed = &p[1];
22 half *allowed2 = &*p;
23 half *allowed3 = p + 1;
Joey Goulydd7f4562013-01-23 11:56:20 +000024
25 return h;
26}
27
Yaxun Liu042acb22016-09-19 17:11:22 +000028kernel void half_disabled_kernel(global half *p,
Anastasia Stulova869d17d2019-12-27 13:38:48 +000029 half h); // expected-error{{declaring function parameter of type '__private half' is not allowed; did you forget * ?}}
Yaxun Liu042acb22016-09-19 17:11:22 +000030
Joey Goulydd7f4562013-01-23 11:56:20 +000031// Exactly the same as above but with the cl_khr_fp16 extension enabled.
32#pragma OPENCL EXTENSION cl_khr_fp16 : enable
Anastasia Stulova5c1a2c52016-02-17 11:34:37 +000033constant half a = 1.0h;
Joey Goulydd7f4562013-01-23 11:56:20 +000034half half_enabled(half *p, half h)
35{
36 half a[2];
37 half b;
John McCall6ced97a2013-02-12 01:29:43 +000038 *p;
Yaxun Liu6aaa01b2016-09-19 14:54:41 +000039 *p = 0;
John McCall6ced97a2013-02-12 01:29:43 +000040 p[1];
Yaxun Liu6aaa01b2016-09-19 14:54:41 +000041 p[1] = 0;
Joey Goulydd7f4562013-01-23 11:56:20 +000042
43 float c = 1.0f;
44 b = (half) c;
Anastasia Stulova5c1a2c52016-02-17 11:34:37 +000045 c = (float) 1.0h;
46 b = 1.0h;
John McCall6ced97a2013-02-12 01:29:43 +000047
48 half *allowed = &p[1];
49 half *allowed2 = &*p;
50 half *allowed3 = p + 1;
Joey Goulydd7f4562013-01-23 11:56:20 +000051
52 return h;
53}
Yaxun Liu042acb22016-09-19 17:11:22 +000054
55kernel void half_enabled_kernel(global half *p,
56 half h);
57