Skip to content

Commit 821f29b

Browse files
authored
Merge pull request #586 from solson/rustup
fix for infallible allocation
2 parents fd12f95 + d0f06a5 commit 821f29b

File tree

4 files changed

+37
-34
lines changed

4 files changed

+37
-34
lines changed

README.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ things (like adding support for a new intrinsic) can be done by working just on
9090
the miri side.
9191

9292
To prepare, make sure you are using a nightly Rust compiler. You also need to
93-
set up a libstd that enables execution with miri:
93+
set up a libstd that enables execution with Miri:
9494

9595
```sh
9696
rustup override set nightly # or the nightly in `rust-version`
9797
cargo run --bin cargo-miri -- miri setup
9898
```
9999

100100
The last command should end in printing the directory where the libstd was
101-
built. Set that as your MIRI_SYSROOT environment variable:
101+
built. Set that as your `MIRI_SYSROOT` environment variable:
102102

103103
```sh
104104
export MIRI_SYSROOT=~/.cache/miri/HOST # or whatever the previous command said
@@ -109,7 +109,7 @@ export MIRI_SYSROOT=~/.cache/miri/HOST # or whatever the previous command said
109109
Now you can run Miri directly, without going through `cargo miri`:
110110

111111
```sh
112-
cargo run tests/run-pass-fullmir/format.rs # or whatever test you like
112+
cargo run tests/run-pass/format.rs # or whatever test you like
113113
```
114114

115115
You can also run the test suite with `cargo test --release`. `cargo test
@@ -120,14 +120,33 @@ less time.
120120

121121
Now you are set up! You can write a failing test case, and tweak miri until it
122122
fails no more.
123+
You can get a trace of which MIR statements are being executed by setting the
124+
`MIRI_LOG` environment variable. For example:
125+
126+
```sh
127+
MIRI_LOG=info cargo run tests/run-pass/vecs.rs
128+
```
129+
130+
Setting `MIRI_LOG` like this will configure logging for miri itself as well as
131+
the `rustc::mir::interpret` and `rustc_mir::interpret` modules in rustc. You
132+
can also do more targeted configuration, e.g. to debug the stacked borrows
133+
implementation:
134+
```sh
135+
MIRI_LOG=rustc_mir::interpret=info,miri::stacked_borrows cargo run tests/run-pass/vecs.rs
136+
```
137+
138+
In addition, you can set `MIRI_BACKTRACE=1` to get a backtrace of where an
139+
evaluation error was originally created.
140+
123141

124142
### Using a locally built rustc
125143

126144
Since the heart of Miri (the main interpreter engine) lives in rustc, working on
127145
Miri will often require using a locally built rustc. The bug you want to fix
128146
may actually be on the rustc side, or you just need to get more detailed trace
129-
of the execution -- in both cases, you should develop miri against a rustc you
130-
compiled yourself, with debug assertions (and hence tracing) enabled.
147+
of the execution than what is possible with release builds -- in both cases, you
148+
should develop miri against a rustc you compiled yourself, with debug assertions
149+
(and hence tracing) enabled.
131150

132151
The setup for a local rustc works as follows:
133152
```sh
@@ -149,22 +168,6 @@ rustup override set custom
149168
With this, you should now have a working development setup! See
150169
["Testing Miri"](#testing-miri) above for how to proceed.
151170

152-
Moreover, you can now run Miri with a trace of all execution steps:
153-
```sh
154-
MIRI_LOG=debug cargo run tests/run-pass/vecs.rs
155-
```
156-
157-
Setting `MIRI_LOG` like this will configure logging for miri itself as well as
158-
the `rustc::mir::interpret` and `rustc_mir::interpret` modules in rustc. You
159-
can also do more targeted configuration, e.g. to debug the stacked borrows
160-
implementation:
161-
```sh
162-
MIRI_LOG=rustc_mir::interpret=debug,miri::stacked_borrows cargo run tests/run-pass/vecs.rs
163-
```
164-
165-
In addition, you can set `MIRI_BACKTRACE=1` to get a backtrace of where an
166-
evaluation error was originally created.
167-
168171
### Miri `-Z` flags and environment variables
169172

170173
Several `-Z` flags are relevant for Miri:

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2018-12-22
1+
nightly-2018-12-24

src/fn_call.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
8484
this.write_null(dest)?;
8585
} else {
8686
let align = this.tcx.data_layout.pointer_align.abi;
87-
let ptr = this.memory_mut().allocate(Size::from_bytes(size), align, MiriMemoryKind::C.into())?;
87+
let ptr = this.memory_mut().allocate(Size::from_bytes(size), align, MiriMemoryKind::C.into());
8888
this.write_scalar(Scalar::Ptr(ptr.with_default_tag()), dest)?;
8989
}
9090
}
@@ -114,7 +114,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
114114
Size::from_bytes(size),
115115
Align::from_bytes(align).unwrap(),
116116
MiriMemoryKind::Rust.into()
117-
)?
117+
)
118118
.with_default_tag();
119119
this.write_scalar(Scalar::Ptr(ptr), dest)?;
120120
}
@@ -132,7 +132,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
132132
Size::from_bytes(size),
133133
Align::from_bytes(align).unwrap(),
134134
MiriMemoryKind::Rust.into()
135-
)?
135+
)
136136
.with_default_tag();
137137
this.memory_mut()
138138
.get_mut(ptr.alloc_id)?
@@ -358,7 +358,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
358358
Size::from_bytes((value.len() + 1) as u64),
359359
Align::from_bytes(1).unwrap(),
360360
MiriMemoryKind::Env.into(),
361-
)?.with_default_tag();
361+
).with_default_tag();
362362
{
363363
let alloc = this.memory_mut().get_mut(value_copy.alloc_id)?;
364364
alloc.write_bytes(tcx, value_copy, &value)?;

src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
101101

102102
// Return value (in static memory so that it does not count as leak)
103103
let ret = ecx.layout_of(start_mir.return_ty())?;
104-
let ret_ptr = ecx.allocate(ret, MiriMemoryKind::MutStatic.into())?;
104+
let ret_ptr = ecx.allocate(ret, MiriMemoryKind::MutStatic.into());
105105

106106
// Push our stack frame
107107
ecx.push_stack_frame(
@@ -125,7 +125,7 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
125125
ecx.write_scalar(argc, dest)?;
126126
// Store argc for macOS _NSGetArgc
127127
{
128-
let argc_place = ecx.allocate(dest.layout, MiriMemoryKind::Env.into())?;
128+
let argc_place = ecx.allocate(dest.layout, MiriMemoryKind::Env.into());
129129
ecx.write_scalar(argc, argc_place.into())?;
130130
ecx.machine.argc = Some(argc_place.ptr.to_ptr()?);
131131
}
@@ -136,14 +136,14 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
136136
let dest = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?;
137137
let cmd = ecx.memory_mut().allocate_static_bytes(CMD.as_bytes()).with_default_tag();
138138
let raw_str_layout = ecx.layout_of(ecx.tcx.mk_imm_ptr(ecx.tcx.types.u8))?;
139-
let cmd_place = ecx.allocate(raw_str_layout, MiriMemoryKind::Env.into())?;
139+
let cmd_place = ecx.allocate(raw_str_layout, MiriMemoryKind::Env.into());
140140
ecx.write_scalar(Scalar::Ptr(cmd), cmd_place.into())?;
141141
ecx.memory_mut().mark_immutable(cmd_place.to_ptr()?.alloc_id)?;
142142
// Store argv for macOS _NSGetArgv
143143
{
144144
let argv = cmd_place.ptr;
145145
ecx.write_scalar(argv, dest)?;
146-
let argv_place = ecx.allocate(dest.layout, MiriMemoryKind::Env.into())?;
146+
let argv_place = ecx.allocate(dest.layout, MiriMemoryKind::Env.into());
147147
ecx.write_scalar(argv, argv_place.into())?;
148148
ecx.machine.argv = Some(argv_place.ptr.to_ptr()?);
149149
}
@@ -155,7 +155,7 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
155155
Size::from_bytes(cmd_utf16.len() as u64 * 2),
156156
Align::from_bytes(2).unwrap(),
157157
MiriMemoryKind::Env.into(),
158-
)?.with_default_tag();
158+
).with_default_tag();
159159
ecx.machine.cmd_line = Some(cmd_ptr);
160160
// store the UTF-16 string
161161
let char_size = Size::from_bytes(2);
@@ -516,13 +516,13 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
516516
ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
517517
ptr: Pointer,
518518
kind: MemoryKind<Self::MemoryKinds>,
519-
) -> EvalResult<'tcx, Pointer<Borrow>> {
519+
) -> Pointer<Borrow> {
520520
if !ecx.machine.validate {
521521
// No tracking
522-
Ok(ptr.with_default_tag())
522+
ptr.with_default_tag()
523523
} else {
524524
let tag = ecx.tag_new_allocation(ptr.alloc_id, kind);
525-
Ok(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag))
525+
Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag)
526526
}
527527
}
528528

0 commit comments

Comments
 (0)