Uh oh!
There was an error while loading. Please reload this page.
emit "align 1" metadata on loads/stores of packed structs - #39586
Conversation
| } else { | ||
| let val = if fn_ty.args[1].is_indirect() { | ||
| bcx.load(llargs[1]) | ||
| bcx.load(llargs[1], None) // FIXME: this is incorrect |
There was a problem hiding this comment.
Are you going to do something about this?
There was a problem hiding this comment.
This is hard to fix without a refactor.
LGTM, except for that one FIXME. f? @Aatch, r=me if no concerns remain. |
arielb1
commented
Feb 6, 2017
And the FIXME turned out to be unneeded - ABI indirect arguments are always aligned. @bors r=eddyb |
bors
commented
Feb 6, 2017
📌 Commit 56591f6 has been approved by |
Aatch
commented
Feb 6, 2017
@bors r=eddyb |
bors
commented
Feb 6, 2017
💡 This pull request was already approved, no need to approve it again.
|
bors
commented
Feb 6, 2017
📌 Commit 56591f6 has been approved by |
arielb1
commented
Feb 6, 2017
@bors r=eddyb |
bors
commented
Feb 6, 2017
📌 Commit 67789c4 has been approved by |
emit "align 1" metadata on loads/stores of packed structs According to the LLVM reference: > A value of 0 or an omitted align argument means that the operation has the ABI alignment for the target. So loads/stores of fields of packed structs need to have their align set to 1. Implement that by tracking the alignment of `LvalueRef`s. Fixesrust-lang#39376. r? @eddyb
According to the LLVM reference: > A value of 0 or an omitted align argument means that the operation has the ABI alignment for the target. So loads/stores of fields of packed structs need to have their align set to 1. Implement that by tracking the alignment of `LvalueRef`s. Fixesrust-lang#39376.
The function was a footgun because it created `undef` references to ZSTs, which could cause trouble were they to leak to user code.
arielb1
commented
Feb 8, 2017
rebased @bors r=eddyb |
bors
commented
Feb 8, 2017
📌 Commit d71988a has been approved by |
Unfortunately, this patch doesn't seem to resolve the issue fully. See #39376 for an example test case that appears to still fail. Note that brute force hack patch also mentioned in the bug there that does resolve the issue for the test case shown. |
This is seen in the RUST_LOG=4 output when building the referenced example: |
I compile your example using your patch - that's it, use std::slice;use std::u32;#[repr(packed)]#[derive(Copy,Clone)]structUnaligned<T>(T);impl<T>Unaligned<T>{fnget(self) -> T{self.0}}fnbytes_to_words(b:&[u8]) -> &[Unaligned<u32>]{unsafe{ slice::from_raw_parts(b.as_ptr()as*constUnaligned<u32>, b.len() / 4)}}fnmain(){let values = String::from("fedcba98765432100123456789abcdef");let bytes = values.as_bytes();letmut words = &bytes_to_words(&bytes[1..]);let index = 1;let position = u32::from_le(words[index].get());}and it works (emits align metadata on the necessary loads). Is there some other example you are talking about?
We should not be having this (immediate |
bors
commented
Feb 9, 2017
emit "align 1" metadata on loads/stores of packed structs According to the LLVM reference: > A value of 0 or an omitted align argument means that the operation has the ABI alignment for the target. So loads/stores of fields of packed structs need to have their align set to 1. Implement that by tracking the alignment of `LvalueRef`s. Fixes#39376. r? @eddyb
bors
commented
Feb 9, 2017
☀️ Test successful - status-appveyor, status-travis |
binarycrusader
commented
Feb 21, 2017
Would someone be willing to beta-nominate this? This patch has been used successfully against 1.16 beta for almost two weeks and resolved the last code generation issue we encountered on sparc (and I suspect would help other architectures too). I believe it applies cleanly without any changes to current beta tip. |
[beta] next - #39913 - #39730 - #39674 - #39602 - #39586 - #39471 - #39980 - #40020 - #40135@nikomatsakis [this commit](3787d33) did not pick cleanly. You might peek at it. I took the liberty of accepting all the nominations myself, but the [packed struct alignment](#39586) PR is quite large. It did pick fine though and there's a comment there suggesting it works on beta cc @rust-lang/compiler. cc @alexcrichton
According to the LLVM reference:
So loads/stores of fields of packed structs need to have their align set
to 1. Implement that by tracking the alignment of
LvalueRefs.Fixes#39376.
r? @eddyb