Skip to content

Commit e34f2a6

Browse files
committed
Add test cases
1 parent 931fd76 commit e34f2a6

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,7 @@ may optionally be present on subsequent declarations.
501501
When compiling for a SYCL device target that does not support the generic
502502
address space, the function shall not specify a raw pointer or reference type
503503
as the return type or as a parameter type.
504-
See section 5.9, "Address-space deduction", of the SYCL 2020 specification.
505-
504+
See section 5.10, "SYCL offline linking", of the SYCL 2020 specification.
506505
The following examples demonstrate the use of this attribute:
507506

508507
.. code-block:: c++

clang/lib/Sema/SemaDecl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16301,6 +16301,13 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
1630116301
}
1630216302
}
1630316303

16304+
if (FD && !FD->isInvalidDecl() && FD->hasAttr<SYCLExternalAttr>()) {
16305+
SYCLExternalAttr *SEAttr = FD->getAttr<SYCLExternalAttr>();
16306+
if (FD->isDeletedAsWritten())
16307+
Diag(SEAttr->getLocation(),
16308+
diag::err_sycl_attribute_invalid_deleted_function);
16309+
}
16310+
1630416311
{
1630516312
// Do not call PopExpressionEvaluationContext() if it is a lambda because
1630616313
// one is already popped when finishing the lambda in BuildLambdaExpr().
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -std=c++17 -verify %s
2+
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -std=c++20 -verify %s
3+
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -std=c++23 -verify %s
4+
5+
// expected-error@+1{{'clang::sycl_external' attribute only applies to functions}}
6+
[[clang::sycl_external]] int bad1;
7+
8+
9+
// expected-error@+2{{'clang::sycl_external' attribute only applies to functions}}
10+
struct s {
11+
[[clang::sycl_external]] int bad2;
12+
};
13+
14+
// expected-error@+1{{'clang::sycl_external' attribute only applies to functions}}
15+
namespace [[clang::sycl_external]] bad3 {}
16+
17+
// expected-error@+1{{'clang::sycl_external' attribute only applies to functions}}
18+
struct [[clang::sycl_external]] bad4;
19+
20+
// expected-error@+1{{'clang::sycl_external' attribute only applies to functions}}
21+
enum [[clang::sycl_external]] bad5 {};
22+
23+
// expected-error@+1{{'clang::sycl_external' attribute only applies to functions}}
24+
int bad6(void (fp [[clang::sycl_external]])());
25+
26+
// expected-error@+1{{'clang::sycl_external' attribute only applies to functions}}
27+
[[clang::sycl_external]];
28+
29+
#if __cplusplus >= 202002L
30+
// expected-error@+2{{'clang::sycl_external' attribute only applies to functions}}
31+
template<typename>
32+
concept bad8 [[clang::sycl_external]] = true;
33+
#endif

clang/test/SemaSYCL/sycl-external-attr-grammar.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify %s
22

3-
// expected-error@+1{{'clang::sycl_external' attribute takes no arguments}}
4-
[[clang::sycl_external(3)]] void bar() {}
53

6-
// FIXME: this case should be diagnosed too
4+
// FIXME: this case should be diagnosed.
5+
// This attribute takes no arguments.
76
[[clang::sycl_external()]] void bad1();
87

98
// expected-error@+1{{expected expression}}

clang/test/SemaSYCL/sycl-external-attr.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,12 @@ class C {
6666

6767
// expected-error@+2{{'sycl_external' cannot be applied to an explicitly deleted function}}
6868
class D {
69-
[[clang::sycl_external]] void del() = delete;
69+
[[clang::sycl_external]] void mdel() = delete;
7070
};
71+
72+
// expected-error@+1{{'sycl_external' cannot be applied to an explicitly deleted function}}
73+
[[clang::sycl_external]] void del() = delete;
74+
7175
struct NonCopyable {
7276
~NonCopyable() = delete;
7377
[[clang::sycl_external]] NonCopyable(const NonCopyable&) = default;
@@ -98,8 +102,11 @@ class B {
98102
[[clang::sycl_external]] void fun3(int *);
99103
[[clang::sycl_external]] void fun4(int &);
100104
[[clang::sycl_external]] void fun5(int &&);
105+
template<typename T>
106+
[[clang::sycl_external]] void fun6(T) {}
107+
template void fun6(int *);
108+
template<> [[clang::sycl_external]] void fun6<long*>(long *) {}
101109

102110
#if CPP20
103111
[[clang::sycl_external]] consteval int func();
104112
#endif
105-

0 commit comments

Comments
 (0)