Skip to content

Commit 6719a8e

Browse files
committed
Move codegen_static function body to an inherent method in preparation of splitting it.
This should make the diff easier to read, as this commit does no functional changes at all.
1 parent d4b30aa commit 6719a8e

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

+27-23
Original file line numberDiff line numberDiff line change
@@ -343,30 +343,8 @@ impl<'ll> CodegenCx<'ll, '_> {
343343
self.instances.borrow_mut().insert(Instance::mono(self.tcx, def_id), g);
344344
g
345345
}
346-
}
347-
348-
impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
349-
fn static_addr_of(&self, cv: &'ll Value, align: Align, kind: Option<&str>) -> &'ll Value {
350-
if let Some(&gv) = self.const_globals.borrow().get(&cv) {
351-
unsafe {
352-
// Upgrade the alignment in cases where the same constant is used with different
353-
// alignment requirements
354-
let llalign = align.bytes() as u32;
355-
if llalign > llvm::LLVMGetAlignment(gv) {
356-
llvm::LLVMSetAlignment(gv, llalign);
357-
}
358-
}
359-
return gv;
360-
}
361-
let gv = self.static_addr_of_mut(cv, align, kind);
362-
unsafe {
363-
llvm::LLVMSetGlobalConstant(gv, True);
364-
}
365-
self.const_globals.borrow_mut().insert(cv, gv);
366-
gv
367-
}
368346

369-
fn codegen_static(&self, def_id: DefId, is_mutable: bool) {
347+
fn codegen_static_item(&self, def_id: DefId, is_mutable: bool) {
370348
unsafe {
371349
let attrs = self.tcx.codegen_fn_attrs(def_id);
372350

@@ -550,6 +528,32 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
550528
}
551529
}
552530
}
531+
}
532+
533+
impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
534+
fn static_addr_of(&self, cv: &'ll Value, align: Align, kind: Option<&str>) -> &'ll Value {
535+
if let Some(&gv) = self.const_globals.borrow().get(&cv) {
536+
unsafe {
537+
// Upgrade the alignment in cases where the same constant is used with different
538+
// alignment requirements
539+
let llalign = align.bytes() as u32;
540+
if llalign > llvm::LLVMGetAlignment(gv) {
541+
llvm::LLVMSetAlignment(gv, llalign);
542+
}
543+
}
544+
return gv;
545+
}
546+
let gv = self.static_addr_of_mut(cv, align, kind);
547+
unsafe {
548+
llvm::LLVMSetGlobalConstant(gv, True);
549+
}
550+
self.const_globals.borrow_mut().insert(cv, gv);
551+
gv
552+
}
553+
554+
fn codegen_static(&self, def_id: DefId, is_mutable: bool) {
555+
self.codegen_static_item(def_id, is_mutable)
556+
}
553557

554558
/// Add a global value to a list to be stored in the `llvm.used` variable, an array of ptr.
555559
fn add_used_global(&self, global: &'ll Value) {

0 commit comments

Comments
 (0)