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

Fix undefined behavior in Rc/Arc allocation #54922

Merged
merged 1 commit into from
Nov 6, 2018
Merged

Fix undefined behavior in Rc/Arc allocation #54922

merged 1 commit into from
Nov 6, 2018

Conversation

murarth
Copy link
Contributor

@murarth murarth commented Oct 9, 2018

Manually calculate allocation layout for Rc/Arc to avoid undefined behavior

Closes #54908

@rust-highfive

This comment has been minimized.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 9, 2018
@Centril
Copy link
Contributor

Centril commented Oct 9, 2018

r? @RalfJung

@rust-highfive rust-highfive assigned RalfJung and unassigned sfackler Oct 9, 2018
@RalfJung
Copy link
Member

RalfJung commented Oct 9, 2018

Could you add a comment saying why we do it this way and not the old way?

Other than that, I agree the alignment problem is gone. However, I do not know nearly enough about layouts to say if that's a correct way to compute these things. Assigning to someone who knows more (feel free to pick someone else).

r? @eddyb

@gnzlbg
Copy link
Contributor

gnzlbg commented Oct 10, 2018

cc @SimonSapin @Amanieu

@TimNN
Copy link
Contributor

TimNN commented Oct 23, 2018

Ping from triage! This PR requires your review @eddyb. Also this PR was references from rust-lang/unsafe-code-guidelines#35, is it blocked on that issue?

@eddyb
Copy link
Member

eddyb commented Nov 5, 2018

This is not a compiler layout, but I suspect it's correct.

r? @alexcrichton

@rust-highfive rust-highfive assigned alexcrichton and unassigned eddyb Nov 5, 2018
@alexcrichton
Copy link
Member

Thanks for the PR and sorry for the delay! This looks good to go to me with @RalfJung's comment

@alexcrichton
Copy link
Member

If possible, it'd also be great to have a regression test for this!

@RalfJung
Copy link
Member

RalfJung commented Nov 5, 2018

If possible, it'd also be great to have a regression test for this!

We'll have one in miri. I have no idea how to make one with rustc only.

Manually calculate allocation layout for `Rc`/`Arc` to avoid undefined behavior
@murarth
Copy link
Contributor Author

murarth commented Nov 5, 2018

I've added a more detailed comment and the tests have passed.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Nov 5, 2018

📌 Commit d60290f has been approved by alexcrichton

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 5, 2018
@bors
Copy link
Contributor

bors commented Nov 5, 2018

⌛ Testing commit d60290f with merge 65e485d...

bors added a commit that referenced this pull request Nov 5, 2018
Fix undefined behavior in Rc/Arc allocation

Manually calculate allocation layout for `Rc`/`Arc` to avoid undefined behavior

Closes #54908
@bors
Copy link
Contributor

bors commented Nov 6, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 65e485d to master...

@bors bors merged commit d60290f into rust-lang:master Nov 6, 2018
@murarth murarth deleted the rc-ub-fix branch November 6, 2018 02:23
@RalfJung
Copy link
Member

RalfJung commented Nov 7, 2018

Hm, this RFC made miri fail even if validation is turned off. Still investigating.

@RalfJung
Copy link
Member

RalfJung commented Nov 7, 2018

The error is that an allocation has size 32 but gets deallocated with size 28.

I assume the layout computations done here are incorrect.

@RalfJung
Copy link
Member

RalfJung commented Nov 7, 2018

Reported as #55747.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants