about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/declare.rs
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2025-02-24 11:14:21 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2025-02-24 15:11:29 +0000
commit396baa750e51a0e40fb0b803bfa6399a35e604a2 (patch)
treeb26c35943e4ccc9afaa3cefd36f4f4a39a74e71e /compiler/rustc_codegen_llvm/src/declare.rs
parent840e31b29f93a5e0569d05c8879468877a9991d4 (diff)
downloadrust-396baa750e51a0e40fb0b803bfa6399a35e604a2.tar.gz
rust-396baa750e51a0e40fb0b803bfa6399a35e604a2.zip
Make allocator shim creation mostly use safe code
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/declare.rs')
-rw-r--r--compiler/rustc_codegen_llvm/src/declare.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/compiler/rustc_codegen_llvm/src/declare.rs b/compiler/rustc_codegen_llvm/src/declare.rs
index e79662ebc64..2419ec1f888 100644
--- a/compiler/rustc_codegen_llvm/src/declare.rs
+++ b/compiler/rustc_codegen_llvm/src/declare.rs
@@ -11,6 +11,8 @@
 //! * Use define_* family of methods when you might be defining the Value.
 //! * When in doubt, define.
 
+use std::borrow::Borrow;
+
 use itertools::Itertools;
 use rustc_codegen_ssa::traits::TypeMembershipCodegenMethods;
 use rustc_data_structures::fx::FxIndexSet;
@@ -22,7 +24,7 @@ use tracing::debug;
 
 use crate::abi::FnAbiLlvmExt;
 use crate::common::AsCCharPtr;
-use crate::context::{CodegenCx, SimpleCx};
+use crate::context::{CodegenCx, GenericCx, SCx, SimpleCx};
 use crate::llvm::AttributePlace::Function;
 use crate::llvm::Visibility;
 use crate::type_::Type;
@@ -81,16 +83,25 @@ pub(crate) fn declare_raw_fn<'ll, 'tcx>(
     llfn
 }
 
-impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
+impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
     /// Declare a global value.
     ///
     /// If there’s a value with the same name already declared, the function will
     /// return its Value instead.
     pub(crate) fn declare_global(&self, name: &str, ty: &'ll Type) -> &'ll Value {
         debug!("declare_global(name={:?})", name);
-        unsafe { llvm::LLVMRustGetOrInsertGlobal(self.llmod, name.as_c_char_ptr(), name.len(), ty) }
+        unsafe {
+            llvm::LLVMRustGetOrInsertGlobal(
+                (**self).borrow().llmod,
+                name.as_c_char_ptr(),
+                name.len(),
+                ty,
+            )
+        }
     }
+}
 
+impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
     /// Declare a C ABI function.
     ///
     /// Only use this for foreign function ABIs and glue. For Rust functions use