Stream: t-lang/wg-unsafe-code-guidelines

Topic: MIRI false positive in hecs?


Benjamin Saunders (Dec 14 2019 at 23:31, on Zulip):

I have some code which copies values into/out of unaligned memory, but isn't doing much else funny before MIRI throws a fit: "trying to reborrow for SharedReadOnly, but parent tag <143201> does not have an appropriate item in the borrow stack". Full code/output here: https://github.com/Ralith/hecs/pull/4/checks?check_run_id=348893958. Am I missing some UB here?

comex (Dec 14 2019 at 23:55, on Zulip):

If possible you should try to come up with a self-contained playground test case.

comex (Dec 14 2019 at 23:56, on Zulip):

(though it would be nice if miri could explain its errors better)

comex (Dec 15 2019 at 00:07, on Zulip):

I think basically, miri does not like when you index into an array, and then take that pointer and go out of bounds of the array element: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=21d5640dfcba3c293c6889cb0ddfe137

comex (Dec 15 2019 at 00:07, on Zulip):

Probably, instead of self.storage[self.cursor].as_mut_ptr(), you want self.storage.as_mut_ptr().offset(self.cursor)

comex (Dec 15 2019 at 00:08, on Zulip):

I'm not sure what the rules around this are supposed to be, though

comex (Dec 15 2019 at 00:08, on Zulip):

@RalfJ

Benjamin Saunders (Dec 15 2019 at 03:33, on Zulip):

no way to run miri on the playground, is there? miri doesn't work at all on my system (https://github.com/mozilla/nixpkgs-mozilla/issues/198) so it's difficult for me to refine

comex (Dec 15 2019 at 03:50, on Zulip):

@Benjamin Saunders It's in the right menu under "tools" (no idea why it's there)

Benjamin Saunders (Dec 15 2019 at 03:51, on Zulip):

ahah, thanks, that'll be a big help! and the indexing indeed seems to have been the key

RalfJ (Dec 22 2019 at 15:05, on Zulip):

no way to run miri on the playground, is there? miri doesn't work at all on my system (https://github.com/mozilla/nixpkgs-mozilla/issues/198) so it's difficult for me to refine

thanks for pointing me to that, I had no idea Miri's sysroot detection is in conflict with nix's overlays. Would be good to find a way to fix that.

RalfJ (Dec 22 2019 at 15:06, on Zulip):

regarding the original issue, I agree with what @comex said -- when you get a pointer to an array element that's a pointer to that element only, not usable for its neighbors.

Last update: Jun 04 2020 at 18:05UTC