[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:46 PDT 2026


================
@@ -429,16 +432,42 @@ __device__ void df_sema() {
   // expected-error at -1 {{initialization is not supported for __shared__ variables}}
   static __constant__ T_FA_NED c_t_fa_ned;
   // expected-error at -1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+
+  static T l_t;
+  static EC l_ec;
+  static ECD l_ecd;
+  static EC_I_EC l_ec_i_ec;
+  static CEEC l_ceec;
+  static CGTC l_cgtc;
+  static NCFS l_ncfs;
+
+  static EC l_ec_i(3);
+  // expected-error at -1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
----------------
Sirraide wrote:

Now that I look at this again, this diagnostic needs to change because this function isn’t declared `__device__`, `__constant__`, `__shared__`, or `__managed__`.

In an earlier comment I recommended using `DiagIfDeviceCode()` for unannotated statics instead, so we might as well introduce a new diagnostic for this case (something like ‘'static' local variable requires runtime initialization or destruction, which is not supported in device code’; there’s probably a shorter way to express this though)

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


More information about the cfe-commits mailing list