Skip to content

Commit a55ac1f

Browse files
committed
pass arguments to start
1 parent 8abd293 commit a55ac1f

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

src/bin/miri.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
4848

4949
ecx.push_stack_frame(def_id, mir.span, CachedMir::Ref(mir), substs, Some(return_ptr));
5050

51+
if mir.arg_decls.len() == 2 {
52+
// start function
53+
let ptr_size = ecx.memory().pointer_size;
54+
let nargs = ecx.memory_mut().allocate(ptr_size);
55+
ecx.memory_mut().write_usize(nargs, 0).unwrap();
56+
let args = ecx.memory_mut().allocate(ptr_size);
57+
ecx.memory_mut().write_usize(args, 0).unwrap();
58+
ecx.frame_mut().locals[0] = nargs;
59+
ecx.frame_mut().locals[1] = args;
60+
}
61+
5162
loop {
5263
match step(&mut ecx) {
5364
Ok(true) => {}

src/interpreter/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
154154
&self.memory
155155
}
156156

157+
pub fn memory_mut(&mut self) -> &mut Memory<'tcx> {
158+
&mut self.memory
159+
}
160+
157161
pub fn stack(&self) -> &[Frame] {
158162
&self.stack
159163
}
@@ -1373,7 +1377,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
13731377
self.stack.last().expect("no call frames exist")
13741378
}
13751379

1376-
fn frame_mut(&mut self) -> &mut Frame<'a, 'tcx> {
1380+
pub fn frame_mut(&mut self) -> &mut Frame<'a, 'tcx> {
13771381
self.stack.last_mut().expect("no call frames exist")
13781382
}
13791383

tests/compiletest.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ fn run_mode(mode: &'static str) {
2121
let targets = &["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"];
2222

2323
for &target in targets {
24+
use std::io::Write;
25+
let stderr = std::io::stderr();
26+
write!(stderr.lock(), "running tests for target {}", target).unwrap();
2427
let mut config = compiletest::default_config();
2528
config.host_rustcflags = Some(flags.clone());
2629
config.mode = mode.parse().expect("Invalid mode");

tests/run-pass/start_fn.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#![feature(start)]
22

33
#[start]
4-
fn foo(_nargs: isize, _args: *const *const u8) -> isize {
5-
return 0;
4+
fn foo(nargs: isize, args: *const *const u8) -> isize {
5+
if nargs > 0 {
6+
assert!(unsafe{*args} as usize != 0);
7+
}
8+
0
69
}

0 commit comments

Comments
 (0)