Skip to content

Addresses are unintentionally aligned #791

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

Closed
pvdrz opened this issue Jun 25, 2019 · 4 comments · Fixed by #795
Closed

Addresses are unintentionally aligned #791

pvdrz opened this issue Jun 25, 2019 · 4 comments · Fixed by #795
Labels
A-intptrcast Area: affects int2ptr and ptr2int casts C-bug Category: This is a bug.

Comments

@pvdrz
Copy link
Contributor

pvdrz commented Jun 25, 2019

During the implementation of the intptrcast model we discovered that memory addresses are aligned even when miri::intptrcast::GlobalState::align_addr is not used.

Relevant code:

let x = (&5u8 as *const u8 as usize) * 2;
let y = (&6u16 as *const u16 as usize) * 2 / 2;
assert!(y % 2 == 1);
@RalfJung
Copy link
Member

% should also cause force_bits, so you shouldn't need the * 2 stuff.

But also it is impossible to entirely avoid this. So maybe we should keep the "no int base addresses" mode... or have a mode where the base address is only used for ptr comparison, not anything else? That seems neat actually.

@oli-obk
Copy link
Contributor

oli-obk commented Jun 26, 2019

wait how is assert!(x % 2 == 1); passing if its value was multiplied by 2 before?

@pvdrz
Copy link
Contributor Author

pvdrz commented Jun 26, 2019

wait how is assert!(x % 2 == 1); passing if its value was multiplied by 2 before?

Oh I should had left a comment/remove it. I left it when I copied and pasted just after finishing doodling with it.

@pvdrz
Copy link
Contributor Author

pvdrz commented Jun 26, 2019

Adding @oli-obk's comment: We should stop wasting align bytes if we were already aligned
Edit: Solved in #795

@RalfJung RalfJung added A-intptrcast Area: affects int2ptr and ptr2int casts C-bug Category: This is a bug. labels Jun 28, 2019
bors added a commit that referenced this issue Jun 29, 2019
tweak inttoptr allocation behavior

- Make `align_addr` not offset by `align` for no reason.
- Add some random slack between allocations to give them the chance to not be aligned.

Cc @christianpoveda

Fixes #791
@bors bors closed this as completed in #795 Jun 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intptrcast Area: affects int2ptr and ptr2int casts C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants