Skip to content

Commit d822eda

Browse files
authored
[SYCL] Report compile time error for recursion in a SYCL kernel (#3390)
According to SYCL 2020 spec(https://www.khronos.org/registry/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:language.restrictions.kernels), recursion is not allowed in SYCL kernel, we had better report compiling error for this illegal behavior. Moving runtime crash to compiling error is more friendly to users too. Signed-off-by: gejin <[email protected]>
1 parent a504f72 commit d822eda

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-7
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11299,9 +11299,6 @@ def warn_sycl_implicit_decl
1129911299
"declaration for a kernel type name; your program may not "
1130011300
"be portable">,
1130111301
InGroup<SyclStrict>, ShowInSystemHeader, DefaultIgnore;
11302-
def warn_sycl_restrict_recursion
11303-
: Warning<"SYCL kernel cannot call a recursive function">,
11304-
InGroup<SyclStrict>, DefaultError;
1130511302
def err_ivdep_duplicate_arg : Error<
1130611303
"duplicate argument to 'ivdep'; attribute requires one or both of a safelen "
1130711304
"and array">;

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
387387
// all functions used by kernel have already been parsed and have
388388
// definitions.
389389
if (RecursiveSet.count(Callee) && !ConstexprDepth) {
390-
SemaRef.Diag(e->getExprLoc(), diag::warn_sycl_restrict_recursion);
390+
SemaRef.Diag(e->getExprLoc(), diag::err_sycl_restrict)
391+
<< Sema::KernelCallRecursiveFunction;
391392
SemaRef.Diag(Callee->getSourceRange().getBegin(),
392393
diag::note_sycl_recursive_function_declared_here)
393394
<< Sema::KernelCallRecursiveFunction;

clang/test/SemaSYCL/restrict-recursion3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ template <typename name, typename Func>
3434
__attribute__((sycl_kernel)) void kernel_single_task2(const Func &kernelFunc) {
3535
// expected-note@+1 {{called by 'kernel_single_task2}}
3636
kernelFunc();
37-
// expected-warning@+1 2{{SYCL kernel cannot call a recursive function}}
37+
// expected-error@+1 2{{SYCL kernel cannot call a recursive function}}
3838
kernel_single_task2<name, Func>(kernelFunc);
3939
}
4040

clang/test/SemaSYCL/restrict-recursion4.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int fib(int n) {
1010

1111
// expected-note@+1 2{{function implemented using recursion declared here}}
1212
void kernel2(void) {
13-
// expected-warning@+1 {{SYCL kernel cannot call a recursive function}}
13+
// expected-error@+1 {{SYCL kernel cannot call a recursive function}}
1414
kernel2();
1515
}
1616

@@ -24,7 +24,7 @@ void *operator new(size_t);
2424
void usage2(myFuncDef functionPtr) {
2525
// expected-error@+1 {{SYCL kernel cannot allocate storage}}
2626
int *ip = new int;
27-
// expected-warning@+1 {{SYCL kernel cannot call a recursive function}}
27+
// expected-error@+1 {{SYCL kernel cannot call a recursive function}}
2828
kernel2();
2929
}
3030

0 commit comments

Comments
 (0)