-
Notifications
You must be signed in to change notification settings - Fork 61
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
Miri UB with -Zmiri-track-raw-pointers #108
Comments
I believe this is rust-lang/unsafe-code-guidelines#134 / rust-lang/unsafe-code-guidelines#256 / rust-lang/unsafe-code-guidelines#276. The short version is that Taking a glance at the code, though, there are definitely a number of places that need to use EDIT: the only computer I have access to at the moment can't run |
109: Use some ptr::addr_of_mut for taking ptr addr r=lnicola a=CAD97 Relevant to #108, but I'm not certain if it addresses the miri failure or not. (Can't check because of rust-lang/miri#705.) Either way, this is a positive change, as previously we were creating `&mut` to uninitialized memory locations. Co-authored-by: Durham, Christopher <[email protected]>
I got another Stacked Borrows violation with use rowan::{GreenNodeBuilder, SyntaxKind};
fn main() {
let mut builder = GreenNodeBuilder::new();
builder.start_node(SyntaxKind(0));
builder.token(SyntaxKind(1), "foo");
builder.finish_node(); // added this line
} In this case, the UB occurs inside backtrace$ MIRIFLAGS='-Zmiri-track-raw-pointers' cargo +nightly miri run
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `/home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri target/miri/x86_64-unknown-linux-gnu/debug/rowan-miri`
error: Undefined Behavior: trying to reborrow for SharedReadOnly at alloc1879+0x18, but parent tag <6966> does not have an appropriate item in the borrow stack
--> /home/pan/.cargo/registry/src/github.com-1ecc6299db9ec823/rowan-0.13.0-pre.8/src/arc.rs:264:13
|
264 | &*(fake_slice as *const HeaderSlice<H, [T]>)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trying to reborrow for SharedReadOnly at alloc1879+0x18, but parent tag <6966> does not have an appropriate item in the borrow stack
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
= note: inside `<rowan::arc::HeaderSlice<rowan::green::token::GreenTokenHead, [u8; 0]> as std::ops::Deref>::deref` at /home/pan/.cargo/registry/src/github.com-1ecc6299db9ec823/rowan-0.13.0-pre.8/src/arc.rs:264:13
= note: inside `rowan::GreenTokenData::text` at /home/pan/.cargo/registry/src/github.com-1ecc6299db9ec823/rowan-0.13.0-pre.8/src/green/token.rs:101:48
= note: inside `rowan::GreenTokenData::text_len` at /home/pan/.cargo/registry/src/github.com-1ecc6299db9ec823/rowan-0.13.0-pre.8/src/green/token.rs:107:22
= note: inside `rowan::green::element::<impl rowan::NodeOrToken<&rowan::GreenNodeData, &rowan::GreenTokenData>>::text_len` at /home/pan/.cargo/registry/src/github.com-1ecc6299db9ec823/rowan-0.13.0-pre.8/src/green/element.rs:86:39
= note: inside `rowan::green::element::<impl rowan::NodeOrToken<rowan::GreenNode, rowan::GreenToken>>::text_len` at /home/pan/.cargo/registry/src/github.com-1ecc6299db9ec823/rowan-0.13.0-pre.8/src/green/element.rs:67:9
= note: inside closure at /home/pan/.cargo/registry/src/github.com-1ecc6299db9ec823/rowan-0.13.0-pre.8/src/green/node.rs:216:25
= note: inside `std::ops::function::impls::<impl std::ops::FnOnce<(rowan::NodeOrToken<rowan::GreenNode, rowan::GreenToken>,)> for &mut [closure@rowan::GreenNode::new<std::iter::Map<std::vec::Drain<(u64, rowan::NodeOrToken<rowan::GreenNode, rowan::GreenToken>)>, [closure@rowan::green::builder::NodeCache::node::{closure#0}::{closure#0}]>>::{closure#0}]>::call_once` at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:280:13
= note: inside `std::option::Option::<rowan::NodeOrToken<rowan::GreenNode, rowan::GreenToken>>::map::<rowan::green::node::GreenChild, &mut [closure@rowan::GreenNode::new<std::iter::Map<std::vec::Drain<(u64, rowan::NodeOrToken<rowan::GreenNode, rowan::GreenToken>)>, [closure@rowan::green::builder::NodeCache::node::{closure#0}::{closure#0}]>>::{closure#0}]>` at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:823:29
= note: inside `<std::iter::Map<std::iter::Map<std::vec::Drain<(u64, rowan::NodeOrToken<rowan::GreenNode, rowan::GreenToken>)>, [closure@rowan::green::builder::NodeCache::node::{closure#0}::{closure#0}]>, [closure@rowan::GreenNode::new<std::iter::Map<std::vec::Drain<(u64, rowan::NodeOrToken<rowan::GreenNode, rowan::GreenToken>)>, [closure@rowan::green::builder::NodeCache::node::{closure#0}::{closure#0}]>>::{closure#0}]> as std::iter::Iterator>::next` at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/adapters/map.rs:101:9
= note: inside `rowan::arc::ThinArc::<rowan::green::node::GreenNodeHead, rowan::green::node::GreenChild>::from_header_and_iter::<std::iter::Map<std::iter::Map<std::vec::Drain<(u64, rowan::NodeOrToken<rowan::GreenNode, rowan::GreenToken>)>, [closure@rowan::green::builder::NodeCache::node::{closure#0}::{closure#0}]>, [closure@rowan::GreenNode::new<std::iter::Map<std::vec::Drain<(u64, rowan::NodeOrToken<rowan::GreenNode, rowan::GreenToken>)>, [closure@rowan::green::builder::NodeCache::node::{closure#0}::{closure#0}]>>::{closure#0}]>>` at /home/pan/.cargo/registry/src/github.com-1ecc6299db9ec823/rowan-0.13.0-pre.8/src/arc.rs:384:25
= note: inside `rowan::GreenNode::new::<std::iter::Map<std::vec::Drain<(u64, rowan::NodeOrToken<rowan::GreenNode, rowan::GreenToken>)>, [closure@rowan::green::builder::NodeCache::node::{closure#0}::{closure#0}]>>` at /home/pan/.cargo/registry/src/github.com-1ecc6299db9ec823/rowan-0.13.0-pre.8/src/green/node.rs:223:20
= note: inside closure at /home/pan/.cargo/registry/src/github.com-1ecc6299db9ec823/rowan-0.13.0-pre.8/src/green/builder.rs:28:13
= note: inside `rowan::green::builder::NodeCache::node` at /home/pan/.cargo/registry/src/github.com-1ecc6299db9ec823/rowan-0.13.0-pre.8/src/green/builder.rs:69:28
= note: inside `rowan::GreenNodeBuilder::finish_node` at /home/pan/.cargo/registry/src/github.com-1ecc6299db9ec823/rowan-0.13.0-pre.8/src/green/builder.rs:149:28
note: inside `main` at src/main.rs:7:5
--> src/main.rs:7:5
|
7 | builder.finish_node();
| ^^^^^^^^^^^^^^^^^^^^^
= note: inside `<fn() as std::ops::FnOnce<()>>::call_once - shim(fn())` at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
= note: inside `std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>` at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys_common/backtrace.rs:125:18
= note: inside closure at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:63:18
= note: inside `std::ops::function::impls::<impl std::ops::FnOnce<()> for &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>::call_once` at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:259:13
= note: inside `std::panicking::r#try::do_call::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>` at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:401:40
= note: inside `std::panicking::r#try::<i32, &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>` at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:365:19
= note: inside `std::panic::catch_unwind::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>` at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:434:14
= note: inside closure at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:45:48
= note: inside `std::panicking::r#try::do_call::<[closure@std::rt::lang_start_internal::{closure#2}], isize>` at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:401:40
= note: inside `std::panicking::r#try::<isize, [closure@std::rt::lang_start_internal::{closure#2}]>` at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:365:19
= note: inside `std::panic::catch_unwind::<[closure@std::rt::lang_start_internal::{closure#2}], isize>` at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:434:14
= note: inside `std::rt::lang_start_internal` at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:45:20
= note: inside `std::rt::lang_start::<()>` at /home/pan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:62:5
error: aborting due to previous error |
Yikes, this reliance on There are two approaches I see towards getting rowan to work under miri again:
|
Hi! I got UB when running Miri with raw pointer tracking enabled (
-Zmiri-track-raw-pointers
) against the invocation ofGreenNodeBuilder::token
. The UB is not reported when running Miri without raw pointer tracking.To reproduce the UB, run the following function with
MIRIFLAGS='-Zmiri-track-raw-pointers' cargo +nightly miri run
.Here is the backtrace:
It looks like Miri is not satisfied with
ThinArc
construction.The text was updated successfully, but these errors were encountered: