Skip to content

Commit 68d3acf

Browse files
committed
[OpenMP][SPIRV] Disable exceptions for OpenMP SPIR-V
Signed-off-by: Nick Sarnie <[email protected]>
1 parent 9a56e55 commit 68d3acf

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

clang/lib/CodeGen/CGException.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E,
450450
// Therefore, we emit a trap which will abort the program, and
451451
// prompt a warning indicating that a trap will be emitted.
452452
const llvm::Triple &T = Target.getTriple();
453-
if (CGM.getLangOpts().OpenMPIsTargetDevice && (T.isNVPTX() || T.isAMDGCN())) {
453+
if (CGM.getLangOpts().OpenMPIsTargetDevice && T.isGPU()) {
454454
EmitTrapCall(llvm::Intrinsic::trap);
455455
return;
456456
}
@@ -627,7 +627,7 @@ void CodeGenFunction::EmitCXXTryStmt(const CXXTryStmt &S) {
627627
// If we encounter a try statement on in an OpenMP target region offloaded to
628628
// a GPU, we treat it as a basic block.
629629
const bool IsTargetDevice =
630-
(CGM.getLangOpts().OpenMPIsTargetDevice && (T.isNVPTX() || T.isAMDGCN()));
630+
(CGM.getLangOpts().OpenMPIsTargetDevice && T.isGPU());
631631
if (!IsTargetDevice)
632632
EnterCXXTryStmt(S);
633633
EmitStmt(S.getTryBlock());

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4303,8 +4303,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
43034303

43044304
// Set the flag to prevent the implementation from emitting device exception
43054305
// handling code for those requiring so.
4306-
if ((Opts.OpenMPIsTargetDevice && (T.isNVPTX() || T.isAMDGCN())) ||
4307-
Opts.OpenCLCPlusPlus) {
4306+
if ((Opts.OpenMPIsTargetDevice && T.isGPU()) || Opts.OpenCLCPlusPlus) {
43084307

43094308
Opts.Exceptions = 0;
43104309
Opts.CXXExceptions = 0;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -fexceptions -fcxx-exceptions -Wno-openmp-target-exception -fopenmp -x c++ -triple x86_64-unknown-linux -fopenmp-targets=spirv64-intel -emit-llvm-bc %s -o %t-host.bc
2+
// RUN: %clang_cc1 -fexceptions -fcxx-exceptions -Wno-openmp-target-exception -fopenmp -x c++ -triple spirv64-intel -fopenmp-targets=spirv64-intel -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-host.bc -o - | \
3+
// RUN: FileCheck -implicit-check-not='{{invoke|throw|cxa}}' %s
4+
void foo() {
5+
// CHECK: call addrspace(9) void @llvm.trap()
6+
// CHECK-NEXT: call spir_func addrspace(9) void @__kmpc_target_deinit()
7+
#pragma omp target
8+
throw "bad";
9+
}

0 commit comments

Comments
 (0)