From a55ac1fea8fe4ca8d96d359a8f5b9538e5e9c351 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 15 Jun 2016 12:55:04 +0200 Subject: [PATCH] pass arguments to `start` --- src/bin/miri.rs | 11 +++++++++++ src/interpreter/mod.rs | 6 +++++- tests/compiletest.rs | 3 +++ tests/run-pass/start_fn.rs | 7 +++++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/bin/miri.rs b/src/bin/miri.rs index cdd6ee027d9..8cc52e39ca6 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -48,6 +48,17 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls { ecx.push_stack_frame(def_id, mir.span, CachedMir::Ref(mir), substs, Some(return_ptr)); + if mir.arg_decls.len() == 2 { + // start function + let ptr_size = ecx.memory().pointer_size; + let nargs = ecx.memory_mut().allocate(ptr_size); + ecx.memory_mut().write_usize(nargs, 0).unwrap(); + let args = ecx.memory_mut().allocate(ptr_size); + ecx.memory_mut().write_usize(args, 0).unwrap(); + ecx.frame_mut().locals[0] = nargs; + ecx.frame_mut().locals[1] = args; + } + loop { match step(&mut ecx) { Ok(true) => {} diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 1b0b416e0e1..89a3b2f593e 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -154,6 +154,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { &self.memory } + pub fn memory_mut(&mut self) -> &mut Memory<'tcx> { + &mut self.memory + } + pub fn stack(&self) -> &[Frame] { &self.stack } @@ -1373,7 +1377,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { self.stack.last().expect("no call frames exist") } - fn frame_mut(&mut self) -> &mut Frame<'a, 'tcx> { + pub fn frame_mut(&mut self) -> &mut Frame<'a, 'tcx> { self.stack.last_mut().expect("no call frames exist") } diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 77cfc57db29..7ce9636fc05 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -21,6 +21,9 @@ fn run_mode(mode: &'static str) { let targets = &["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]; for &target in targets { + use std::io::Write; + let stderr = std::io::stderr(); + write!(stderr.lock(), "running tests for target {}", target).unwrap(); let mut config = compiletest::default_config(); config.host_rustcflags = Some(flags.clone()); config.mode = mode.parse().expect("Invalid mode"); diff --git a/tests/run-pass/start_fn.rs b/tests/run-pass/start_fn.rs index 600f6e49f68..8b884e22fed 100644 --- a/tests/run-pass/start_fn.rs +++ b/tests/run-pass/start_fn.rs @@ -1,6 +1,9 @@ #![feature(start)] #[start] -fn foo(_nargs: isize, _args: *const *const u8) -> isize { - return 0; +fn foo(nargs: isize, args: *const *const u8) -> isize { + if nargs > 0 { + assert!(unsafe{*args} as usize != 0); + } + 0 }