Skip to content

[SYCL] Skip device diagnostics for unevaluated functions. #1093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,12 @@ Sema::DeviceDiagBuilder Sema::SYCLDiagIfDeviceCode(SourceLocation Loc,

void Sema::checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee) {
assert(Callee && "Callee may not be null.");

// Errors in unevaluated context don't need to be generated,
// so we can safely skip them.
if (isUnevaluatedContext())
return;

FunctionDecl *Caller = dyn_cast<FunctionDecl>(getCurLexicalContext());

// If the caller is known-emitted, mark the callee as known-emitted.
Expand Down
50 changes: 50 additions & 0 deletions clang/test/SemaSYCL/unevaluated-function.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// RUN: %clang_cc1 -fcxx-exceptions -fsycl-is-device -verify -fsyntax-only %s

// Check that a function used in an unevaluated context is not subject
// to delayed device diagnostics.

bool foo1() {
// Throw exception which is not allowed on device. Error is expected
// only when the function is called in evaluated context.
// expected-error@+1 1{{SYCL kernel cannot use exceptions}}
throw 10;

return false;
}

template <typename T>
T foo2(T t) {
throw t;
return t;
}

bool foo3() {
__float128 a;
return false;
}

template <typename Name, typename Func>
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
// expected-note@+1 1{{called by}}
kernelFunc();
}

int main() {
using T1 = decltype(foo1());
kernel_single_task<class fake_kernel>([]() {
using T2 = decltype(foo1());

// expected-note@+1 1{{called by}}
auto S1 = foo1();
auto S2 = sizeof(foo1());

using T3 = decltype(foo2(decltype(foo1()){}));
using T4 = decltype(foo3());

T1 f1;
T2 f2;
T3 f3;
T4 f4;
});
return 0;
}