1- // RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify %s
1+ // RUN: %clang_cc1 -fsycl-is-device -std=c++17 - fsyntax-only -verify -DCPP17 %s
22// RUN: %clang_cc1 -fsycl-is-device -std=c++20 -fsyntax-only -verify -DCPP20 %s
3- // Semantic tests for sycl_external attribute
43
5- [[clang::sycl_external]] // expected-error {{'sycl_external' can only be applied to functions with external linkage}}
4+ // Semantic tests for the sycl_external attribute.
5+
6+ // expected-error@+1{{'sycl_external' can only be applied to functions with external linkage}}
7+ [[clang::sycl_external]]
68static void func1 () {}
79
10+ // expected-error@+2{{'sycl_external' can only be applied to functions with external linkage}}
811namespace {
9- [[clang::sycl_external]] // expected-error {{'sycl_external' can only be applied to functions with external linkage}}
12+ [[clang::sycl_external]]
1013 void func2 () {}
1114
1215 struct UnnX {};
1316}
1417
15- [[clang::sycl_external]] // expected-error {{'sycl_external' can only be applied to functions with external linkage}}
16- void func4 (UnnX) {}
18+ // expected-error@+2{{'sycl_external' can only be applied to functions with external linkage}}
19+ namespace { struct S4 {}; }
20+ [[clang::sycl_external]] void func4 (S4) {}
21+
22+ // FIXME: This case is currently being diagnosed as an error because clang implements
23+ // default inheritance of attribute and explicit instantiation declaration names the
24+ // symbol that causes the instantiated specialization to have internal linkage.
25+ // expected-error@+3{{'sycl_external' can only be applied to functions with external linkage}}
26+ namespace { struct S6 {}; }
27+ template <typename >
28+ [[clang::sycl_external]] void func6 () {}
29+ template void func6<S6>();
30+ // expected-note@-1{{in instantiation of function template specialization 'func6<(anonymous namespace)::S6>' requested here}}
31+
32+ // expected-error@+3 2{{'sycl_external' can only be applied to functions with external linkage}}
33+ namespace { struct S7 {}; }
34+ template <typename >
35+ [[clang::sycl_external]] void func7 ();
36+ template <> void func7<S7>() {}
37+ // expected-note@-1{{in instantiation of function template specialization 'func7<(anonymous namespace)::S7>' requested here}}
38+
39+ namespace { struct S8 {}; }
40+ template <typename >
41+ void func8 ();
42+ template <> [[clang::sycl_external]] void func8<S8>() {}
43+ // expected-error@-1{{'clang::sycl_external' attribute does not appear on the first declaration}}
44+ // expected-note@-2{{previous declaration is here}}
1745
1846// The first declaration of a SYCL external function is required to have this attribute.
19- int foo (); // expected-note {{previous declaration is here}}
20-
21- [[clang::sycl_external]] int foo (); // expected-error {{'clang::sycl_external' attribute does not appear on the first declaration}}
47+ // expected-note@+1{{previous declaration is here}}
48+ int foo ();
49+ // expected-error@+1{{'clang::sycl_external' attribute does not appear on the first declaration}}
50+ [[clang::sycl_external]] int foo ();
2251
2352// Subsequent declrations of a SYCL external function may optionally specify this attribute.
2453[[clang::sycl_external]] int boo ();
25-
2654[[clang::sycl_external]] int boo (); // OK
27-
2855int boo (); // OK
2956
3057class C {
3158 [[clang::sycl_external]] void member ();
3259};
3360
34- [[clang::sycl_external]] int main () // expected-error {{'sycl_external' cannot be applied to the 'main' function}}
61+ // expected-error@+1{{'sycl_external' cannot be applied to the 'main' function}}
62+ [[clang::sycl_external]] int main ()
3563{
3664 return 0 ;
3765}
3866
67+ // expected-error@+2{{'sycl_external' cannot be applied to an explicitly deleted function}}
3968class D {
40- [[clang::sycl_external]] void del () = delete; // expected-error {{'sycl_external' cannot be applied to an explicitly deleted function}}
69+ [[clang::sycl_external]] void del () = delete;
4170};
42-
4371struct NonCopyable {
4472 ~NonCopyable () = delete ;
4573 [[clang::sycl_external]] NonCopyable(const NonCopyable&) = default ;
@@ -49,7 +77,8 @@ class A {
4977 [[clang::sycl_external]]
5078 A () {}
5179
52- [[clang::sycl_external]] void func3 () {}
80+ [[clang::sycl_external]] void mf () {}
81+ [[clang::sycl_external]] static void smf ();
5382};
5483
5584class B {
@@ -59,12 +88,18 @@ class B {
5988 [[clang::sycl_external]] virtual void bar () = 0;
6089};
6190
62- [[clang::sycl_external]] int *func0 () { return nullptr ; }
63-
64- [[clang::sycl_external]] void func2 (int *) {}
65-
6691[[clang::sycl_external]] constexpr int square (int x);
6792
68- #ifdef CPP20
93+ // Devices that do not support the generic address space shall not specify
94+ // a raw pointer or reference type as the return type or as a parameter type.
95+ [[clang::sycl_external]] int *fun0 ();
96+ [[clang::sycl_external]] int &fun1 ();
97+ [[clang::sycl_external]] int &&fun2();
98+ [[clang::sycl_external]] void fun3 (int *);
99+ [[clang::sycl_external]] void fun4 (int &);
100+ [[clang::sycl_external]] void fun5 (int &&);
101+
102+ #if CPP20
69103[[clang::sycl_external]] consteval int func ();
70104#endif
105+
0 commit comments