Skip to content

Commit

Permalink
[SYCL] Defer diagnostics about usage of SEH (intel#11619)
Browse files Browse the repository at this point in the history
Rather issue an immediate diagnostic about the use of SEH, emit them
deferred similar to what is done for C++ exceptions.
  • Loading branch information
premanandrao authored Oct 23, 2023
1 parent 3847c7c commit 9be40b5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
8 changes: 6 additions & 2 deletions clang/lib/Sema/SemaStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4626,8 +4626,12 @@ StmtResult Sema::ActOnSEHTryBlock(bool IsCXXTry, SourceLocation TryLoc,
Diag(TryLoc, diag::err_seh_try_outside_functions);

// Reject __try on unsupported targets.
if (!Context.getTargetInfo().isSEHTrySupported())
Diag(TryLoc, diag::err_seh_try_unsupported);
if (!Context.getTargetInfo().isSEHTrySupported()) {
if (getLangOpts().SYCLIsDevice)
SYCLDiagIfDeviceCode(TryLoc, diag::err_seh_try_unsupported);
else
Diag(TryLoc, diag::err_seh_try_unsupported);
}

return SEHTryStmt::Create(Context, IsCXXTry, TryLoc, TryBlock, Handler);
}
Expand Down
34 changes: 34 additions & 0 deletions clang/test/SemaSYCL/sycl-seh.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -triple spir64 -aux-triple x86_64 -fms-compatibility %s -verify
//
// This test checks that we issue a diagnostic about the use of SEH
// features only when they are used on the device.
//
#include "sycl.hpp"

void seh_okay_on_host() {
__try {
} __except(0) {
}
}

void seh_not_okay_on_device() {
// expected-error@+2 {{SEH '__try' is not supported on this target}}
// expected-error@+1 {{SYCL kernel cannot use exceptions}}
__try {
} __except(0) {
}
}

void foo() {
sycl::queue q;

seh_okay_on_host();
q.submit([&](sycl::handler &h) {
// expected-note@#KernelSingleTaskKernelFuncCall {{called by 'kernel_single_task<kernel_wrapper}}
h.single_task<class kernel_wrapper>(
[=]() {
// expected-note@+1 {{called by 'operator()'}}
seh_not_okay_on_device();
});
});
}

0 comments on commit 9be40b5

Please sign in to comment.