[clang] [CUDA] Treat function-scope statics in device code as device variables (PR #222985)
Ambrose Leeb via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 2 10:50:47 PDT 2026
================
@@ -491,6 +520,50 @@ __device__ void *ptr2 = ptr1;
// expected-error at -1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
__device__ [[gnu::constructor(101)]] void ctor() {}
-// expected-error at -1 {{CUDA does not support global constructors for __device__ functions}}
+// dev-error at -1 {{CUDA does not support global constructors for __device__ functions}}
__device__ [[gnu::destructor(101)]] void dtor() {}
-// expected-error at -1 {{CUDA does not support global destructors for __device__ functions}}
+// dev-error at -1 {{CUDA does not support global destructors for __device__ functions}}
+
+__global__ void gf_local_static() {
+ static HD_NEC nec;
+ // expected-error at -1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+ static HD_EC ec;
+ static int i = 42;
+}
+
+__host__ __device__ void hd_local_static() {
+ static HD_NEC nec;
+ // dev-error at -1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+ static int i = 42;
+}
+
+inline __host__ __device__ void hd_local_static_host_only() {
+ static HD_NEC nec;
+ // dev-error at -1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+}
+
+void call_hd_local_static_host_only() { hd_local_static_host_only(); }
+
+__host__ void h_local_static() { static HD_NEC nec; }
+void plain_local_static() { static HD_NEC nec; }
+
+#if __cplusplus >= 202002L
----------------
Sirraide wrote:
So we generally prefer not to disable/enable test code with preprocessor directives like this; instead of this, change the C++11 RUN lines to `-verify=expected,cxx11` and then add `cxx11-error` etc. comments for whatever diagnostics you get here in C++11 mode.
https://github.com/llvm/llvm-project/pull/222985
More information about the cfe-commits
mailing list