Skip to content

Commit

Permalink
Remove env_alloca hack
Browse files Browse the repository at this point in the history
This is no longer necessary for LLVM >= 6.
  • Loading branch information
nikic committed Dec 11, 2018
1 parent 706e67b commit 6c2d704
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 30 deletions.
5 changes: 0 additions & 5 deletions src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use attributes;
use llvm;
use llvm_util;
use rustc::dep_graph::DepGraphSafe;
use rustc::hir;
use debuginfo;
Expand Down Expand Up @@ -447,10 +446,6 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
attributes::apply_target_cpu_attr(self, llfn)
}

fn closure_env_needs_indirect_debuginfo(&self) -> bool {
llvm_util::get_major_version() < 6
}

fn create_used_variable(&self) {
let name = const_cstr!("llvm.used");
let section = const_cstr!("llvm.metadata");
Expand Down
26 changes: 2 additions & 24 deletions src/librustc_codegen_ssa/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,35 +610,13 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
};
let upvar_tys = upvar_substs.upvar_tys(def_id, tcx);

// Store the pointer to closure data in an alloca for debuginfo
// because that's what the llvm.dbg.declare intrinsic expects.

// FIXME(eddyb) this shouldn't be necessary but SROA seems to
// mishandle DW_OP_plus not preceded by DW_OP_deref, i.e., it
// doesn't actually strip the offset when splitting the closure
// environment into its components so it ends up out of bounds.
// (cuviper) It seems to be fine without the alloca on LLVM 6 and later.
let env_alloca = !env_ref && bx.closure_env_needs_indirect_debuginfo();
let env_ptr = if env_alloca {
let scratch = PlaceRef::alloca(bx,
bx.layout_of(tcx.mk_mut_ptr(arg.layout.ty)),
"__debuginfo_env_ptr");
bx.store(place.llval, scratch.llval, scratch.align);
scratch.llval
} else {
place.llval
};

for (i, (decl, ty)) in mir.upvar_decls.iter().zip(upvar_tys).enumerate() {
let byte_offset_of_var_in_env = closure_layout.fields.offset(i).bytes();

let ops = bx.debuginfo_upvar_decls_ops_sequence(byte_offset_of_var_in_env);

// The environment and the capture can each be indirect.

// FIXME(eddyb) see above why we sometimes have to keep
// a pointer in an alloca for debuginfo atm.
let mut ops = if env_ref || env_alloca { &ops[..] } else { &ops[1..] };
let mut ops = if env_ref { &ops[..] } else { &ops[1..] };

let ty = if let (true, &ty::Ref(_, ty, _)) = (decl.by_ref, &ty.sty) {
ty
Expand All @@ -648,7 +626,7 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
};

let variable_access = VariableAccess::IndirectVariable {
alloca: env_ptr,
alloca: place.llval,
address_operations: &ops
};
bx.declare_local(
Expand Down
1 change: 0 additions & 1 deletion src/librustc_codegen_ssa/traits/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub trait MiscMethods<'tcx>: BackendTypes {
fn stats(&self) -> &RefCell<Stats>;
fn consume_stats(self) -> RefCell<Stats>;
fn codegen_unit(&self) -> &Arc<CodegenUnit<'tcx>>;
fn closure_env_needs_indirect_debuginfo(&self) -> bool;
fn used_statics(&self) -> &RefCell<Vec<Self::Value>>;
fn set_frame_pointer_elimination(&self, llfn: Self::Value);
fn apply_target_cpu_attr(&self, llfn: Self::Value);
Expand Down

0 comments on commit 6c2d704

Please sign in to comment.