hvdijk created this revision. hvdijk added a reviewer: bader. hvdijk added a project: clang. Herald added subscribers: Naghasan, Anastasia, ebevhan, yaxunl. Herald added a project: All. hvdijk requested review of this revision. Herald added a reviewer: jdoerfert. Herald added subscribers: cfe-commits, jplehr, sstefan1.
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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D147097 Files: clang/lib/CodeGen/CGCall.cpp clang/test/CodeGenSYCL/convergent.cpp clang/test/CodeGenSYCL/function-attrs.cpp Index: clang/test/CodeGenSYCL/function-attrs.cpp =================================================================== --- clang/test/CodeGenSYCL/function-attrs.cpp +++ clang/test/CodeGenSYCL/function-attrs.cpp @@ -1,9 +1,10 @@ // RUN: %clang_cc1 -fsycl-is-device -emit-llvm -disable-llvm-passes \ -// RUN: -triple spir64 -emit-llvm %s -o - | FileCheck %s +// RUN: -triple spir64 -fexceptions -emit-llvm %s -o - | FileCheck %s -// CHECK-DAG: Function Attrs: -// CHECK-DAG-SAME: convergent -// CHECK-DAG-NEXT: define void @_Z3foov +// CHECK: Function Attrs: +// CHECK-SAME: convergent +// CHECK-SAME: nounwind +// CHECK-NEXT: define dso_local spir_func void @_Z3foov void foo() { int a = 1; } Index: clang/lib/CodeGen/CGCall.cpp =================================================================== --- clang/lib/CodeGen/CGCall.cpp +++ clang/lib/CodeGen/CGCall.cpp @@ -1971,10 +1971,9 @@ } // TODO: NoUnwind attribute should be added for other GPU modes HIP, - // SYCL, OpenMP offload. AFAIK, none of them support exceptions in device - // code. + // OpenMP offload. AFAIK, neither of them support exceptions in device code. if ((getLangOpts().CUDA && getLangOpts().CUDAIsDevice) || - getLangOpts().OpenCL) { + getLangOpts().OpenCL || getLangOpts().SYCLIsDevice) { FuncAttrs.addAttribute(llvm::Attribute::NoUnwind); }
Index: clang/test/CodeGenSYCL/function-attrs.cpp =================================================================== --- clang/test/CodeGenSYCL/function-attrs.cpp +++ clang/test/CodeGenSYCL/function-attrs.cpp @@ -1,9 +1,10 @@ // RUN: %clang_cc1 -fsycl-is-device -emit-llvm -disable-llvm-passes \ -// RUN: -triple spir64 -emit-llvm %s -o - | FileCheck %s +// RUN: -triple spir64 -fexceptions -emit-llvm %s -o - | FileCheck %s -// CHECK-DAG: Function Attrs: -// CHECK-DAG-SAME: convergent -// CHECK-DAG-NEXT: define void @_Z3foov +// CHECK: Function Attrs: +// CHECK-SAME: convergent +// CHECK-SAME: nounwind +// CHECK-NEXT: define dso_local spir_func void @_Z3foov void foo() { int a = 1; } Index: clang/lib/CodeGen/CGCall.cpp =================================================================== --- clang/lib/CodeGen/CGCall.cpp +++ clang/lib/CodeGen/CGCall.cpp @@ -1971,10 +1971,9 @@ } // TODO: NoUnwind attribute should be added for other GPU modes HIP, - // SYCL, OpenMP offload. AFAIK, none of them support exceptions in device - // code. + // OpenMP offload. AFAIK, neither of them support exceptions in device code. if ((getLangOpts().CUDA && getLangOpts().CUDAIsDevice) || - getLangOpts().OpenCL) { + getLangOpts().OpenCL || getLangOpts().SYCLIsDevice) { FuncAttrs.addAttribute(llvm::Attribute::NoUnwind); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits