summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaCUDA.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Sema/SemaCUDA.cpp')
-rw-r--r--clang/lib/Sema/SemaCUDA.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index 6f94e54a0cc..b1939a17157 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -515,3 +515,27 @@ bool Sema::CheckCUDACall(SourceLocation Loc, FunctionDecl *Callee) {
}
return true;
}
+
+bool Sema::CheckCUDAExceptionExpr(SourceLocation Loc, StringRef ExprTy) {
+ assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
+ FunctionDecl *CurFn = dyn_cast<FunctionDecl>(CurContext);
+ if (!CurFn)
+ return true;
+ CUDAFunctionTarget Target = IdentifyCUDATarget(CurFn);
+
+ // Raise an error immediately if this is a __global__ or __device__ function.
+ // If it's a __host__ __device__ function, enqueue a deferred error which will
+ // be emitted if the function is codegen'ed for device.
+ if (Target == CFT_Global || Target == CFT_Device) {
+ Diag(Loc, diag::err_cuda_device_exceptions) << ExprTy << Target << CurFn;
+ return false;
+ }
+ if (Target == CFT_HostDevice && getLangOpts().CUDAIsDevice) {
+ PartialDiagnostic ErrPD{PartialDiagnostic::NullDiagnostic()};
+ ErrPD.Reset(diag::err_cuda_device_exceptions);
+ ErrPD << ExprTy << Target << CurFn;
+ CurFn->addDeferredDiag({Loc, std::move(ErrPD)});
+ return false;
+ }
+ return true;
+}
OpenPOWER on IntegriCloud