-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Kill the storage for all locals on returning terminators #46100
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// revisions: ast mir | ||
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need the emit-end-regions flag any more btw, thanks to this very nice PR: #44717. My PR #46106 is removing them everywhere but I guess I should start spreading the word so that the line doesn't keep getting added :p. The comment applies to the other places where you have -Z emit-end-regions as well, but I won't comment on each of them. |
||
|
||
fn cplusplus_mode(x: isize) -> &'static isize { | ||
&x //[ast]~ ERROR `x` does not live long enough | ||
//[mir]~^ ERROR `x` does not live long enough (Ast) | ||
//[mir]~| ERROR borrowed value does not live long enough (Mir) | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// revisions: ast mir | ||
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir | ||
|
||
#![feature(thread_local)] | ||
|
||
#[thread_local] | ||
static FOO: u8 = 3; | ||
|
||
fn assert_static(_t: &'static u8) {} | ||
fn main() { | ||
assert_static(&FOO); //[ast]~ ERROR [E0597] | ||
//[mir]~^ ERROR (Ast) [E0597] | ||
//[mir]~| ERROR (Mir) [E0597] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
// error-pattern:panic 1 | ||
|
||
// revisions: ast mir | ||
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir | ||
|
||
fn main() { | ||
let x = 2; | ||
let y = &x; | ||
panic!("panic 1"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add the test that @arielb1 added to the issue and check that it generates two errors (one for each function) -- both in AST and MIR mode? A quick test with play seems to suggest that it does not generate two errors today, but it'd be good to verify that your test is not working before your patch, and works after while you are at it. fn cplusplus_mode(x: isize) -> &'static isize { &x }
fn cplusplus_mode_exceptionally_unsafe(x: &mut Option<&'static mut isize>) {
let z = 0;
*x = Some(&mut z);
panic!("catch me for a dangling pointer!")
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other thing I'm not sure about is whether this should be a shallow write instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a drop - basically a shallow write for structs without a destructor, and a deep write for structs with one.
This is because you want to avoid the likes of #31567 while still permitting borrowing the interior of types such as
&mut
references, as in:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah so this code only runs for thread-locals. In that case, I suppose there won't be much harm from it remaining a deep write.