Avoid a bunch of unnecessary unsafe blocks in cg_llvm

This commit is contained in:
Oli Scherer
2025-07-09 09:12:42 +00:00
parent ad635e5d06
commit d3d51b4fdb
8 changed files with 52 additions and 63 deletions

View File

@@ -19,11 +19,10 @@ use tracing::{debug, instrument, trace};
use crate::common::{AsCCharPtr, CodegenCx};
use crate::errors::SymbolAlreadyDefined;
use crate::llvm::{self, True};
use crate::type_::Type;
use crate::type_of::LayoutLlvmExt;
use crate::value::Value;
use crate::{base, debuginfo};
use crate::{base, debuginfo, llvm};
pub(crate) fn const_alloc_to_llvm<'ll>(
cx: &CodegenCx<'ll, '_>,
@@ -247,7 +246,7 @@ impl<'ll> CodegenCx<'ll, '_> {
};
llvm::set_initializer(gv, cv);
set_global_alignment(self, gv, align);
llvm::SetUnnamedAddress(gv, llvm::UnnamedAddr::Global);
llvm::set_unnamed_address(gv, llvm::UnnamedAddr::Global);
gv
}
@@ -272,9 +271,8 @@ impl<'ll> CodegenCx<'ll, '_> {
return gv;
}
let gv = self.static_addr_of_mut(cv, align, kind);
unsafe {
llvm::LLVMSetGlobalConstant(gv, True);
}
llvm::set_global_constant(gv, true);
self.const_globals.borrow_mut().insert(cv, gv);
gv
}
@@ -465,7 +463,7 @@ impl<'ll> CodegenCx<'ll, '_> {
// Forward the allocation's mutability (picked by the const interner) to LLVM.
if alloc.mutability.is_not() {
llvm::LLVMSetGlobalConstant(g, llvm::True);
llvm::set_global_constant(g, true);
}
debuginfo::build_global_var_di_node(self, def_id, g);