Skip to content

Commit 226c51c

Browse files
authored
[clang][Sema][OpenMP] Fix GPU exception target check (llvm#169056)
Looks like I missed this when I added `Triple::isGPU()`. Signed-off-by: Nick Sarnie <[email protected]>
1 parent 36d7e91 commit 226c51c

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
852852
bool IsThrownVarInScope) {
853853
const llvm::Triple &T = Context.getTargetInfo().getTriple();
854854
const bool IsOpenMPGPUTarget =
855-
getLangOpts().OpenMPIsTargetDevice && (T.isNVPTX() || T.isAMDGCN());
855+
getLangOpts().OpenMPIsTargetDevice && T.isGPU();
856856

857857
DiagnoseExceptionUse(OpLoc, /* IsTry= */ false);
858858

clang/lib/Sema/SemaStmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4357,7 +4357,7 @@ StmtResult Sema::ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
43574357
ArrayRef<Stmt *> Handlers) {
43584358
const llvm::Triple &T = Context.getTargetInfo().getTriple();
43594359
const bool IsOpenMPGPUTarget =
4360-
getLangOpts().OpenMPIsTargetDevice && (T.isNVPTX() || T.isAMDGCN());
4360+
getLangOpts().OpenMPIsTargetDevice && T.isGPU();
43614361

43624362
DiagnoseExceptionUse(TryLoc, /* IsTry= */ true);
43634363

@@ -4464,7 +4464,7 @@ StmtResult Sema::ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
44644464
void Sema::DiagnoseExceptionUse(SourceLocation Loc, bool IsTry) {
44654465
const llvm::Triple &T = Context.getTargetInfo().getTriple();
44664466
const bool IsOpenMPGPUTarget =
4467-
getLangOpts().OpenMPIsTargetDevice && (T.isNVPTX() || T.isAMDGCN());
4467+
getLangOpts().OpenMPIsTargetDevice && T.isGPU();
44684468

44694469
// Don't report an error if 'try' is used in system headers or in an OpenMP
44704470
// target region compiled for a GPU architecture.

clang/test/OpenMP/nvptx_target_exceptions_messages.cpp renamed to clang/test/OpenMP/target_exceptions_messages.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@
66
// RUN: -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - \
77
// RUN: -fexceptions -fcxx-exceptions -ferror-limit 100
88

9+
// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown \
10+
// RUN: -verify=host -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc \
11+
// RUN: %s -o %t-ppc-host-amd.bc -fexceptions -fcxx-exceptions
12+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple amdgcn-amd-amdhsa \
13+
// RUN: -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s \
14+
// RUN: -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host-amd.bc -o - \
15+
// RUN: -fexceptions -fcxx-exceptions -ferror-limit 100
16+
17+
// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown \
18+
// RUN: -verify=host -fopenmp-targets=spirv64-intel -emit-llvm-bc \
19+
// RUN: %s -o %t-ppc-host-spirv.bc -fexceptions -fcxx-exceptions
20+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple spirv64-intel \
21+
// RUN: -fopenmp-targets=spirv64-intel -emit-llvm %s \
22+
// RUN: -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host-spirv.bc -o - \
23+
// RUN: -fexceptions -fcxx-exceptions -ferror-limit 100
24+
925
#ifndef HEADER
1026
#define HEADER
1127

@@ -34,7 +50,7 @@ T FA() {
3450
#pragma omp declare target
3551
struct S {
3652
int a;
37-
S(int a) : a(a) { throw 1; } // expected-warning {{target 'nvptx64-unknown-unknown' does not support exception handling; 'throw' is assumed to be never reached}}
53+
S(int a) : a(a) { throw 1; } // expected-warning-re {{target '{{.*}}' does not support exception handling; 'throw' is assumed to be never reached}}
3854
};
3955

4056
int foo() { return 0; }
@@ -57,7 +73,7 @@ int maini1() {
5773
static long aaa = 23;
5874
a = foo() + bar() + b + c + d + aa + aaa + FA<int>(); // expected-note{{called by 'maini1'}}
5975
if (!a)
60-
throw "Error"; // expected-warning {{target 'nvptx64-unknown-unknown' does not support exception handling; 'throw' is assumed to be never reached}}
76+
throw "Error"; // expected-warning-re {{target '{{.*}}' does not support exception handling; 'throw' is assumed to be never reached}}
6177
}
6278
} catch(...) {
6379
}
@@ -67,14 +83,14 @@ int maini1() {
6783
int baz3() { return 2 + baz2(); }
6884
int baz2() {
6985
#pragma omp target
70-
try { // expected-warning {{target 'nvptx64-unknown-unknown' does not support exception handling; 'catch' block is ignored}}
86+
try { // expected-warning-re {{target '{{.*}}' does not support exception handling; 'catch' block is ignored}}
7187
++c;
7288
} catch (...) {
7389
}
7490
return 2 + baz3();
7591
}
7692

77-
int baz1() { throw 1; } // expected-warning {{target 'nvptx64-unknown-unknown' does not support exception handling; 'throw' is assumed to be never reached}}
93+
int baz1() { throw 1; } // expected-warning-re {{target '{{.*}}' does not support exception handling; 'throw' is assumed to be never reached}}
7894

7995
int foobar1();
8096
int foobar2();
@@ -85,7 +101,7 @@ int (*B)() = &foobar2;
85101
#pragma omp end declare target
86102

87103
int foobar1() { throw 1; }
88-
int foobar2() { throw 1; } // expected-warning {{target 'nvptx64-unknown-unknown' does not support exception handling; 'throw' is assumed to be never reached}}
104+
int foobar2() { throw 1; } // expected-warning-re {{target '{{.*}}' does not support exception handling; 'throw' is assumed to be never reached}}
89105

90106

91107
int foobar3();
@@ -95,7 +111,7 @@ int (*C)() = &foobar3; // expected-warning {{declaration is not declared in any
95111
int (*D)() = C; // expected-note {{used here}}
96112
// host-note@-1 {{used here}}
97113
#pragma omp end declare target
98-
int foobar3() { throw 1; } // expected-warning {{target 'nvptx64-unknown-unknown' does not support exception handling; 'throw' is assumed to be never reached}}
114+
int foobar3() { throw 1; } // expected-warning-re {{target '{{.*}}' does not support exception handling; 'throw' is assumed to be never reached}}
99115

100116
// Check no infinite recursion in deferred diagnostic emitter.
101117
long E = (long)&E;

0 commit comments

Comments
 (0)