Skip to content

Commit 81e62b8

Browse files
committed
Share the llvm type computation between both arms of a condition
1 parent 6958deb commit 81e62b8

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::mir::interpret::{
1717
};
1818
use rustc_middle::mir::mono::MonoItem;
1919
use rustc_middle::ty::layout::LayoutOf;
20-
use rustc_middle::ty::{self, Instance, Ty};
20+
use rustc_middle::ty::{self, Instance};
2121
use rustc_middle::{bug, span_bug};
2222
use rustc_session::config::Lto;
2323
use rustc_target::abi::{
@@ -147,11 +147,10 @@ fn set_global_alignment<'ll>(cx: &CodegenCx<'ll, '_>, gv: &'ll Value, mut align:
147147
fn check_and_apply_linkage<'ll, 'tcx>(
148148
cx: &CodegenCx<'ll, 'tcx>,
149149
attrs: &CodegenFnAttrs,
150-
ty: Ty<'tcx>,
150+
llty: &'ll Type,
151151
sym: &str,
152152
def_id: DefId,
153153
) -> &'ll Value {
154-
let llty = cx.layout_of(ty).llvm_type(cx);
155154
if let Some(linkage) = attrs.import_linkage {
156155
debug!("get_static: sym={} linkage={:?}", sym, linkage);
157156

@@ -245,9 +244,9 @@ impl<'ll> CodegenCx<'ll, '_> {
245244
let fn_attrs = self.tcx.codegen_fn_attrs(def_id);
246245

247246
debug!("get_static: sym={} instance={:?} fn_attrs={:?}", sym, instance, fn_attrs);
247+
let llty = self.layout_of(ty).llvm_type(self);
248248

249249
let g = if def_id.is_local() && !self.tcx.is_foreign_item(def_id) {
250-
let llty = self.layout_of(ty).llvm_type(self);
251250
if let Some(g) = self.get_declared_value(sym) {
252251
if self.val_ty(g) != self.type_ptr() {
253252
span_bug!(self.tcx.def_span(def_id), "Conflicting types for static");
@@ -264,7 +263,7 @@ impl<'ll> CodegenCx<'ll, '_> {
264263

265264
g
266265
} else {
267-
check_and_apply_linkage(self, fn_attrs, ty, sym, def_id)
266+
check_and_apply_linkage(self, fn_attrs, llty, sym, def_id)
268267
};
269268

270269
// Thread-local statics in some other crate need to *always* be linked

0 commit comments

Comments
 (0)