about summary refs log tree commit diff
path: root/src/librustc/mir
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-03-08 20:54:28 +0100
committerGitHub <noreply@github.com>2020-03-08 20:54:28 +0100
commitff961789bc11bcace77e789cd680ee18de37ca05 (patch)
tree7cefec3af0236d25ad21f816763b812de09c092e /src/librustc/mir
parent85241b5aa6bd08b90f6ce88afdb9d0b3a1e2bdf7 (diff)
parent05f6482f435c498b19f3af56d1017c84323683f5 (diff)
downloadrust-ff961789bc11bcace77e789cd680ee18de37ca05.tar.gz
rust-ff961789bc11bcace77e789cd680ee18de37ca05.zip
Rollup merge of #69326 - JOE1994:os_str_widestring, r=RalfJung
mir-interpret: add method to read wide strings from Memory

Implemented *step2* from [instructions](https://github.com/rust-lang/miri/issues/707#issuecomment-561564057) laid out in rust-lang/miri#707.

Added 2 new methods to struct `rustc_mir::interpret::InterpCx`.

* `read_os_str_from_wide_str` (src/librustc_mir/interpret/operand.rs)
* `write_os_str_to_wide_str` (src/librustc_mir/interpret/place.rs)
  - used existing logic implemented in [MIRI/src/eval.rs](https://github.com/rust-lang/miri/blob/94732aaf7bf79fd01a4a48d11155c6586b937514/src/eval.rs#L132-L141)

These methods are intended to be used for environment variable emulation in Windows.
Diffstat (limited to 'src/librustc/mir')
-rw-r--r--src/librustc/mir/interpret/value.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs
index 2be60d35af3..9dc0b24cd2f 100644
--- a/src/librustc/mir/interpret/value.rs
+++ b/src/librustc/mir/interpret/value.rs
@@ -613,6 +613,11 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
     }
 
     #[inline(always)]
+    pub fn to_u16(self) -> InterpResult<'tcx, u16> {
+        self.not_undef()?.to_u16()
+    }
+
+    #[inline(always)]
     pub fn to_u32(self) -> InterpResult<'tcx, u32> {
         self.not_undef()?.to_u32()
     }
@@ -633,6 +638,11 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
     }
 
     #[inline(always)]
+    pub fn to_i16(self) -> InterpResult<'tcx, i16> {
+        self.not_undef()?.to_i16()
+    }
+
+    #[inline(always)]
     pub fn to_i32(self) -> InterpResult<'tcx, i32> {
         self.not_undef()?.to_i32()
     }