From 668f2b6fd475af40e1b19d49f04ee5feab83a68f Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Fri, 18 Mar 2016 23:20:59 -0600 Subject: [PATCH] Implement bytestring literals. --- src/interpreter.rs | 9 ++++++++- test/strings.rs | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/interpreter.rs b/src/interpreter.rs index 620f994ddcf..a15eec77b5b 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -620,7 +620,14 @@ impl<'a, 'tcx: 'a, 'arena> Interpreter<'a, 'tcx, 'arena> { try!(self.memory.write_uint(ptr.offset(psize as isize), s.len() as u64, psize)); Ok(ptr) } - ByteStr(ref _bs) => unimplemented!(), + ByteStr(ref bs) => { + let psize = self.memory.pointer_size; + let static_ptr = self.memory.allocate(bs.len()); + let ptr = self.memory.allocate(psize); + try!(self.memory.write_bytes(static_ptr, bs)); + try!(self.memory.write_ptr(ptr, static_ptr)); + Ok(ptr) + } Bool(b) => { let ptr = self.memory.allocate(1); try!(self.memory.write_bool(ptr, b)); diff --git a/test/strings.rs b/test/strings.rs index 0b9c3faff64..a442901bb59 100755 --- a/test/strings.rs +++ b/test/strings.rs @@ -10,3 +10,8 @@ fn empty() -> &'static str { fn hello() -> &'static str { "Hello, world!" } + +#[miri_run] +fn hello_bytes() -> &'static [u8; 13] { + b"Hello, world!" +}