Skip to content

Commit

Permalink
Turn ICE for dangling pointers into error
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Oct 22, 2018
1 parent a66dc8a commit 9f0a352
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/librustc_mir/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,11 @@ where
if self.alloc_map.contains_key(&alloc) {
// Not yet interned, so proceed recursively
self.intern_static(alloc, mutability)?;
} else if self.dead_alloc_map.contains_key(&alloc) {
// danging pointer
return err!(ValidationFailure(
"encountered dangling pointer in final constant".into(),
))
}
}
Ok(())
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/consts/dangling-alloc-id-ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// https://github.com/rust-lang/rust/issues/55223

#![feature(const_let)]

union Foo<'a> {
y: &'a (),
long_live_the_unit: &'static (),
}

const FOO: &() = { //~ ERROR this constant cannot be used
let y = ();
unsafe { Foo { y: &y }.long_live_the_unit }
};

fn main() {}
13 changes: 13 additions & 0 deletions src/test/ui/consts/dangling-alloc-id-ice.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error: this constant cannot be used
--> $DIR/dangling-alloc-id-ice.rs:10:1
|
LL | / const FOO: &() = { //~ ERROR this constant cannot be used
LL | | let y = ();
LL | | unsafe { Foo { y: &y }.long_live_the_unit }
LL | | };
| |__^ type validation failed: encountered dangling pointer in final constant
|
= note: #[deny(const_err)] on by default

error: aborting due to previous error

0 comments on commit 9f0a352

Please sign in to comment.