Files
clang-p2996/clang/test/CodeGenSYCL/function-attrs.cpp
Harald van Dijk 6b86813945 [SYCL] Always set NoUnwind attribute for SYCL.
Like CUDA and OpenCL, the SYCL specification says that throwing and
catching exceptions in device functions is not supported, so this change
extends the logic for adding the NoUnwind attribute to SYCL.

The existing convergent.cpp test, which tests that the convergent
attribute is added to functions by default, is renamed and reused to
test that the nounwind attribute is added by default. This test now has
-fexceptions added to it, which the driver adds by default as well.

The obvious question here is why not simply change the driver to remove
-fexceptions. This change follows the direction given by the TODO
comment because removing -fexceptions would also disable the
__EXCEPTIONS macro, which should reflect whether exceptions are enabled
on the host, rather than on the device, to avoid conflicts in types
shared between host and device.

Reviewed By: bader

Differential Revision: https://reviews.llvm.org/D147097
2023-03-30 02:18:52 +01:00

27 lines
585 B
C++

// RUN: %clang_cc1 -fsycl-is-device -emit-llvm -disable-llvm-passes \
// RUN: -triple spir64 -fexceptions -emit-llvm %s -o - | FileCheck %s
int foo();
// CHECK: define dso_local spir_func void @_Z3barv() [[BAR:#[0-9]+]]
// CHECK: attributes [[BAR]] =
// CHECK-SAME: convergent
// CHECK-SAME: nounwind
void bar() {
int a = foo();
}
int foo() {
return 1;
}
template <typename Name, typename Func>
__attribute__((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
kernelFunc();
}
int main() {
kernel_single_task<class fake_kernel>([] { bar(); });
return 0;
}