Skip to content

Commit 24d053c

Browse files
authored
[SYCL] Allow recursive function calls on sycl device with a warning (#2162)
Currently recursive function calls are not allowed on device. A hard error is generated in the FE when recursive calls are detected on device. To permit enabling this functionality in the BE, this diagnostic has been moved to the -Wsycl-strict group. When -Wsycl-strict is specified, this is still an error, but can be turned into a warning with -Wno-error=sycl-strict. TO DO: Once full support is available in the BE, this new diagnostic, the existing enumerated diagnostic for recursive calls and the mechanism for detecting the recursion can be removed. Signed-off-by: Premanand M Rao <[email protected]>
1 parent 280b93c commit 24d053c

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10979,6 +10979,9 @@ def warn_sycl_implicit_decl
1097910979
"declaration for a kernel type name; your program may not "
1098010980
"be portable">,
1098110981
InGroup<SyclStrict>, DefaultIgnore;
10982+
def warn_sycl_restrict_recursion
10983+
: Warning<"SYCL kernel cannot call a recursive function">,
10984+
InGroup<SyclStrict>, DefaultError;
1098210985
def err_ivdep_duplicate_arg : Error<
1098310986
"duplicate argument to 'ivdep'. attribute requires one or both of a safelen "
1098410987
"and array">;

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,7 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
354354
// all functions used by kernel have already been parsed and have
355355
// definitions.
356356
if (RecursiveSet.count(Callee) && !ConstexprDepth) {
357-
SemaRef.Diag(e->getExprLoc(), diag::err_sycl_restrict)
358-
<< Sema::KernelCallRecursiveFunction;
357+
SemaRef.Diag(e->getExprLoc(), diag::warn_sycl_restrict_recursion);
359358
SemaRef.Diag(Callee->getSourceRange().getBegin(),
360359
diag::note_sycl_recursive_function_declared_here)
361360
<< Sema::KernelCallRecursiveFunction;

clang/test/SemaSYCL/restrict-recursion3.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fcxx-exceptions -Wno-return-type -Wno-sycl-strict -verify -fsyntax-only -std=c++17 %s
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fcxx-exceptions -Wno-return-type -Wno-error=sycl-strict -verify -fsyntax-only -std=c++17 %s
22

33
// This recursive function is not called from sycl kernel,
44
// so it should not be diagnosed.
@@ -16,6 +16,7 @@ using myFuncDef = int(int, int);
1616

1717
typedef __typeof__(sizeof(int)) size_t;
1818

19+
// expected-warning@+1 {{SYCL 1.2.1 specification does not allow 'sycl_device' attribute applied to a function with a raw pointer return type}}
1920
SYCL_EXTERNAL
2021
void *operator new(size_t);
2122

@@ -34,7 +35,7 @@ template <typename name, typename Func>
3435
__attribute__((sycl_kernel)) void kernel_single_task2(Func kernelFunc) {
3536
// expected-note@+1 {{called by 'kernel_single_task2}}
3637
kernelFunc();
37-
// expected-error@+1 2{{SYCL kernel cannot call a recursive function}}
38+
// expected-warning@+1 2{{SYCL kernel cannot call a recursive function}}
3839
kernel_single_task2<name, Func>(kernelFunc);
3940
}
4041

clang/test/SemaSYCL/restrict-recursion4.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fcxx-exceptions -Wno-return-type -Wno-sycl-strict -verify -fsyntax-only -std=c++17 %s
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fcxx-exceptions -Wno-return-type -Wno-error=sycl-strict -verify -fsyntax-only -std=c++17 %s
22

33
// This recursive function is not called from sycl kernel,
44
// so it should not be diagnosed.
@@ -10,21 +10,22 @@ int fib(int n) {
1010

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

1717
using myFuncDef = int(int, int);
1818

1919
typedef __typeof__(sizeof(int)) size_t;
2020

21+
// expected-warning@+1 {{SYCL 1.2.1 specification does not allow 'sycl_device' attribute applied to a function with a raw pointer return type}}
2122
SYCL_EXTERNAL
2223
void *operator new(size_t);
2324

2425
void usage2(myFuncDef functionPtr) {
2526
// expected-error@+1 {{SYCL kernel cannot allocate storage}}
2627
int *ip = new int;
27-
// expected-error@+1 {{SYCL kernel cannot call a recursive function}}
28+
// expected-warning@+1 {{SYCL kernel cannot call a recursive function}}
2829
kernel2();
2930
}
3031

0 commit comments

Comments
 (0)