From 446ed26412eeb7263b0474b3c9468cc075309c27 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 29 Aug 2017 12:24:58 +0200 Subject: [PATCH] Add at least the program name argument in order to get rustc tests a little further --- miri/lib.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/miri/lib.rs b/miri/lib.rs index 852a4cbe2aa..a824f47a509 100644 --- a/miri/lib.rs +++ b/miri/lib.rs @@ -15,6 +15,7 @@ use rustc::hir::def_id::DefId; use rustc::mir; +use syntax::ast::Mutability; use syntax::codemap::Span; use std::collections::{HashMap, BTreeMap}; @@ -98,15 +99,21 @@ fn run_main<'a, 'tcx: 'a>( dest, )?; - // Second argument (argc): 0 + // Second argument (argc): 1 let dest = ecx.eval_lvalue(&mir::Lvalue::Local(args.next().unwrap()))?; let ty = ecx.tcx.types.isize; - ecx.write_null(dest, ty)?; + ecx.write_primval(dest, PrimVal::Bytes(1), ty)?; - // Third argument (argv): 0 + // FIXME: extract main source file path + // Third argument (argv): &[b"foo"] let dest = ecx.eval_lvalue(&mir::Lvalue::Local(args.next().unwrap()))?; let ty = ecx.tcx.mk_imm_ptr(ecx.tcx.mk_imm_ptr(ecx.tcx.types.u8)); - ecx.write_null(dest, ty)?; + let foo = ecx.memory.allocate_cached(b"foo\0")?; + let ptr_size = ecx.memory.pointer_size(); + let foo_ptr = ecx.memory.allocate(ptr_size * 1, ptr_size, MemoryKind::UninitializedStatic)?; + ecx.memory.write_primval(foo_ptr.into(), PrimVal::Ptr(foo.into()), ptr_size, false)?; + ecx.memory.mark_static_initalized(foo_ptr.alloc_id, Mutability::Immutable)?; + ecx.write_ptr(dest, foo_ptr.into(), ty)?; } else { ecx.push_stack_frame( main_instance,