rustc_codegen_ssa: remove redundant va_list_ref field from FunctionCx.

This commit is contained in:
Eduard-Mihai Burtescu 2019-08-12 15:27:31 +03:00
parent a88d181a02
commit 057f23d3dd
2 changed files with 8 additions and 18 deletions

View file

@ -1,3 +1,4 @@
use rustc_data_structures::indexed_vec::Idx;
use rustc::middle::lang_items; use rustc::middle::lang_items;
use rustc::ty::{self, Ty, TypeFoldable, Instance}; use rustc::ty::{self, Ty, TypeFoldable, Instance};
use rustc::ty::layout::{self, LayoutOf, HasTyCtxt, FnTypeExt}; 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) { 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 { if self.fn_ty.c_variadic {
match self.va_list_ref { // The `VaList` "spoofed" argument is just after all the real arguments.
Some(va_list) => { 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); bx.va_end(va_list.llval);
} }
None => { _ => bug!("C-variadic function must have a `VaList` place"),
bug!("C-variadic function must have a `va_list_ref`");
}
} }
} }
if self.fn_ty.ret.layout.abi.is_uninhabited() { if self.fn_ty.ret.layout.abi.is_uninhabited() {

View file

@ -81,10 +81,6 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
/// Debug information for MIR scopes. /// Debug information for MIR scopes.
scopes: IndexVec<mir::SourceScope, debuginfo::MirDebugScope<Bx::DIScope>>, 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> { 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, scopes,
locals: IndexVec::new(), locals: IndexVec::new(),
debug_context, debug_context,
va_list_ref: None,
}; };
let memory_locals = analyze::non_ssa_locals(&fx); let memory_locals = analyze::non_ssa_locals(&fx);
// Allocate variable and temp allocas // Allocate variable and temp allocas
fx.locals = { fx.locals = {
// FIXME(dlrobertson): This is ugly. Find a better way of getting the `PlaceRef` or let args = arg_local_refs(&mut bx, &fx, &memory_locals);
// `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 mut allocate_local = |local| { let mut allocate_local = |local| {
let decl = &mir.local_decls[local]; let decl = &mir.local_decls[local];
@ -426,7 +417,6 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
bx: &mut Bx, bx: &mut Bx,
fx: &FunctionCx<'a, 'tcx, Bx>, fx: &FunctionCx<'a, 'tcx, Bx>,
memory_locals: &BitSet<mir::Local>, memory_locals: &BitSet<mir::Local>,
va_list_ref: &mut Option<PlaceRef<'tcx, Bx::Value>>,
) -> Vec<LocalRef<'tcx, Bx::Value>> { ) -> Vec<LocalRef<'tcx, Bx::Value>> {
let mir = fx.mir; let mir = fx.mir;
let tcx = fx.cx.tcx(); 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)); let va_list = PlaceRef::alloca(bx, bx.layout_of(arg_ty));
bx.set_var_name(va_list.llval, name); bx.set_var_name(va_list.llval, name);
bx.va_start(va_list.llval); bx.va_start(va_list.llval);
// FIXME(eddyb) remove `va_list_ref`.
*va_list_ref = Some(va_list);
arg_scope.map(|scope| { arg_scope.map(|scope| {
let variable_access = VariableAccess::DirectVariable { let variable_access = VariableAccess::DirectVariable {