================
@@ -764,8 +764,26 @@ void SemaCUDA::checkAllowedInitializer(VarDecl *VD) {
   if (VD->isInvalidDecl() || !VD->hasInit() || !VD->hasGlobalStorage() ||
       IsDependentVar(VD))
     return;
+
+  // A function-scope static is a device variable when it is emitted on the
+  // device side, and has the same initialization restrictions.
+  CUDAVariableTarget VT = IdentifyTarget(VD);
+  const FunctionDecl *FD = VD->getDeclContext()->getEnclosingFunction();
+
+  // CVT_Both means the enclosing function is __host__ __device__, so the
+  // variable is emitted on both sides and only the device-side copy is
+  // restricted. Lambdas are implicitly HD and their statics are host 
variables.
+  const bool IsDeviceCopyOfHDStatic = VT == CVT_Both &&
+                                      getLangOpts().CUDAIsDevice && FD &&
+                                      !isImplicitHostDeviceFunction(FD);
+
+  // constexpr implies constant initialization and constant destruction.
+  bool IsDeviceLocalStatic = !IsSharedVar && VD->isStaticLocal() &&
+                             !VD->isConstexpr() &&
+                             (VT == CVT_Device || IsDeviceCopyOfHDStatic);
----------------
Sirraide wrote:

Also, can you add tests for statics in implicit `__host__ __device__` functions?

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

Reply via email to