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 ICE when using Box<T, A> with pointer sized A #94043

Merged
merged 2 commits into from
Feb 18, 2022

Conversation

beepster4096
Copy link
Contributor

Fixes #78459

Note that using Box<T, A> with a more than pointer sized A or using a pointer sized A with a Box of a DST will produce a different ICE (#92054) which is not fixed by this PR.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 16, 2022
@rust-highfive
Copy link
Collaborator

r? @wesleywiser

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 16, 2022
@@ -330,7 +330,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
ty::Ref(..) | ty::RawPtr(_) => {
return self.field(cx, index).llvm_type(cx);
}
ty::Adt(def, _) if def.is_box() => {
ty::Adt(def, substs) if def.is_box() && cx.layout_of(substs.type_at(1)).is_zst() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave a comment here stating that we only handle wide pointer boxes as pointers, not thin pointer boxes with a scalar allocator. That case is handled in the general logic below

@oli-obk
Copy link
Contributor

oli-obk commented Feb 17, 2022

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 17, 2022

📌 Commit d0b508e has been approved by oli-obk

@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 Feb 17, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 17, 2022
…askrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#93337 (Update tracking issue numbers for inline assembly sub-features)
 - rust-lang#93758 (Improve comments about type folding/visiting.)
 - rust-lang#93780 (Generate list instead of div items in sidebar)
 - rust-lang#93976 (Add MAIN_SEPARATOR_STR)
 - rust-lang#94011 (Even more let_else adoptions)
 - rust-lang#94041 (Add a `try_collect()` helper method to `Iterator`)
 - rust-lang#94043 (Fix ICE when using Box<T, A> with pointer sized A)
 - rust-lang#94082 (Remove CFG_PLATFORM)
 - rust-lang#94085 (Clippy: Don't lint `needless_borrow` in method receiver positions)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6dc62f4 into rust-lang:master Feb 18, 2022
@rustbot rustbot added this to the 1.60.0 milestone Feb 18, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 28, 2022
Fix ICE when using Box<T, A> with large A

A sequel to rust-lang#94043 that fixes rust-lang#81270 and rust-lang#92054 (duplicate).
ty::Adt(def, _) if def.is_box() => {
// only wide pointer boxes are handled as pointers
// thin pointer boxes with scalar allocators are handled by the general logic below
ty::Adt(def, substs) if def.is_box() && cx.layout_of(substs.type_at(1)).is_zst() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @antoyo I think cg_gcc needs the same fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like applying the same fix cause another issue.
Do you think there is the same issue for the LLVM codegen?
cc @drmeepster

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the problem is that in the mini_core test, Box doesn't have the allocator type parameter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fixed it in cg_clif in bjorn3/rustc_codegen_cranelift@401b034. Feel free to copy the changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, that doesn't solve the issue. I made changes more similar to liballoc itself, but got another ICE:

thread 'rustc' panicked at 'assertion failed: sig.c_variadic || extra_args.is_empty()', compiler/rustc_middle/src/ty/layout.rs:3027:13

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you change Box to include an extra field (eg ()) and change box_free to add an extra argument of the same type? They need to be in sync. I got the exact same error when I hadn't changed box_free yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.
What I meant is that I still get the error fixed by this PR with your changes:

thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', /rustc/4b043faba34ccc053a4d0110634c323f6c03765e/compiler/rustc_middle/src/ty/subst.rs:364:43

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see what you mean.
My own fixes miss the change you made to box_free.
Thanks. It works now!

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Mar 10, 2022
…eta, r=michaelwoerister

Only emit pointer-like metadata for `Box<T, A>` when `A` is ZST

Basically copy the change in rust-lang#94043, but for debuginfo.

r? `@michaelwoerister`

Fixes rust-lang#94725
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Mar 10, 2022
…eta, r=michaelwoerister

Only emit pointer-like metadata for `Box<T, A>` when `A` is ZST

Basically copy the change in rust-lang#94043, but for debuginfo.

r? ``@michaelwoerister``

Fixes rust-lang#94725
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 12, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 21, 2022
Remove dereferencing of Box from codegen

Through rust-lang#94043, rust-lang#94414, rust-lang#94873, and rust-lang#95328, I've been fixing issues caused by Box being treated like a pointer when it is not a pointer. However, these PRs just introduced special cases for Box. This PR removes those special cases and instead transforms a deref of Box into a deref of the pointer it contains.

Hopefully, this is the end of the Box<T, A> ICEs.
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE when using Box<T, A> with non-zero sized A
8 participants