-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Fix ICE on offsetted ZST pointer #147576
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 on offsetted ZST pointer #147576
Conversation
Some changes occurred in compiler/rustc_codegen_gcc Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
r? @nnethercote rustbot has assigned @nnethercote. Use |
This comment has been minimized.
This comment has been minimized.
060e453
to
7a513dd
Compare
@bors r=nnethercote |
…nnethercote Fix ICE on offsetted ZST pointer I'm not sure this is the *right* fix, but it's simple enough and does roughly what I'd expect. Like with the previous optimization to codegen usize rather than a zero-sized static, there's no guarantee that we continue returning a particular value from the offsetting. A grep for `const_usize.*align` found the same code copied to rustc_codegen_gcc and cranelift but a quick skim didn't find other cases of similar 'optimization'. That said, I'm not convinced I caught everything, it's not trivial to search for this. Closes rust-lang#147516
Rollup of 7 pull requests Successful merges: - #147168 (Don't unconditionally build alloc for `no-std` targets) - #147178 ([DebugInfo] Improve formatting of MSVC enum struct variants) - #147495 (Update wasm-component-ld to 0.5.18) - #147576 (Fix ICE on offsetted ZST pointer) - #147592 (Add tidy to the target of ./x check) - #147597 (Add a regression test for #72207) - #147604 (Some clippy cleanups in compiler) r? `@ghost` `@rustbot` modify labels: rollup
7a513dd
to
d58c744
Compare
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
@bors try jobs=dist-i586-gnu-i586-i686-musl |
This comment has been minimized.
This comment has been minimized.
Fix ICE on offsetted ZST pointer try-job: dist-i586-gnu-i586-i686-musl
This comment has been minimized.
This comment has been minimized.
d58c744
to
b27c4ef
Compare
tests/ui/consts/zst_no_llvm_alloc.rs
Outdated
|
||
// This tests for regression of https://github.com/rust-lang/rust/issues/147516 | ||
// | ||
// THe compiler will codegen `&Zst` without creating a real allocation, just a properly aligned |
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 compiler will codegen `&Zst` without creating a real allocation, just a properly aligned | |
// The compiler will codegen `&Zst` without creating a real allocation, just a properly aligned |
A grep for `const_usize.*align` found the same code copied to rustc_codegen_gcc but I don't see other cases where we get this wrong.
b27c4ef
to
a8c79b8
Compare
@bors r=nnethercote,RalfJung |
Rollup of 9 pull requests Successful merges: - #144438 (Guard HIR lowered contracts with `contract_checks`) - #147000 (std: Add Motor OS std library port) - #147576 (Fix ICE on offsetted ZST pointer) - #147732 (remove duplicate inline macro) - #147738 (Don't highlight `let` expressions as having type `bool` in let-chain error messages) - #147744 (miri subtree update) - #147751 (Use `bit_set::Word` in a couple more places.) - #147752 (style-guide: fix typo for empty struct advice) - #147773 (`is_ascii` on an empty string or slice returns true) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #147576 - Mark-Simulacrum:fix-offset-zst, r=nnethercote,RalfJung Fix ICE on offsetted ZST pointer I'm not sure this is the *right* fix, but it's simple enough and does roughly what I'd expect. Like with the previous optimization to codegen usize rather than a zero-sized static, there's no guarantee that we continue returning a particular value from the offsetting. A grep for `const_usize.*align` found the same code copied to rustc_codegen_gcc and cranelift but a quick skim didn't find other cases of similar 'optimization'. That said, I'm not convinced I caught everything, it's not trivial to search for this. Closes #147516
assert_eq!(offset, Size::ZERO); | ||
fx.bcx.ins().iconst(fx.pointer_type, alloc.inner().align.bytes() as i64) | ||
let val = alloc.inner().align.bytes().wrapping_add(offset.bytes()); | ||
fx.bcx.ins().iconst( | ||
fx.pointer_type, | ||
fx.tcx.truncate_to_target_usize(val) as i64, | ||
) |
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 proper fix would have been to remove the assert_eq!()
here and to do the truncate_to_target_usize
at the fx.bcx.ins().iadd_imm(base_addr, i64::try_from(offset.bytes()).unwrap())
below. As is this still ICEs. Will push a fix to the cg_clif repo.
Edit: rust-lang/rustc_codegen_cranelift@ca23203
I'm not sure this is the right fix, but it's simple enough and does roughly what I'd expect. Like with the previous optimization to codegen usize rather than a zero-sized static, there's no guarantee that we continue returning a particular value from the offsetting.
A grep for
const_usize.*align
found the same code copied to rustc_codegen_gcc and cranelift but a quick skim didn't find other cases of similar 'optimization'. That said, I'm not convinced I caught everything, it's not trivial to search for this.Closes #147516