Skip to content
Permalink
Browse files

rustc_codegen_ssa: remove redundant `va_list_ref` field from `Functio…

…nCx`.
  • Loading branch information...
eddyb committed Aug 12, 2019
1 parent a88d181 commit 057f23d3ddabf8c89e5da371d724d1995e9655da
Showing with 8 additions and 18 deletions.
  1. +7 −5 src/librustc_codegen_ssa/mir/block.rs
  2. +1 −13 src/librustc_codegen_ssa/mir/mod.rs
@@ -1,3 +1,4 @@
use rustc_data_structures::indexed_vec::Idx;
use rustc::middle::lang_items;
use rustc::ty::{self, Ty, TypeFoldable, Instance};
use rustc::ty::layout::{self, LayoutOf, HasTyCtxt, FnTypeExt};
@@ -224,14 +225,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}

fn codegen_return_terminator(&mut self, mut bx: Bx) {
// Call `va_end` if this is the definition of a C-variadic function.
if self.fn_ty.c_variadic {
match self.va_list_ref {
Some(va_list) => {
// The `VaList` "spoofed" argument is just after all the real arguments.
let va_list_arg_idx = self.fn_ty.args.len();
match self.locals[mir::Local::new(1 + va_list_arg_idx)] {
LocalRef::Place(va_list) => {
bx.va_end(va_list.llval);
}
None => {
bug!("C-variadic function must have a `va_list_ref`");
}
_ => bug!("C-variadic function must have a `VaList` place"),
}
}
if self.fn_ty.ret.layout.abi.is_uninhabited() {
@@ -81,10 +81,6 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {

/// Debug information for MIR scopes.
scopes: IndexVec<mir::SourceScope, debuginfo::MirDebugScope<Bx::DIScope>>,

/// If this function is a C-variadic function, this contains the `PlaceRef` of the
/// "spoofed" `VaListImpl`.
va_list_ref: Option<PlaceRef<'tcx, Bx::Value>>,
}

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
@@ -236,18 +232,13 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
scopes,
locals: IndexVec::new(),
debug_context,
va_list_ref: None,
};

let memory_locals = analyze::non_ssa_locals(&fx);

// Allocate variable and temp allocas
fx.locals = {
// FIXME(dlrobertson): This is ugly. Find a better way of getting the `PlaceRef` or
// `LocalRef` from `arg_local_refs`
let mut va_list_ref = None;
let args = arg_local_refs(&mut bx, &fx, &memory_locals, &mut va_list_ref);
fx.va_list_ref = va_list_ref;
let args = arg_local_refs(&mut bx, &fx, &memory_locals);

let mut allocate_local = |local| {
let decl = &mir.local_decls[local];
@@ -426,7 +417,6 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
bx: &mut Bx,
fx: &FunctionCx<'a, 'tcx, Bx>,
memory_locals: &BitSet<mir::Local>,
va_list_ref: &mut Option<PlaceRef<'tcx, Bx::Value>>,
) -> Vec<LocalRef<'tcx, Bx::Value>> {
let mir = fx.mir;
let tcx = fx.cx.tcx();
@@ -500,8 +490,6 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let va_list = PlaceRef::alloca(bx, bx.layout_of(arg_ty));
bx.set_var_name(va_list.llval, name);
bx.va_start(va_list.llval);
// FIXME(eddyb) remove `va_list_ref`.
*va_list_ref = Some(va_list);

arg_scope.map(|scope| {
let variable_access = VariableAccess::DirectVariable {

0 comments on commit 057f23d

Please sign in to comment.
You can’t perform that action at this time.