Repository navigation
Dangling raw pointers in constants will ICE in codegen #55353
Description
Activity
Fix instructions:
The if in
rust/src/librustc_mir/interpret/validity.rs
Line 211 in 8ec22e7
| if !ty.is_unsafe_ptr() { |
In fact we can know one thing, and that is whether the raw pointer is dangling.
So, expand the condition to handle the ty.is_unsafe_ptr() case and call self.memory.get(place.ptr). If that results in an Ok, then we're good, but if you get an Err, it can essentially only mean that we got a dangling pointer. So you can call validation_failure! with an appropriate error.
Remember to also add a test in src/test/ui/consts to make sure that this doesn't ICE the compiler anymore.
Why do you want to validate raw pointers not to dangle? That seems wrong, they are allowed to.
I thought you had #55262 which would bail out during interning when it sees a dangling relocation. That didn't land yet, so I am not surprised we have this ICE.
cc @RalfJung
(Playground)
Errors: