-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ICE mutable allocation in constant ui/associated-type-bounds/union-bounds.rs with -Zmir-opt-level=2 #68296
Comments
const FOO: *const u32 = { //~ ERROR any use of this value will cause an error
let x = 42;
&x
};
fn main() {
let x = FOO;
} |
While the original example no longer panics for me on |
Caused/Uncovered by the copy propagation pass |
It turns the constant into this, so probably the issue is that it removes the storage markers: // MIR for `FOO` after CopyPropagation
const FOO: *const u32 = {
let mut _0: *const u32; // return place in scope 0 at src/test/ui/consts/dangling_raw_ptr.rs:1:12: 1:22
let _1: u32; // in scope 0 at src/test/ui/consts/dangling_raw_ptr.rs:2:9: 2:10
let _2: &u32; // in scope 0 at src/test/ui/consts/dangling_raw_ptr.rs:3:5: 3:7
scope 1 {
debug x => _1; // in scope 1 at src/test/ui/consts/dangling_raw_ptr.rs:2:9: 2:10
}
bb0: {
nop; // bb0[0]: scope 0 at src/test/ui/consts/dangling_raw_ptr.rs:2:9: 2:10
_1 = const 42u32; // bb0[1]: scope 0 at src/test/ui/consts/dangling_raw_ptr.rs:2:13: 2:15
// ty::Const
// + ty: u32
// + val: Value(Scalar(0x0000002a))
// mir::Constant
// + span: src/test/ui/consts/dangling_raw_ptr.rs:2:13: 2:15
// + literal: Const { ty: u32, val: Value(Scalar(0x0000002a)) }
StorageLive(_2); // bb0[2]: scope 1 at src/test/ui/consts/dangling_raw_ptr.rs:3:5: 3:7
_2 = &_1; // bb0[3]: scope 1 at src/test/ui/consts/dangling_raw_ptr.rs:3:5: 3:7
_0 = &raw const (*_2); // bb0[4]: scope 1 at src/test/ui/consts/dangling_raw_ptr.rs:3:5: 3:7
nop; // bb0[5]: scope 0 at src/test/ui/consts/dangling_raw_ptr.rs:4:1: 4:2
StorageDead(_2); // bb0[6]: scope 0 at src/test/ui/consts/dangling_raw_ptr.rs:4:1: 4:2
return; // bb0[7]: scope 0 at src/test/ui/consts/dangling_raw_ptr.rs:1:1: 4:3
}
} (aside: the pass didn't actually optimize anything here, it just removed the markers, which is not very helpful) |
@matthiaskrgr const FOO: *const u32 = { //~ ERROR any use of this value will cause an error
let x = 42;
&x
};
fn main() {
let x = FOO;
} Just looks like wrong code to me, the pointer is dangling as it refers to a local that does out of scope. I don't see a bug. Since it seems like the example in the OP got fixed, could you describe expected and actual behavior with latest rustc to explain what the bug is that we are tracking here? Cc @rust-lang/wg-const-eval |
I think the ICE from this snippet (#68296 (comment)) has been fixed by #71665. |
Yeah that PR entirely removes the |
Can confirm that all the snippets mentioned no longer ICE with |
RUST_BACKTRACE=1 rustc ui/associated-type-bounds/union-bounds.rs -Zmir-opt-level=2
somewhat reduced:
rustc @ 9fe05e9
The text was updated successfully, but these errors were encountered: