Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustup #364

Closed
wants to merge 30 commits into from
Closed

Rustup #364

wants to merge 30 commits into from

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Mar 17, 2018

Based on #361

@oli-obk
Copy link
Contributor

oli-obk commented Mar 18, 2018

so now we're hitting some alignment issue in the initialization... I'll have to analyze this in detail

let src = self.into_ptr(args[0].value)?;
let src_align = self.layout_of(args[0].ty)?.align;
Copy link
Member Author

@bjorn3 bjorn3 Mar 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so now we're hitting some alignment issue in the initialization... I'll have to analyze this in detail

This takes the alignment of the pointer itself, instead of what it points to.

@bjorn3
Copy link
Member Author

bjorn3 commented Mar 18, 2018

#364 (comment) is the root cause of the alignment issue, temporarily worked around it. I am getting this error now:

error[E0080]: constant evaluation error
   --> /home/bjorn/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/thread/mod.rs:939:16
    |
939 |             if COUNTER == ::u64::MAX {
    |                ^^^^^^^^^^^^^^^^^^^^^ attempted to read undefined bytes
    |
note: inside call to `std::thread::ThreadId::new`
   --> /home/bjorn/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/thread/mod.rs:1008:21
    |
1008|                 id: ThreadId::new(),
    |                     ^^^^^^^^^^^^^^^
note: inside call to `std::thread::Thread::new`
   --> /home/bjorn/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:50:22
    |
50  |         let thread = Thread::new(Some("main".to_owned()));
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `std::rt::lang_start_internal`
   --> /home/bjorn/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:74:5
    |
74  |     lang_start_internal(&move || main().report(), argc, argv)
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Copy link
Member

@solson solson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick skim, though I didn't pay attention to which changes were yours or from the other PR.

miri/fn_call.rs Outdated
let def_id = instance.def_id();
let item_path = self.tcx.absolute_item_path_str(def_id);
if item_path.starts_with("std::") {
println!("{}", item_path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stray debug println should be removed (or use the debug! logging macro).

miri/fn_call.rs Outdated
println!("{}", item_path);
}
match &*item_path {
"std::sys::unix::thread::guard::init" | "std::sys::unix::thread::guard::current" => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a more thorough explanation of what problem this solves?

miri/fn_call.rs Outdated
match ret_ty.sty {
ty::TyAdt(ref adt_def, _) => {
assert!(adt_def.is_enum(), "Unexpected return type for {}", item_path);
let none_variant_index = adt_def.variants.iter().enumerate().find(|&(_i, ref def)| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Iterator::position to simplify this, as in:

let none_variant_index = adt_def.variants.iter().position(|def| def.name.as_str() == "None").expect("No None variant");

Place::Ptr { .. } => {
bug!("init intrinsic tried to write to fat or unaligned ptr target")
}
_ => bug!("TODO"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate this TODO? What needs to be done here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, it comes from #361

@oli-obk
Copy link
Contributor

oli-obk commented Mar 19, 2018

The current failure looks to me like we are not initializing static muts. There were a lot of changes in rustc around statics, I'll look into it.

@bjorn3
Copy link
Member Author

bjorn3 commented Mar 19, 2018

@oli-obk second last commit should fix it. I incorrectly returned true from mark_static_initialised

@oli-obk
Copy link
Contributor

oli-obk commented Mar 19, 2018

The problem is that the const evaluation from rustc ends up creating an immutable allocation. You need to evaluate the static without calling tcx.const_eval. The relevant methods are in rustc_mir::interpret::const_eval and should be public.

kennytm added a commit to kennytm/rust that referenced this pull request Mar 21, 2018
Don't check interpret_interner when accessing a static to fix miri mutable statics

Mutable statics don't work in my PR to fix the standalone [miri](https://github.com/solson/miri), as init_static didn't get called when the interpret_interner already contained a entry for the static, which is always immutable.

cc rust-lang/miri#364
kennytm added a commit to kennytm/rust that referenced this pull request Mar 22, 2018
Don't check interpret_interner when accessing a static to fix miri mutable statics

Mutable statics don't work in my PR to fix the standalone [miri](https://github.com/solson/miri), as init_static didn't get called when the interpret_interner already contained a entry for the static, which is always immutable.

cc rust-lang/miri#364
miri/lib.rs Outdated
.interpret_interner
.get_cached(cid.instance.def_id())
.expect("uncached static");
ecx.memory.copy(ptr, layout.align, to_ptr.into(), layout.align, layout.size.bytes(), true)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work, because the memory might contain references into other statics. We also can't implement it as deep copies, because then we'd duplicate some other static's memory instead of referring to it.

Instead of calling ecx.const_eval do the code you had above, just without the interpret_interner accesses (instead to the machine caching as you do it here)

miri/lib.rs Outdated
@@ -287,6 +287,7 @@ impl<'mir, 'tcx: 'mir> Machine<'mir, 'tcx> for Evaluator<'tcx> {
.interpret_interner
.get_cached(cid.instance.def_id())
.expect("uncached static");
// TODO: do a recursive copy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, no recursive copy. if you have

static FOO: &'static Foo = &BAR;
static BAR: Foo = Foo { field: &FOO };

Then BAR would end up referring to a copy of FOO instead of referring to it directly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't evaluate the static in the same EvalContext as far as I know, so we have to copy it anyway. A cache could be used just like ecx.memory.data.mut_static to prevent duplication.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do it. Just push a stackframe for it as you had before 907e67f

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the while ecx.step()? {} will step out of the frame present at the beginning of the init_static function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, you can solve that by recording the stack size before pushing the frame (self.frames().len()) in a variable and looping until you're back at the same frame.

@oli-obk
Copy link
Contributor

oli-obk commented Mar 31, 2018

Do you know where miri is failing atm? The travis logs are unhelpful due to an error reporting bug I need to fix in rustc

@bjorn3
Copy link
Member Author

bjorn3 commented Mar 31, 2018

With rust-lang/rust#49540 applied run-pass gives:

failures:

---- [ui] run-pass/issue-15523-big.rs stdout ----
	normalized stderr:
error[E0080]: constant evaluation error
  --> $DIR/issue-15523-big.rs:17:21
   |
17 | #[derive(PartialEq, PartialOrd)]
   |                     ^^^^^^^^^^ invalid enum discriminant value read
   |
note: inside call to `<Eu64 as std::cmp::PartialOrd>::partial_cmp`
  --> /home/bjorn/Documenten/rust2/src/libcore/cmp.rs:647:15
   |
647|         match self.partial_cmp(other) {
   |               ^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `<Eu64 as std::cmp::PartialOrd>::lt`
  --> $DIR/issue-15523-big.rs:37:13
   |
37 |     assert!(Eu64::Pos2 < Eu64::PosMax);
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `main`
  --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:74:34
   |
74 |     lang_start_internal(&move || main().report(), argc, argv)
   |                                  ^^^^^^
note: inside call to `closure`
  --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:59:75
   |
59 |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
   |                                                                           ^^^^^^
note: inside call to `closure`
  --> /home/bjorn/Documenten/rust2/src/libstd/sys_common/backtrace.rs:136:5
   |
136|     f()
   |     ^^^
note: inside call to `std::sys_common::backtrace::__rust_begin_short_backtrace::<[closure@DefId(1/1:1802 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]::{{closure}}[0]) 0:&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
  --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:59:13
   |
59 |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `closure`
  --> /home/bjorn/Documenten/rust2/src/libstd/panicking.rs:306:40
   |
306|             ptr::write(&mut (*data).r, f());
   |                                        ^^^
note: inside call to `std::panicking::try::do_call::<[closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
  --> /home/bjorn/Documenten/rust2/src/libstd/panicking.rs:302:5
   |
302| /     fn do_call<F: FnOnce() -> R, R>(data: *mut u8) {
303| |         unsafe {
304| |             let data = data as *mut Data<F, R>;
305| |             let f = ptr::read(&mut (*data).f);
306| |             ptr::write(&mut (*data).r, f());
307| |         }
308| |     }
   | |_____^
note: inside call to `std::panicking::try::<i32, [closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe]>`
  --> /home/bjorn/Documenten/rust2/src/libstd/panic.rs:361:9
   |
361|         panicking::try(f)
   |         ^^^^^^^^^^^^^^^^^
note: inside call to `std::panic::catch_unwind::<[closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
  --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:58:25
   |
58 |           let exit_code = panic::catch_unwind(|| {
   |  _________________________^
59 | |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
60 | |         });
   | |__________^
note: inside call to `std::rt::lang_start_internal`
  --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:74:5
   |
74 |     lang_start_internal(&move || main().report(), argc, argv)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.


expected stderr:


diff of stderr:

+error[E0080]: constant evaluation error
+  --> $DIR/issue-15523-big.rs:17:21
+   |
+17 | #[derive(PartialEq, PartialOrd)]
+   |                     ^^^^^^^^^^ invalid enum discriminant value read
+   |
+note: inside call to `<Eu64 as std::cmp::PartialOrd>::partial_cmp`
+  --> /home/bjorn/Documenten/rust2/src/libcore/cmp.rs:647:15
+   |
+647|         match self.partial_cmp(other) {
+   |               ^^^^^^^^^^^^^^^^^^^^^^^
+note: inside call to `<Eu64 as std::cmp::PartialOrd>::lt`
+  --> $DIR/issue-15523-big.rs:37:13
+   |
+37 |     assert!(Eu64::Pos2 < Eu64::PosMax);
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^
+note: inside call to `main`
+  --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:74:34
+   |
+74 |     lang_start_internal(&move || main().report(), argc, argv)
+   |                                  ^^^^^^
+note: inside call to `closure`
+  --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:59:75
+   |
+59 |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
+   |                                                                           ^^^^^^
+note: inside call to `closure`
+  --> /home/bjorn/Documenten/rust2/src/libstd/sys_common/backtrace.rs:136:5
+   |
+136|     f()
+   |     ^^^
+note: inside call to `std::sys_common::backtrace::__rust_begin_short_backtrace::<[closure@DefId(1/1:1802 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]::{{closure}}[0]) 0:&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
+  --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:59:13
+   |
+59 |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+note: inside call to `closure`
+  --> /home/bjorn/Documenten/rust2/src/libstd/panicking.rs:306:40
+   |
+306|             ptr::write(&mut (*data).r, f());
+   |                                        ^^^
+note: inside call to `std::panicking::try::do_call::<[closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
+  --> /home/bjorn/Documenten/rust2/src/libstd/panicking.rs:302:5
+   |
+302| /     fn do_call<F: FnOnce() -> R, R>(data: *mut u8) {
+303| |         unsafe {
+304| |             let data = data as *mut Data<F, R>;
+305| |             let f = ptr::read(&mut (*data).f);
+306| |             ptr::write(&mut (*data).r, f());
+307| |         }
+308| |     }
+   | |_____^
+note: inside call to `std::panicking::try::<i32, [closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe]>`
+  --> /home/bjorn/Documenten/rust2/src/libstd/panic.rs:361:9
+   |
+361|         panicking::try(f)
+   |         ^^^^^^^^^^^^^^^^^
+note: inside call to `std::panic::catch_unwind::<[closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
+  --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:58:25
+   |
+58 |           let exit_code = panic::catch_unwind(|| {
+   |  _________________________^
+59 | |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
+60 | |         });
+   | |__________^
+note: inside call to `std::rt::lang_start_internal`
+  --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:74:5
+   |
+74 |     lang_start_internal(&move || main().report(), argc, argv)
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.
+

The actual stderr differed from the expected stderr.
Actual stderr saved to /tmp/compiletest.H6HYTdQhAgsq/issue-15523-big.stderr
To update references, run this command from build directory:
tests/run-pass/update-references.sh '/tmp/compiletest.H6HYTdQhAgsq' 'issue-15523-big.rs'

error: 1 errors occurred comparing output.
status: exit code: 101
command: "target/debug/miri" "tests/run-pass/issue-15523-big.rs" "-L" "/tmp/compiletest.H6HYTdQhAgsq" "--target=x86_64-unknown-linux-gnu" "-C" "prefer-dynamic" "-o" "/tmp/compiletest.H6HYTdQhAgsq/issue-15523-big.stage-id" "-Zmir-opt-level=0" "-Zmir-emit-validate=1" "-L" "/tmp/compiletest.H6HYTdQhAgsq/issue-15523-big.stage-id.aux" "-A" "unused"
stdout:
------------------------------------------

------------------------------------------
stderr:
------------------------------------------
error[E0080]: constant evaluation error
  --> tests/run-pass/issue-15523-big.rs:17:21
   |
17 | #[derive(PartialEq, PartialOrd)]
   |                     ^^^^^^^^^^ invalid enum discriminant value read
   |
note: inside call to `<Eu64 as std::cmp::PartialOrd>::partial_cmp`
  --> /home/bjorn/Documenten/rust2/src/libcore/cmp.rs:647:15
   |
647|         match self.partial_cmp(other) {
   |               ^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `<Eu64 as std::cmp::PartialOrd>::lt`
  --> tests/run-pass/issue-15523-big.rs:37:13
   |
37 |     assert!(Eu64::Pos2 < Eu64::PosMax);
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `main`
  --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:74:34
   |
74 |     lang_start_internal(&move || main().report(), argc, argv)
   |                                  ^^^^^^
note: inside call to `closure`
  --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:59:75
   |
59 |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
   |                                                                           ^^^^^^
note: inside call to `closure`
  --> /home/bjorn/Documenten/rust2/src/libstd/sys_common/backtrace.rs:136:5
   |
136|     f()
   |     ^^^
note: inside call to `std::sys_common::backtrace::__rust_begin_short_backtrace::<[closure@DefId(1/1:1802 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]::{{closure}}[0]) 0:&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
  --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:59:13
   |
59 |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `closure`
  --> /home/bjorn/Documenten/rust2/src/libstd/panicking.rs:306:40
   |
306|             ptr::write(&mut (*data).r, f());
   |                                        ^^^
note: inside call to `std::panicking::try::do_call::<[closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
  --> /home/bjorn/Documenten/rust2/src/libstd/panicking.rs:302:5
   |
302| /     fn do_call<F: FnOnce() -> R, R>(data: *mut u8) {
303| |         unsafe {
304| |             let data = data as *mut Data<F, R>;
305| |             let f = ptr::read(&mut (*data).f);
306| |             ptr::write(&mut (*data).r, f());
307| |         }
308| |     }
   | |_____^
note: inside call to `std::panicking::try::<i32, [closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe]>`
  --> /home/bjorn/Documenten/rust2/src/libstd/panic.rs:361:9
   |
361|         panicking::try(f)
   |         ^^^^^^^^^^^^^^^^^
note: inside call to `std::panic::catch_unwind::<[closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
  --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:58:25
   |
58 |           let exit_code = panic::catch_unwind(|| {
   |  _________________________^
59 | |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
60 | |         });
   | |__________^
note: inside call to `std::rt::lang_start_internal`
  --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:74:5
   |
74 |     lang_start_internal(&move || main().report(), argc, argv)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.

------------------------------------------

thread '[ui] run-pass/issue-15523-big.rs' panicked at 'explicit panic', /home/bjorn/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/compiletest_rs-0.3.8/src/runtest.rs:2539:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: std::panicking::rust_panic_with_hook
   5: std::panicking::begin_panic
             at /home/bjorn/Documenten/rust2/src/libstd/panicking.rs:365
   6: compiletest_rs::runtest::ProcRes::fatal
             at /home/bjorn/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/compiletest_rs-0.3.8/src/runtest.rs:2539
   7: compiletest_rs::runtest::TestCx::fatal_proc_rec
             at /home/bjorn/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/compiletest_rs-0.3.8/src/runtest.rs:1639
   8: compiletest_rs::runtest::TestCx::run_ui_test
             at /home/bjorn/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/compiletest_rs-0.3.8/src/runtest.rs:2238
   9: compiletest_rs::runtest::TestCx::run_revision
             at /home/bjorn/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/compiletest_rs-0.3.8/src/runtest.rs:140
  10: compiletest_rs::runtest::run
             at /home/bjorn/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/compiletest_rs-0.3.8/src/runtest.rs:80
  11: compiletest_rs::make_test_closure::{{closure}}
             at /home/bjorn/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/compiletest_rs-0.3.8/src/lib.rs:275
  12: <F as alloc::boxed::FnBox<A>>::call_box
             at /home/bjorn/Documenten/rust2/src/liballoc/boxed.rs:783
  13: <F as alloc::boxed::FnBox<A>>::call_box
  14: __rust_maybe_catch_panic

---- [ui] run-pass/zero-sized-binary-heap-push.rs stdout ----
	normalized stderr:
error[E0080]: constant evaluation error
   --> /home/bjorn/Documenten/rust2/src/libcore/ptr.rs:364:42
    |
364 |     intrinsics::move_val_init(&mut *dst, src)
    |                                          ^^^ a memory access tried to interpret some bytes as a pointer
    |
note: inside call to `std::ptr::write::<()>`
   --> /home/bjorn/Documenten/rust2/src/liballoc/vec.rs:1063:13
    |
1063|             ptr::write(end, value);
    |             ^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `<std::vec::Vec<T>><()>::push`
   --> /home/bjorn/Documenten/rust2/src/liballoc/binary_heap.rs:582:9
    |
582 |         self.data.push(item);
    |         ^^^^^^^^^^^^^^^^^^^^
note: inside call to `<std::collections::BinaryHeap<T>><()>::push`
   --> $DIR/zero-sized-binary-heap-push.rs:22:13
    |
22  |             tester.push(());
    |             ^^^^^^^^^^^^^^^
note: inside call to `main`
   --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:74:34
    |
74  |     lang_start_internal(&move || main().report(), argc, argv)
    |                                  ^^^^^^
note: inside call to `closure`
   --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:59:75
    |
59  |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
    |                                                                           ^^^^^^
note: inside call to `closure`
   --> /home/bjorn/Documenten/rust2/src/libstd/sys_common/backtrace.rs:136:5
    |
136 |     f()
    |     ^^^
note: inside call to `std::sys_common::backtrace::__rust_begin_short_backtrace::<[closure@DefId(1/1:1802 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]::{{closure}}[0]) 0:&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
   --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:59:13
    |
59  |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `closure`
   --> /home/bjorn/Documenten/rust2/src/libstd/panicking.rs:306:40
    |
306 |             ptr::write(&mut (*data).r, f());
    |                                        ^^^
note: inside call to `std::panicking::try::do_call::<[closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
   --> /home/bjorn/Documenten/rust2/src/libstd/panicking.rs:302:5
    |
302 | /     fn do_call<F: FnOnce() -> R, R>(data: *mut u8) {
303 | |         unsafe {
304 | |             let data = data as *mut Data<F, R>;
305 | |             let f = ptr::read(&mut (*data).f);
306 | |             ptr::write(&mut (*data).r, f());
307 | |         }
308 | |     }
    | |_____^
note: inside call to `std::panicking::try::<i32, [closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe]>`
   --> /home/bjorn/Documenten/rust2/src/libstd/panic.rs:361:9
    |
361 |         panicking::try(f)
    |         ^^^^^^^^^^^^^^^^^
note: inside call to `std::panic::catch_unwind::<[closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
   --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:58:25
    |
58  |           let exit_code = panic::catch_unwind(|| {
    |  _________________________^
59  | |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
60  | |         });
    | |__________^
note: inside call to `std::rt::lang_start_internal`
   --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:74:5
    |
74  |     lang_start_internal(&move || main().report(), argc, argv)
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.


expected stderr:


diff of stderr:

+error[E0080]: constant evaluation error
+   --> /home/bjorn/Documenten/rust2/src/libcore/ptr.rs:364:42
+    |
+364 |     intrinsics::move_val_init(&mut *dst, src)
+    |                                          ^^^ a memory access tried to interpret some bytes as a pointer
+    |
+note: inside call to `std::ptr::write::<()>`
+   --> /home/bjorn/Documenten/rust2/src/liballoc/vec.rs:1063:13
+    |
+1063|             ptr::write(end, value);
+    |             ^^^^^^^^^^^^^^^^^^^^^^
+note: inside call to `<std::vec::Vec<T>><()>::push`
+   --> /home/bjorn/Documenten/rust2/src/liballoc/binary_heap.rs:582:9
+    |
+582 |         self.data.push(item);
+    |         ^^^^^^^^^^^^^^^^^^^^
+note: inside call to `<std::collections::BinaryHeap<T>><()>::push`
+   --> $DIR/zero-sized-binary-heap-push.rs:22:13
+    |
+22  |             tester.push(());
+    |             ^^^^^^^^^^^^^^^
+note: inside call to `main`
+   --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:74:34
+    |
+74  |     lang_start_internal(&move || main().report(), argc, argv)
+    |                                  ^^^^^^
+note: inside call to `closure`
+   --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:59:75
+    |
+59  |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
+    |                                                                           ^^^^^^
+note: inside call to `closure`
+   --> /home/bjorn/Documenten/rust2/src/libstd/sys_common/backtrace.rs:136:5
+    |
+136 |     f()
+    |     ^^^
+note: inside call to `std::sys_common::backtrace::__rust_begin_short_backtrace::<[closure@DefId(1/1:1802 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]::{{closure}}[0]) 0:&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
+   --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:59:13
+    |
+59  |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
+    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+note: inside call to `closure`
+   --> /home/bjorn/Documenten/rust2/src/libstd/panicking.rs:306:40
+    |
+306 |             ptr::write(&mut (*data).r, f());
+    |                                        ^^^
+note: inside call to `std::panicking::try::do_call::<[closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
+   --> /home/bjorn/Documenten/rust2/src/libstd/panicking.rs:302:5
+    |
+302 | /     fn do_call<F: FnOnce() -> R, R>(data: *mut u8) {
+303 | |         unsafe {
+304 | |             let data = data as *mut Data<F, R>;
+305 | |             let f = ptr::read(&mut (*data).f);
+306 | |             ptr::write(&mut (*data).r, f());
+307 | |         }
+308 | |     }
+    | |_____^
+note: inside call to `std::panicking::try::<i32, [closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe]>`
+   --> /home/bjorn/Documenten/rust2/src/libstd/panic.rs:361:9
+    |
+361 |         panicking::try(f)
+    |         ^^^^^^^^^^^^^^^^^
+note: inside call to `std::panic::catch_unwind::<[closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
+   --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:58:25
+    |
+58  |           let exit_code = panic::catch_unwind(|| {
+    |  _________________________^
+59  | |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
+60  | |         });
+    | |__________^
+note: inside call to `std::rt::lang_start_internal`
+   --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:74:5
+    |
+74  |     lang_start_internal(&move || main().report(), argc, argv)
+    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.
+

The actual stderr differed from the expected stderr.
Actual stderr saved to /tmp/compiletest.H6HYTdQhAgsq/zero-sized-binary-heap-push.stderr
To update references, run this command from build directory:
tests/run-pass/update-references.sh '/tmp/compiletest.H6HYTdQhAgsq' 'zero-sized-binary-heap-push.rs'

error: 1 errors occurred comparing output.
status: exit code: 101
command: "target/debug/miri" "tests/run-pass/zero-sized-binary-heap-push.rs" "-L" "/tmp/compiletest.H6HYTdQhAgsq" "--target=x86_64-unknown-linux-gnu" "-C" "prefer-dynamic" "-o" "/tmp/compiletest.H6HYTdQhAgsq/zero-sized-binary-heap-push.stage-id" "-Zmir-opt-level=0" "-Zmir-emit-validate=1" "-L" "/tmp/compiletest.H6HYTdQhAgsq/zero-sized-binary-heap-push.stage-id.aux" "-A" "unused"
stdout:
------------------------------------------

------------------------------------------
stderr:
------------------------------------------
error[E0080]: constant evaluation error
   --> /home/bjorn/Documenten/rust2/src/libcore/ptr.rs:364:42
    |
364 |     intrinsics::move_val_init(&mut *dst, src)
    |                                          ^^^ a memory access tried to interpret some bytes as a pointer
    |
note: inside call to `std::ptr::write::<()>`
   --> /home/bjorn/Documenten/rust2/src/liballoc/vec.rs:1063:13
    |
1063|             ptr::write(end, value);
    |             ^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `<std::vec::Vec<T>><()>::push`
   --> /home/bjorn/Documenten/rust2/src/liballoc/binary_heap.rs:582:9
    |
582 |         self.data.push(item);
    |         ^^^^^^^^^^^^^^^^^^^^
note: inside call to `<std::collections::BinaryHeap<T>><()>::push`
   --> tests/run-pass/zero-sized-binary-heap-push.rs:22:13
    |
22  |             tester.push(());
    |             ^^^^^^^^^^^^^^^
note: inside call to `main`
   --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:74:34
    |
74  |     lang_start_internal(&move || main().report(), argc, argv)
    |                                  ^^^^^^
note: inside call to `closure`
   --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:59:75
    |
59  |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
    |                                                                           ^^^^^^
note: inside call to `closure`
   --> /home/bjorn/Documenten/rust2/src/libstd/sys_common/backtrace.rs:136:5
    |
136 |     f()
    |     ^^^
note: inside call to `std::sys_common::backtrace::__rust_begin_short_backtrace::<[closure@DefId(1/1:1802 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]::{{closure}}[0]) 0:&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
   --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:59:13
    |
59  |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `closure`
   --> /home/bjorn/Documenten/rust2/src/libstd/panicking.rs:306:40
    |
306 |             ptr::write(&mut (*data).r, f());
    |                                        ^^^
note: inside call to `std::panicking::try::do_call::<[closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
   --> /home/bjorn/Documenten/rust2/src/libstd/panicking.rs:302:5
    |
302 | /     fn do_call<F: FnOnce() -> R, R>(data: *mut u8) {
303 | |         unsafe {
304 | |             let data = data as *mut Data<F, R>;
305 | |             let f = ptr::read(&mut (*data).f);
306 | |             ptr::write(&mut (*data).r, f());
307 | |         }
308 | |     }
    | |_____^
note: inside call to `std::panicking::try::<i32, [closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe]>`
   --> /home/bjorn/Documenten/rust2/src/libstd/panic.rs:361:9
    |
361 |         panicking::try(f)
    |         ^^^^^^^^^^^^^^^^^
note: inside call to `std::panic::catch_unwind::<[closure@DefId(1/1:1801 ~ std[a0b6]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>`
   --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:58:25
    |
58  |           let exit_code = panic::catch_unwind(|| {
    |  _________________________^
59  | |             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
60  | |         });
    | |__________^
note: inside call to `std::rt::lang_start_internal`
   --> /home/bjorn/Documenten/rust2/src/libstd/rt.rs:74:5
    |
74  |     lang_start_internal(&move || main().report(), argc, argv)
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.

------------------------------------------

thread '[ui] run-pass/zero-sized-binary-heap-push.rs' panicked at 'explicit panic', /home/bjorn/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/compiletest_rs-0.3.8/src/runtest.rs:2539:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: std::panicking::rust_panic_with_hook
   5: std::panicking::begin_panic
             at /home/bjorn/Documenten/rust2/src/libstd/panicking.rs:365
   6: compiletest_rs::runtest::ProcRes::fatal
             at /home/bjorn/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/compiletest_rs-0.3.8/src/runtest.rs:2539
   7: compiletest_rs::runtest::TestCx::fatal_proc_rec
             at /home/bjorn/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/compiletest_rs-0.3.8/src/runtest.rs:1639
   8: compiletest_rs::runtest::TestCx::run_ui_test
             at /home/bjorn/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/compiletest_rs-0.3.8/src/runtest.rs:2238
   9: compiletest_rs::runtest::TestCx::run_revision
             at /home/bjorn/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/compiletest_rs-0.3.8/src/runtest.rs:140
  10: compiletest_rs::runtest::run
             at /home/bjorn/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/compiletest_rs-0.3.8/src/runtest.rs:80
  11: compiletest_rs::make_test_closure::{{closure}}
             at /home/bjorn/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/compiletest_rs-0.3.8/src/lib.rs:275
  12: <F as alloc::boxed::FnBox<A>>::call_box
             at /home/bjorn/Documenten/rust2/src/liballoc/boxed.rs:783
  13: <F as alloc::boxed::FnBox<A>>::call_box
  14: __rust_maybe_catch_panic


failures:
    [ui] run-pass/issue-15523-big.rs
    [ui] run-pass/zero-sized-binary-heap-push.rs

test result: FAILED. 127 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out

Compile-fail tests all fail, because of changed error format.

Edit: updated for last commit (only two tests failing, one invalid discriminant for enum with niche filling (Option<cmp::Ordering>) and one with a zst)

miri/lib.rs Outdated
// ------------------------------------------------------------
// ||||||||||||| TODO: remove this horrible hack ||||||||||||||
// ------------------------------------------------------------
unsafe { &mut *(frame as *const Frame as *mut Frame) }.storage_dead(local);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: remove this!

Copy link
Member

@RalfJung RalfJung Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, this is an & to &mut cast, right? This is UB. You might as well deref a dangling pointer here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, that is why I want to remove it.

miri/lib.rs Outdated
let call_stackframe = ecx.stack().len();
while ecx.step()? && ecx.stack().len() >= call_stackframe {
if ecx.stack().len() == call_stackframe {
let frame = ecx.stack().last().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is frame_mut still public? if so, you can use that, otherwise, make it public in rustc

@@ -558,6 +560,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator<'
TyAdt(adt, _) if adt.is_box() => true,
TySlice(_) | TyAdt(_, _) | TyTuple(..) | TyClosure(..) | TyArray(..) |
TyDynamic(..) | TyGenerator(..) | TyForeign(_) => false,
TyGeneratorWitness(..) => bug!("I'm not sure what to return here"),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should I return here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is reachable, so just throw an unreachable!() invocation there for now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable.

@bjorn3
Copy link
Member Author

bjorn3 commented Apr 7, 2018

A list of upstream TODO's:

  • make EvalContext::write_discriminant_value public (#49758)

@oli-obk
Copy link
Contributor

oli-obk commented Apr 13, 2018

@bjorn3 thank's for your awesome work! I have rebased and sqashed some commits into the rustup branch on this repo and opened rust-lang/rust#49933 to apply the necessary fixes to the compiler

@oli-obk oli-obk closed this Apr 13, 2018
@bjorn3 bjorn3 deleted the rustup branch April 14, 2018 10:58
@bjorn3 bjorn3 restored the rustup branch April 15, 2018 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants