(&self, def_id: DefId, is_mutable: bool)
| 369 | } |
| 370 | |
| 371 | fn codegen_static(&self, def_id: DefId, is_mutable: bool) { |
| 372 | unsafe { |
| 373 | let attrs = self.tcx.codegen_fn_attrs(def_id); |
| 374 | |
| 375 | let (v, _) = match codegen_static_initializer(self, def_id) { |
| 376 | Ok(v) => v, |
| 377 | // Error has already been reported |
| 378 | Err(_) => return, |
| 379 | }; |
| 380 | |
| 381 | let g = self.get_static(def_id); |
| 382 | |
| 383 | let mut val_llty = self.val_ty(v); |
| 384 | let v = if val_llty == self.type_i1() { |
| 385 | val_llty = self.type_i8(); |
| 386 | llvm::LLVMConstZExt(v, val_llty) |
| 387 | } else { |
| 388 | v |
| 389 | }; |
| 390 | |
| 391 | let instance = Instance::mono(self.tcx, def_id); |
| 392 | let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all()); |
| 393 | let llty = self.layout_of(ty).llvm_type(self); |
| 394 | let g = if val_llty == llty { |
| 395 | g |
| 396 | } else { |
| 397 | trace!( |
| 398 | "Making new RAUW global: from ty `{:?}` to `{:?}`, initializer: `{:?}`", |
| 399 | llty, |
| 400 | val_llty, |
| 401 | v |
| 402 | ); |
| 403 | // If we created the global with the wrong type, |
| 404 | // correct the type. |
| 405 | let name = llvm::get_value_name(g).to_vec(); |
| 406 | |
| 407 | llvm::set_value_name(g, b""); |
| 408 | |
| 409 | let linkage = llvm::LLVMRustGetLinkage(g); |
| 410 | let visibility = llvm::LLVMRustGetVisibility(g); |
| 411 | |
| 412 | let addrspace = self.static_addrspace(instance); |
| 413 | let new_g = llvm::LLVMRustGetOrInsertGlobal( |
| 414 | self.llmod, |
| 415 | name.as_ptr().cast(), |
| 416 | name.len(), |
| 417 | val_llty, |
| 418 | addrspace.0, |
| 419 | ); |
| 420 | |
| 421 | llvm::LLVMRustSetLinkage(new_g, linkage); |
| 422 | llvm::LLVMRustSetVisibility(new_g, visibility); |
| 423 | |
| 424 | // To avoid breaking any invariants, we leave around the old |
| 425 | // global for the moment; we'll replace all references to it |
| 426 | // with the new global later. (See base::codegen_backend.) |
| 427 | self.statics_to_rauw.borrow_mut().push((g, new_g)); |
| 428 | new_g |
nothing calls this directly
no test coverage detected