-
Notifications
You must be signed in to change notification settings - Fork 13.5k
rustc_codegen_llvm: don't overalign loads of pair operands. #56329
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
r? @estebank (rust_highfive has picked a reviewer for you, use r? to override) |
Why is |
@bors r+ p=10 |
📌 Commit 51cf4e9 has been approved by |
cc @rust-lang/compiler Marking as beta-accepted because small and tight time constraints. |
rustc_codegen_llvm: don't overalign loads of pair operands. Counterpart to #56300, but for loads instead of stores.
☀️ Test successful - status-appveyor, status-travis |
Removing beta-accepted so we can discuss in today's @rust-lang/compiler meeting. |
I was somewhat skeptical about whether the incorrect alignments could result in actual miscompilations, as usually LLVM cannot do a whole lot with alignments that are larger than the load/store size from a codegen perspective. I've been able to come up with the following case, which segfaults prior to the alignment fixes: #[repr(align(16))]
pub struct Foo<T> {
bar: T,
baz: T,
}
#[inline(never)]
pub fn test(x: Foo<(i64, i64)>) -> Foo<(i64, i64)> {
let bar = x.bar;
let baz = x.baz;
Foo { bar: (bar.1, baz.0), baz: (0, 0) }
}
fn main() {
test(Foo { bar: (0, 0), baz: (0, 0) });
} The trick is to make sure the load of the first pair element is optimized away, while the load for the second pair element is coalesced with adjacent loads into a larger size. This results in codegen emitting |
FWIW this bug already existed AFAICT, I don't know how we hadn't hit it before... |
@eddyb Probably due to this code on stable: rust/src/librustc_codegen_llvm/mir/place.rs Line 176 in 1433507
|
discussed in T-compiler meeting. beta-accepting. |
@eddyb and/or @nikic, would y'all be able to help out in a backport to beta for this? It appears the patch to |
It's |
Ok thanks! I think this is running into the same errors found on #56300 (comment), can you help out with those? |
Ok I think I've figured it out with some help at #56352 |
Counterpart to #56300, but for loads instead of stores.