xref: /llvm-project/clang/test/SemaSYCL/int128.cpp (revision 15f3cd6bfc670ba6106184a903eb04be059e5977)
1 // RUN: %clang_cc1 -triple spir64 -aux-triple x86_64-unknown-linux-gnu \
2 // RUN:    -fsycl-is-device -verify -fsyntax-only %s
3 
4 typedef __uint128_t BIGTY;
5 
6 template <class T>
7 class Z {
8 public:
9   // expected-note@+1 {{'field' defined here}}
10   T field;
11   // expected-note@+1 2{{'field1' defined here}}
12   __int128 field1;
13   using BIGTYPE = __int128;
14   // expected-note@+1 {{'bigfield' defined here}}
15   BIGTYPE bigfield;
16 };
17 
host_ok(void)18 void host_ok(void) {
19   __int128 A;
20   int B = sizeof(__int128);
21   Z<__int128> C;
22   C.field1 = A;
23 }
24 
usage()25 void usage() {
26   // expected-note@+1 3{{'A' defined here}}
27   __int128 A;
28   Z<__int128> C;
29   // expected-error@+3 2{{expression requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
30   // expected-error@+2 {{'A' requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
31   // expected-error@+1 {{'field1' requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
32   C.field1 = A;
33   // expected-error@+2 {{expression requires 128 bit size 'BIGTYPE' (aka '__int128') type support, but target 'spir64' does not support it}}
34   // expected-error@+1 {{'bigfield' requires 128 bit size 'BIGTYPE' (aka '__int128') type support, but target 'spir64' does not support it}}
35   C.bigfield += 1.0;
36 
37   // expected-error@+1 {{'A' requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
38   auto foo1 = [=]() {
39     __int128 AA;
40     // expected-note@+2 {{'BB' defined here}}
41     // expected-error@+1 {{'A' requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
42     auto BB = A;
43     // expected-error@+2 {{expression requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
44     // expected-error@+1 {{'BB' requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
45     BB += 1;
46   };
47 
48   // expected-note@+1 {{called by 'usage'}}
49   foo1();
50 }
51 
52 template <typename t>
foo2()53 void foo2(){};
54 
55 // expected-note@+3 {{'P' defined here}}
56 // expected-error@+2 {{'P' requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
57 // expected-note@+1 2{{'foo' defined here}}
foo(__int128 P)58 __int128 foo(__int128 P) { return P; }
59 
foobar()60 void foobar() {
61   // expected-note@+1 {{'operator __int128' defined here}}
62   struct X { operator  __int128() const; } x;
63   bool a = false;
64   // expected-error@+2 2{{expression requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
65   // expected-error@+1 {{'operator __int128' requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
66   a = x == __int128(0);
67 }
68 
69 template <typename Name, typename Func>
kernel(Func kernelFunc)70 __attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
71   // expected-note@+1 6{{called by 'kernel}}
72   kernelFunc();
73 }
74 
main()75 int main() {
76   // expected-note@+1 {{'CapturedToDevice' defined here}}
77   __int128 CapturedToDevice = 1;
78   host_ok();
79   kernel<class variables>([=]() {
80     decltype(CapturedToDevice) D;
81     // expected-error@+1 {{'CapturedToDevice' requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
82     auto C = CapturedToDevice;
83     Z<__int128> S;
84     // expected-error@+2 {{expression requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
85     // expected-error@+1 {{'field1' requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
86     S.field1 += 1;
87     // expected-error@+2 {{expression requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
88     // expected-error@+1 {{'field' requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
89     S.field = 1;
90   });
91 
92   kernel<class functions>([=]() {
93     // expected-note@+1 2{{called by 'operator()'}}
94     usage();
95     // expected-note@+1 {{'BBBB' defined here}}
96     BIGTY BBBB;
97     // expected-error@+3 {{'BBBB' requires 128 bit size 'BIGTY' (aka 'unsigned __int128') type support, but target 'spir64' does not support it}}
98     // expected-error@+2 2{{'foo' requires 128 bit size '__int128' type support, but target 'spir64' does not support it}}
99     // expected-note@+1 1{{called by 'operator()'}}
100     auto A = foo(BBBB);
101     // expected-note@+1 {{called by 'operator()'}}
102     foobar();
103   });
104 
105   kernel<class ok>([=]() {
106     Z<__int128> S;
107     foo2<__int128>();
108     auto A = sizeof(CapturedToDevice);
109   });
110 
111   return 0;
112 }
113 
114 // no error expected
zoo(BIGTY h)115 BIGTY zoo(BIGTY h) {
116   h = 1;
117   return h;
118 }
119 
120 namespace PR12964 {
121   struct X { operator  __int128() const; } x;
122   bool a = x == __int128(0);
123 }
124 
125