================
@@ -1015,6 +1016,94 @@ Sema::SemaDiagnosticBuilder 
SemaCUDA::DiagIfHostCode(SourceLocation Loc,
   return SemaDiagnosticBuilder(DiagKind, Loc, DiagID, CurFunContext, SemaRef);
 }
 
+bool SemaCUDA::isDeviceVarInit() const {
+  return CurCUDATargetCtx.Kind == CTCK_InitGlobalVar &&
+         CurCUDATargetCtx.Target == CUDAFunctionTarget::Device;
+}
+
+void SemaCUDA::checkRTTIUse(SourceLocation Loc, StringRef Op) {
+  assert(getLangOpts().CUDA && "Should only be called during CUDA 
compilation");
+  // A default argument is checked where it is used.
+  if (isa_and_present<ParmVarDecl>(
+          SemaRef.currentEvaluationContext().ManglingContextDecl))
+    return;
+
+  if (SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
+    DiagIfDeviceCode(Loc, diag::err_cuda_device_rtti) << Op << CurrentTarget();
+    return;
+  }
+
+  // Outside a function, only the initializer of a device variable is device
+  // code. A default member initializer is checked where it is used.
+  if (isDeviceVarInit())
+    Diag(Loc, diag::err_cuda_device_rtti_var_init) << Op;
+}
+
+namespace {
+/// Finds a use of RTTI, as diagnosed by checkRTTIUse, in a default argument or
+/// default member initializer.
+struct RTTIUseFinder : DynamicRecursiveASTVisitor {
----------------
steffenlarsen wrote:

Good call. Migrated to that instead.

https://github.com/llvm/llvm-project/pull/228469
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to