Skip to content

Conversation

Mark-Simulacrum
Copy link
Member

@Mark-Simulacrum Mark-Simulacrum commented Oct 11, 2025

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

@rustbot
Copy link
Collaborator

rustbot commented Oct 11, 2025

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 11, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 11, 2025

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rust-log-analyzer

This comment has been minimized.

@Mark-Simulacrum Mark-Simulacrum force-pushed the fix-offset-zst branch 4 times, most recently from 060e453 to 7a513dd Compare October 12, 2025 10:55
@Mark-Simulacrum
Copy link
Member Author

@bors r=nnethercote

@bors
Copy link
Collaborator

bors commented Oct 12, 2025

📌 Commit 7a513dd has been approved by nnethercote

It is now in the queue for this repository.

@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 Oct 12, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 12, 2025
…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
bors added a commit that referenced this pull request Oct 12, 2025
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
@matthiaskrgr
Copy link
Member

@bors r-
#147609 (comment)

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 12, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 12, 2025

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

@rustbot
Copy link
Collaborator

rustbot commented Oct 12, 2025

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.

@Mark-Simulacrum
Copy link
Member Author

@bors try jobs=dist-i586-gnu-i586-i686-musl

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 12, 2025
Fix ICE on offsetted ZST pointer

try-job: dist-i586-gnu-i586-i686-musl
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Oct 12, 2025

☀️ Try build successful (CI)
Build commit: 33c7e18 (33c7e186ed3534529f54d75674a864e6e1617999, parent: ff6dc928c5e33ce8e65c6911a790b9efcb5ef53a)


// 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// 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.
@RalfJung
Copy link
Member

@bors r=nnethercote,RalfJung

@bors
Copy link
Collaborator

bors commented Oct 16, 2025

📌 Commit a8c79b8 has been approved by nnethercote,RalfJung

It is now in the queue for this repository.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 16, 2025
bors added a commit that referenced this pull request Oct 16, 2025
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
@bors bors merged commit 5408ec3 into rust-lang:master Oct 16, 2025
11 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 16, 2025
rust-timer added a commit that referenced this pull request Oct 16, 2025
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
Comment on lines -141 to +147
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,
)
Copy link
Member

@bjorn3 bjorn3 Oct 17, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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 compiler/rustc_codegen_llvm/src/common.rs 2 == 0

8 participants