-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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
base: master
Are you sure you want to change the base?
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
/// Assuming that the pointer is to a ZST, this computes the appropriate value to use for the | ||
/// result of properly aligning (essentially `ptr::dangling`) and offsetting the resulting | ||
/// pointer. | ||
pub fn zst_addr(self, align: Align, cx: &impl HasDataLayout) -> u64 { |
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.
I can't make any sense of this comment, unfortunately. If this pointer points to an actual allocation, it makes no logical sense to just add its offset to anything else except for the address of that allocation.
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.
Oh, this is about pointers to zero-sized allocations -- not ZST pointers in general. &()
can point inside a larger allocation and then this function must not be used.
And even then, the only time this function is correct to use if if the caller can guarantee that all pointers to this allocation are treated like this. I am not sure that should be such an easy-to-accidentally-misuse helper like this.
This comment has been minimized.
This comment has been minimized.
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.
d58c744
to
b27c4ef
Compare
|
||
// 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 |
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