Skip to content
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

stable addresses for local variables, etc #15

Open
nikomatsakis opened this issue Aug 30, 2018 · 0 comments
Open

stable addresses for local variables, etc #15

nikomatsakis opened this issue Aug 30, 2018 · 0 comments
Labels
A-stable-address Topic: Related to stable addresses S-pending-design Status: Resolving this issue requires addressing some open design questions

Comments

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Aug 30, 2018

When do we guarantee "stable" addresses? (Meaning that the integral value of a pointer remains the same). Note that addresses are visible to safe code via as conversions.

Some examples:

Local variables

let x = 22;
{ let y = &x; .. }
...
{ let z = &x; .. }

Are the integral values of y and z guaranteed to be equal? It might be useful if they were not, since a compiler could keep x in a register and spill it to memory in different spots on the stack.


Assuming the answer to this question is "yes", are locals still guaranteed to have a stable address when they are reallocated using StorageDead / StorageLive? For example:

let x = 22;
let y = &x as *const _ as usize;
x = 33;
let z = &x as *const _ as usize;
assert_eq!(y, z); // is this true?

Or:

let mut prev = None;
loop {
  let x = 22;
  let y = &x as *const _ as usize;
  if let Some(z) = prev {
    assert_eq!(y, z); // is this true?
  }
  prev = Some(y);
}

Edit by @digama0: moved question about const address stability to #406 , clarified question on killed locals

@RalfJung RalfJung added the A-stable-address Topic: Related to stable addresses label Aug 14, 2019
@JakobDegen JakobDegen added S-pending-design Status: Resolving this issue requires addressing some open design questions and removed C-discussion-topic labels May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stable-address Topic: Related to stable addresses S-pending-design Status: Resolving this issue requires addressing some open design questions
Projects
None yet
Development

No branches or pull requests

3 participants