Stream: t-compiler

Topic: #58684 illegal instruction via uninitialized in thread local


pnkfelix (Mar 05 2019 at 13:02, on Zulip):

hey @oli , would you agree that at this point, this is either not-a-bug or a T-libs issue?

oli (Mar 05 2019 at 13:04, on Zulip):

I commented on the issue, but yes, not-a-bug, someone misused mem::uninitialized

oli (Mar 05 2019 at 13:06, on Zulip):

Basically using mem::uninitialized is UB unless your type has a valid value for all bits patterns, and even then it's questionable

pnkfelix (Mar 05 2019 at 13:07, on Zulip):

okay, in this case I think the mem::uninitialized originates from the arraydeque crate

pnkfelix (Mar 05 2019 at 13:18, on Zulip):

Luckily this is trivial to demo, so I can file a bug with the arraydeque crate itself:

let tester: ArrayDeque<[Box<()>; 100], Wrapping> = ArrayDeque::new();
assert!(Some(tester).is_some());
pnkfelix (Mar 05 2019 at 13:28, on Zulip):

@nagisa , just to be clear, your comment is just meant to reenforce the statement that this is not a bug in rustc nor libstd, but rather a misuse of mem::uninitialized, right?

nagisa (Mar 05 2019 at 13:29, on Zulip):

Yes. ManuallyDrop::<T>::new(uninitialized())is invalid for most/all T.

nagisa (Mar 05 2019 at 13:30, on Zulip):

If let x: T = uninitialized() is wrong, then let x: ManuallyDrop<T> = uninitialized or let x = ManuallyDrop::<T>::from(uninitialized()) is also wrong.

pnkfelix (Mar 05 2019 at 13:30, on Zulip):

okay thanks. I was actually trying to remember the name of MaybeUninit (and I was definitely staring at ManuallyDrop trying to remember it), so your comment was certainly appreciated.

pnkfelix (Mar 05 2019 at 13:31, on Zulip):

Yes. ManuallyDrop::<T>::new(uninitialized())is invalid for most/all T.

Hmm. I would at least think that if uninitialized is valid for T, then it is also valid for ManuallyDrop::<T>, no?

pnkfelix (Mar 05 2019 at 13:31, on Zulip):

or wait, is there something I'm overlooking with drop flag initialization?

pnkfelix (Mar 05 2019 at 13:31, on Zulip):

/me thinks

nagisa (Mar 05 2019 at 13:32, on Zulip):

most is the right thing

nagisa (Mar 05 2019 at 13:32, on Zulip):

if let x: T = uninitialized() is valid, then it is also valid to construct ManuallyDrop of the same, or use that x in general

pnkfelix (Mar 05 2019 at 13:32, on Zulip):

okay. I think that answers that question.

Last update: Nov 16 2019 at 01:10UTC