Skip to content

Commit

Permalink
rustc_codegen_ssa: remove redundant va_list_ref field from `Functio…
Browse files Browse the repository at this point in the history
…nCx`.
  • Loading branch information
eddyb committed Sep 28, 2019
1 parent a88d181 commit 057f23d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
12 changes: 7 additions & 5 deletions src/librustc_codegen_ssa/mir/block.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};
Expand Down Expand Up @@ -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() {
Expand Down
14 changes: 1 addition & 13 deletions src/librustc_codegen_ssa/mir/mod.rs
Expand Up @@ -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> {
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 057f23d

Please sign in to comment.