-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Hi! I came across your crate on crates.io because I wanted to do something similar to UnsafeAliasCell
and I was curious about how others might solve the same issue :) I may have spotted a potential soundness issue in your approach, which I wanted to let you know about.
Currently the implementation of UnsafeAliasCell
relies on it being !Unpin
in order for LLVM to omit the noalias
attribute:
As far as I understand, rustc and miri currently do this as an implementation detail to work-around a known soundness issue with self-referential structs (e.g. async generators), but it is not a stable API guarantee to the outside world. This means that at some point in the future, Rust may start to emit noalias
again for types that are !Unpin
and then current users of this crate will have a soundness bug in them retroactively. I was warned of the same danger some time ago (relevant Zulip thread).
We were chatting on Zulip about something similar very recently, in case it helps for additional inspiration on how to work-around this soundness issue. Although I'm not sure if there exists a proper one-size-fits-all solution yet without additional support from the standard library. You might be able to partially leverage the MaybeUninit<T>
type to strip the noalias
attribute from pointees T
(pointees T
as in e.g. Box<T>
and &mut T
, where we distinguish between the pointer and pointee parts of the type), but a big downside is that it also strips a lot of other useful LLVM attributes as well. I'm not sure if this would work for regular struct fields like i32
or the pointers themselves. I hope this feedback is useful and might help prevent some UB :)