Skip to content

Miri finds aliasing rules violation #20

@purplesyringa

Description

@purplesyringa

This crate does exactly what I'm looking for, but alas...

$ cargo miri test lockmap::tests
running 10 tests
test lockmap::tests::test_lockmap_get_set ...
error: Undefined Behavior: trying to retag from <298302> for Unique permission at alloc136154[0x0], but that tag does not exist in the borrow stack for this location
    --> src/lockmap.rs:524:30
     |
 524 |         let state = unsafe { &mut *ptr };
     |                              ^^^^^^^^^ this error occurs as part of retag at alloc136154[0x0..0x10]
     |
     = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows 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
help: <298302> was created by a SharedReadWrite retag at offsets [0x0..0x10]
    --> src/lockmap.rs:126:27
     |
 126 |                 let ptr = state.as_mut() as _;
     |                           ^^^^^^^^^^^^^^
help: <298302> was later invalidated at offsets [0x0..0x10] by a Unique retag
    --> src/lockmap.rs:127:40
     |
 127 |                 (UpdateAction::Replace(state), ptr)
     |                                        ^^^^^
     = note: BACKTRACE (of the first span) on thread `unnamed-2`:
     = note: inside `lockmap::LockMap::<u32, u32>::guard_by_val` at src/lockmap.rs:524:30: 524:39
note: inside `lockmap::LockMap::<u32, u32>::entry`
    --> src/lockmap.rs:131:9
     |
 131 |         self.guard_by_val(ptr, key)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure
    --> src/lockmap.rs:1017:37
     |
1017 |                     let mut entry = lock_map.entry(key);
     |                                     ^^^^^^^^^^^^^^^^^^^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error

error: test failed, to rerun pass `--lib`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions