22// RUN: %clang_cc1 -fcxx-exceptions -triple spir64 -fsycl-is-device -fno-sycl-allow-func-ptr -Wno-return-type -verify -fsyntax-only -std=c++17 %s
33// RUN: %clang_cc1 -fcxx-exceptions -triple spir64 -fsycl-is-device -DALLOW_FP=1 -fsycl-allow-func-ptr -Wno-return-type -verify -fsyntax-only -std=c++17 %s
44
5-
65namespace std {
7- class type_info ;
8- typedef __typeof__ (sizeof (int )) size_t;
9- }
6+ class type_info ;
7+ typedef __typeof__ (sizeof (int )) size_t;
8+ } // namespace std
109namespace Check_User_Operators {
11- class Fraction
12- {
13- // expected-error@+2 {{SYCL kernel cannot call a recursive function }}
14- // expected-note@+1 {{function implemented using recursion declared here} }
15- int gcd ( int a, int b) { return b == 0 ? a : gcd (b, a % b); }
16- int n, d;
10+ class Fraction {
11+ // expected-error@+2 {{SYCL kernel cannot call a recursive function}}
12+ // expected-note@+1 {{function implemented using recursion declared here }}
13+ int gcd ( int a, int b) { return b == 0 ? a : gcd (b, a % b); }
14+ int n, d;
15+
1716public:
18- Fraction (int n, int d = 1 ) : n(n/ gcd(n, d)), d(d/ gcd(n, d)) { }
19- int num () const { return n; }
20- int den () const { return d; }
17+ Fraction (int n, int d = 1 ) : n(n / gcd(n, d)), d(d / gcd(n, d)) {}
18+ int num () const { return n; }
19+ int den () const { return d; }
2120};
22- bool operator ==(const Fraction& lhs, const Fraction& rhs)
23- {
24- new int ; // expected-error {{SYCL kernel cannot allocate storage}}
25- return lhs. num () == rhs. num () && lhs. den () == rhs. den ();
26- }}
21+ bool operator ==(const Fraction & lhs, const Fraction & rhs) {
22+ new int ; // expected-error {{SYCL kernel cannot allocate storage}}
23+ return lhs. num () == rhs. num () && lhs. den () == rhs. den ();
24+ }
25+ } // namespace Check_User_Operators
2726
2827namespace Check_VLA_Restriction {
2928void no_restriction (int p) {
30- int index[p+ 2 ];
29+ int index[p + 2 ];
3130}
3231void restriction (int p) {
3332 // expected-error@+1 {{variable length arrays are not supported for the current target}}
34- int index[p+2 ];
35- }
33+ int index[p + 2 ];
3634}
35+ } // namespace Check_VLA_Restriction
3736
38- void * operator new (std::size_t size, void * ptr) throw () { return ptr; };
37+ void * operator new (std::size_t size, void * ptr) throw () { return ptr; };
3938namespace Check_RTTI_Restriction {
4039struct A {
4140 virtual ~A (){};
@@ -50,35 +49,38 @@ struct OverloadedNewDelete {
5049 void *operator new (std::size_t size) throw () {
5150 // expected-error@+1 {{SYCL kernel cannot allocate storage}}
5251 float *pt = new float ;
53- return 0 ;}
52+ return 0 ;
53+ }
5454 // This overload does not allocate: no diagnostic.
55- void *operator new [](std::size_t size) throw () {return 0 ;}
55+ void *operator new [](std::size_t size) throw () { return 0 ; }
5656 void operator delete (void *){};
5757 void operator delete[] (void *){};
5858};
5959
6060bool isa_B (A *a) {
6161 Check_User_Operators::Fraction f1 (3 , 8 ), f2 (1 , 2 ), f3 (10 , 2 );
62- if (f1 == f2) return false ;
62+ if (f1 == f2)
63+ return false ;
6364
6465 Check_VLA_Restriction::restriction (7 );
6566 // expected-error@+1 {{SYCL kernel cannot allocate storage}}
6667 int *ip = new int ;
67- int i; int *p3 = new (&i) int ; // no error on placement new
68+ int i;
69+ int *p3 = new (&i) int ; // no error on placement new
6870 // expected-note@+1 {{called by 'isa_B'}}
69- OverloadedNewDelete *x = new ( struct OverloadedNewDelete );
70- auto y = new struct OverloadedNewDelete [5 ];
71+ OverloadedNewDelete *x = new ( struct OverloadedNewDelete );
72+ auto y = new struct OverloadedNewDelete [5 ];
7173 // expected-error@+1 {{SYCL kernel cannot use rtti}}
7274 (void )typeid (int );
7375 // expected-error@+1 {{SYCL kernel cannot use rtti}}
7476 return dynamic_cast <B *>(a) != 0 ;
7577}
7678
77- template <typename N, typename L>
79+ template <typename N, typename L>
7880__attribute__ ((sycl_kernel)) void kernel1 (L l) {
7981 l ();
8082}
81- }
83+ } // namespace Check_RTTI_Restriction
8284
8385typedef struct Base {
8486 virtual void f () const {}
@@ -87,22 +89,19 @@ typedef struct Base {
8789typedef struct A {
8890 static int stat_member;
8991 const static int const_stat_member;
90- constexpr static int constexpr_stat_member= 0 ;
92+ constexpr static int constexpr_stat_member = 0 ;
9193
92- int fm (void )
93- {
94+ int fm (void ) {
9495 // expected-error@+1 {{SYCL kernel cannot use a non-const static data variable}}
9596 return stat_member;
9697 }
9798} a_type;
9899
99-
100100b_type b;
101101
102- using myFuncDef = int (int ,int );
102+ using myFuncDef = int (int , int );
103103
104- void eh_ok (void )
105- {
104+ void eh_ok (void ) {
106105 __float128 A;
107106 try {
108107 ;
@@ -112,8 +111,7 @@ void eh_ok(void)
112111 throw 20 ;
113112}
114113
115- void eh_not_ok (void )
116- {
114+ void eh_not_ok (void ) {
117115 // expected-error@+1 {{SYCL kernel cannot use exceptions}}
118116 try {
119117 ;
@@ -134,7 +132,7 @@ void usage(myFuncDef functionPtr) {
134132 // expected-error@+2 {{SYCL kernel cannot call through a function pointer}}
135133#endif
136134 if ((*functionPtr)(1 , 2 ))
137- // expected-error@+2 {{SYCL kernel cannot use a global variable}}
135+ // expected-error@+2 {{SYCL kernel cannot use a non-const global variable}}
138136 // expected-error@+1 {{SYCL kernel cannot call a virtual function}}
139137 b.f ();
140138 Check_RTTI_Restriction::kernel1<class kernel_name >([]() {
@@ -146,58 +144,64 @@ void usage(myFuncDef functionPtr) {
146144}
147145
148146namespace ns {
149- int glob;
147+ int glob;
150148}
151149extern " C++" {
152- int another_global = 5 ;
153- namespace AnotherNS {
154- int moar_globals = 5 ;
155- }
150+ int another_global = 5 ;
151+ namespace AnotherNS {
152+ int moar_globals = 5 ;
153+ }
156154}
157155
158156int addInt (int n, int m) {
159- return n+ m;
157+ return n + m;
160158}
161159
162- int use2 ( a_type ab, a_type *abp ) {
160+ int use2 ( a_type ab, a_type *abp) {
163161
164- if (ab.constexpr_stat_member ) return 2 ;
165- if (ab.const_stat_member ) return 1 ;
162+ if (ab.constexpr_stat_member )
163+ return 2 ;
164+ if (ab.const_stat_member )
165+ return 1 ;
166166 // expected-error@+1 {{SYCL kernel cannot use a non-const static data variable}}
167- if (ab.stat_member ) return 0 ;
167+ if (ab.stat_member )
168+ return 0 ;
168169 // expected-error@+1 {{SYCL kernel cannot use a non-const static data variable}}
169- if (abp->stat_member ) return 0 ;
170- if (ab.fm ()) return 0 ;
171- // expected-error@+1 {{SYCL kernel cannot use a global variable}}
172- return another_global ;
173- // expected-error@+1 {{SYCL kernel cannot use a global variable}}
170+ if (abp->stat_member )
171+ return 0 ;
172+ // expected-note@+1 {{called by 'use2'}}
173+ if (ab.fm ())
174+ return 0 ;
175+ // expected-error@+1 {{SYCL kernel cannot use a non-const global variable}}
176+ return another_global;
177+ // expected-error@+1 {{SYCL kernel cannot use a non-const global variable}}
174178 return ns::glob +
175- // expected-error@+1 {{SYCL kernel cannot use a global variable}}
176- AnotherNS::moar_globals;
179+ // expected-error@+1 {{SYCL kernel cannot use a non-const global variable}}
180+ AnotherNS::moar_globals;
177181 // expected-note@+1 {{called by 'use2'}}
178182 eh_not_ok ();
179- Check_RTTI_Restriction:: A *a;
183+ Check_RTTI_Restriction::A *a;
180184 // expected-note@+1 2{{called by 'use2'}}
181- Check_RTTI_Restriction:: isa_B (a);
185+ Check_RTTI_Restriction::isa_B (a);
182186 // expected-note@+1 {{called by 'use2'}}
183187 usage (&addInt);
184188 Check_User_Operators::Fraction f1 (3 , 8 ), f2 (1 , 2 ), f3 (10 , 2 );
185189 // expected-note@+1 {{called by 'use2'}}
186- if (f1 == f2) return false ;
190+ if (f1 == f2)
191+ return false ;
187192}
188193
189194template <typename name, typename Func>
190195__attribute__ ((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
191196 kernelFunc ();
192197 a_type ab;
193198 a_type *p;
194- // expected-note@+1 5 {{called by 'kernel_single_task}}
199+ // expected-note@+1 7 {{called by 'kernel_single_task}}
195200 use2 (ab, p);
196201}
197202
198203int main () {
199204 a_type ab;
200- kernel_single_task<class fake_kernel >([]() { usage ( &addInt ); });
205+ kernel_single_task<class fake_kernel >([]() { usage (&addInt); });
201206 return 0 ;
202207}
203-
0 commit comments