[clang] [Clang] [CUDA] Clean up exception handling diagnostics in device code (PR #230658)

Ambrose Leeb via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 20 11:48:14 PDT 2026


================
@@ -858,24 +858,8 @@ Sema::ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *Ex) {
 
 ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
                                bool IsThrownVarInScope) {
-  const llvm::Triple &T = Context.getTargetInfo().getTriple();
-  const bool IsOpenMPGPUTarget =
-      getLangOpts().OpenMPIsTargetDevice && T.isGPU();
-
   DiagnoseExceptionUse(OpLoc, /* IsTry= */ false);
 
-  // In OpenMP target regions, we replace 'throw' with a trap on GPU targets.
-  if (IsOpenMPGPUTarget)
-    targetDiag(OpLoc, diag::warn_throw_not_valid_on_target) << T.str();
-
-  // Exceptions aren't allowed in CUDA device code.
-  if (getLangOpts().CUDA)
-    CUDA().DiagIfDeviceCode(OpLoc, diag::err_cuda_device_exceptions)
-        << "throw" << CUDA().CurrentTarget();
-
-  if (getCurScope() && getCurScope()->isOpenMPSimdDirectiveScope())
----------------
Sirraide wrote:

Hmm, iiuc, you mean because of this in `DiagnoseExceptionUse()`:
```c++
if (IsOpenMPGPUTarget) {
  targetDiag(Loc, diag::warn_exceptions_not_valid_on_target)
      << T.str() << IsTry;
  return;
}
```
I missed that this is just a warning; I think we should remove the early `return` here; if we do that then, I believe we have the same behaviour as before because the checks as to what diagnostics we should emit here are still emitted in the same order, except that they’ve all been moved into `DiagnoseExceptionUse()`.

Or do you have concerns w/ something else here?

https://github.com/llvm/llvm-project/pull/230658


More information about the cfe-commits mailing list