(&self, def_id: DefId)
| 296 | } |
| 297 | |
| 298 | pub(crate) fn get_static(&self, def_id: DefId) -> &'ll Value { |
| 299 | let instance = Instance::mono(self.tcx, def_id); |
| 300 | if let Some(&g) = self.instances.borrow().get(&instance) { |
| 301 | return g; |
| 302 | } |
| 303 | |
| 304 | let defined_in_current_codegen_unit = self |
| 305 | .codegen_unit |
| 306 | .items() |
| 307 | .contains_key(&MonoItem::Static(def_id)); |
| 308 | assert!( |
| 309 | !defined_in_current_codegen_unit, |
| 310 | "consts::get_static() should always hit the cache for \ |
| 311 | statics defined in the same CGU, but did not for `{:?}`", |
| 312 | def_id |
| 313 | ); |
| 314 | |
| 315 | let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all()); |
| 316 | let sym = self.tcx.symbol_name(instance).name; |
| 317 | let fn_attrs = self.tcx.codegen_fn_attrs(def_id); |
| 318 | |
| 319 | let g = if def_id.is_local() && !self.tcx.is_foreign_item(def_id) { |
| 320 | let llty = self.layout_of(ty).llvm_type(self); |
| 321 | if let Some(g) = self.get_declared_value(sym) { |
| 322 | if self.val_ty(g) != self.type_ptr_to(llty) { |
| 323 | span_bug!(self.tcx.def_span(def_id), "Conflicting types for static"); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | let addrspace = self.static_addrspace(instance); |
| 328 | let g = self.declare_global(sym, llty, addrspace); |
| 329 | |
| 330 | if !self.tcx.is_reachable_non_generic(def_id) { |
| 331 | unsafe { |
| 332 | llvm::LLVMRustSetVisibility(g, llvm::Visibility::Hidden); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | g |
| 337 | } else { |
| 338 | check_and_apply_linkage(self, fn_attrs, ty, sym, def_id, instance) |
| 339 | }; |
| 340 | |
| 341 | if fn_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) { |
| 342 | self.unsupported("thread locals"); |
| 343 | } |
| 344 | |
| 345 | self.instances.borrow_mut().insert(instance, g); |
| 346 | g |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | impl<'ll, 'tcx> StaticMethods for CodegenCx<'ll, 'tcx> { |
no test coverage detected