You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Creating a raw reference/pointer to an extern never value claims following code is unreachable #74840
@oli-obk looks like creating a raw ptr to a static goes through a reference, with the new scheme? Also Cc @matthewjasper
FWIW I am not sure if this is really a bug; an explicitly uninhabited static seems at the very least highly suspicious to me. This is currently certainly not a blessed pattern. But the generated MIR is still odd.
The context in which I noticed it was an attempt by @repnop at using them to pass the heap start/end addresses from the linker to a Rust program (discord convo). It seemed like a somewhat correct way to encode a symbol that has a known address, but should not be readable.
I thought we had some more logic there a while back... oh well. We need an else if self.is_foreign_item(def_id) { self.mk_imm_ptr(static_ty) }... before the else, which should then give us exactly what we want
You can check this out by changing all your extern statics to be mutable, then you get the codegen you'd get with my suggested change above. Though the never type example still dies horribly, so there seems to be a bit more to the never type, even if there's never a reference to it.
The fix is described in #74840 (comment) where you'll end up with a raw pointer in that constant. But there's some additional messiness around never types, but without doing the fix first, I don't know what it is exactly.
Activity
Nemo157 commentedon Jul 27, 2020
To step it up a notch, I then tried giving
FOOan address pointing to data at least as valid as!(playground):I expected this to run and exit fine, since it is just printing the address of a symbol that definitely has an address.
Instead, it ran and then SIGILLed (after giving the same warnings as above):
RalfJung commentedon Jul 28, 2020
The relevant MIR looks like this:
@oli-obk looks like creating a raw ptr to a static goes through a reference, with the new scheme? Also Cc @matthewjasper
FWIW I am not sure if this is really a bug; an explicitly uninhabited static seems at the very least highly suspicious to me. This is currently certainly not a blessed pattern. But the generated MIR is still odd.
Nemo157 commentedon Jul 28, 2020
The context in which I noticed it was an attempt by @repnop at using them to pass the heap start/end addresses from the linker to a Rust program (discord convo). It seemed like a somewhat correct way to encode a symbol that has a known address, but should not be readable.
RalfJung commentedon Jul 28, 2020
I think an inhabited ZST like
()is a more appropriate way to encode that pattern. Also see the "opaque struct" section in the Nomicon.RalfJung commentedon Jul 29, 2020
Btw I think this should be merged with #74843; both are caused by the same odd MIR generation.
oli-obk commentedon Jul 29, 2020
We're computing the type of the "address of" constant of statics in
rust/src/librustc_mir_build/hair/cx/expr.rs
Line 839 in 06e7b93
rust/src/librustc_middle/ty/util.rs
Lines 543 to 552 in 39d5a61
I thought we had some more logic there a while back... oh well. We need an
else if self.is_foreign_item(def_id) { self.mk_imm_ptr(static_ty) }... before theelse, which should then give us exactly what we wantoli-obk commentedon Jul 29, 2020
You can check this out by changing all your extern statics to be mutable, then you get the codegen you'd get with my suggested change above. Though the never type example still dies horribly, so there seems to be a bit more to the never type, even if there's never a reference to it.
EDIT: I'm not sure what's causing this, but I'm guessing the deref projection for the reborrow, as just having a constant of raw pointer to never type doesn't cause any problems: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=fb80e957cebf8bf982ce50f914bd9236
RalfJung commentedon Aug 17, 2020
Yeah, the problem is here already:
We are embedding the const at reference type (note that
&!), which is wrong.Maybe @matthewjasper knows more about how/why this happens.
oli-obk commentedon Aug 17, 2020
The fix is described in #74840 (comment) where you'll end up with a raw pointer in that constant. But there's some additional messiness around never types, but without doing the fix first, I don't know what it is exactly.
55 remaining items
Bump `stacksafe` (zed-industries#62468)
[tui] Replace copypasta-ext with copypasta 0.10.2
[tui] Replace copypasta-ext with copypasta 0.10.2
feat: drive CGEventTap directly, dropping rdev and its unmaintained c…
fix(build): patch block 0.1.6 static rejected by future Rust
Error (#2)
fix: silence future-incompat warning from block 0.1.6
fix(deps): Patch block 0.1.6's static of an uninhabited type
fix(platform): 手写事件注入 FFI 退役 rdev (#178)
chore: remove vendor/ and the [patch.crates-io] overrides (#61)
refactor(harness): migrate smeltr-metal-harness from metal to objc2-m…
fix: vendor a block 0.1.6 fork to kill the future-incompat (issue 968)
fix: vendor the block 0.1.6 future-incompat fork (katgpt-rs issue 968…
chore(deps): move arboard 2 to 3.7.0, dropping block's future-incompa…
mercs2_workshop Cargo.toml: raise rfd to 0.17