MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / codegen_static

Method codegen_static

crates/rustc_codegen_spirv/src/codegen_cx/declare.rs:333–352  ·  view source on GitHub ↗
(&self, def_id: DefId, _is_mutable: bool)

Source from the content-addressed store, hash-verified

331 }
332
333 fn codegen_static(&self, def_id: DefId, _is_mutable: bool) {
334 let g = self.get_static(def_id);
335
336 let alloc = match self.tcx.eval_static_initializer(def_id) {
337 Ok(alloc) => alloc,
338 // Error has already been reported
339 Err(_) => return,
340 };
341 let value_ty = match self.lookup_type(g.ty) {
342 SpirvType::Pointer { pointee } => pointee,
343 other => self.tcx.sess.fatal(format!(
344 "global had non-pointer type {}",
345 other.debug(g.ty, self)
346 )),
347 };
348 let v = self.create_const_alloc(alloc, value_ty);
349 assert_ty_eq!(self, value_ty, v.ty);
350 self.builder
351 .set_global_initializer(g.def_cx(self), v.def_cx(self));
352 }
353
354 /// Mark the given global value as "used", to prevent the compiler and linker from potentially
355 /// removing a static variable that may otherwise appear unused.

Callers

nothing calls this directly

Calls 6

lookup_typeMethod · 0.80
fatalMethod · 0.80
create_const_allocMethod · 0.80
def_cxMethod · 0.80
get_staticMethod · 0.45

Tested by

no test coverage detected