-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 alignment for array indexing #57053
Conversation
// as this will yield the lowest alignment. | ||
let layout = self.layout.field(bx, 0); | ||
let offset = if bx.is_const_integral(llindex) { | ||
layout.size.checked_mul(bx.const_to_uint(llindex), bx).unwrap_or(layout.size) |
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 think this checked_mul is not strictly necessary, as such cases won't reach here, but included it to be sure.
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.
Could you also add a test case(s) for #[packed]
that would exercise these specific constructs? I don’t believe we have such a test yet. codegen/packed.rs
would be a good place for one.
r=me after CHECK-LABEL
s are added to the test.
arr: [u32; 4], | ||
} | ||
|
||
// CHECK: store i32 0, i32* %{{.+}}, align 16 |
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.
Please check for the label before the store
instructions.
We need to reduce the alignment with the used offset. If the offset isn't known, we need to reduce with the element size to support arbitrary offsets.
@nagisa I've added CHECK-LABELs and a couple of packed tests. |
@bors r+ |
📌 Commit 097d39d has been approved by |
Fix alignment for array indexing We need to reduce the alignment with the used offset. If the offset isn't known, use the element size, as this will yield the minimum possible alignment. This handles both direct array indexing, and array repeat expressions. Fixes rust-lang#56927. r? @nagisa
Fix alignment for array indexing We need to reduce the alignment with the used offset. If the offset isn't known, use the element size, as this will yield the minimum possible alignment. This handles both direct array indexing, and array repeat expressions. Fixes rust-lang#56927. r? @nagisa
Rollup of 10 pull requests Successful merges: - #56188 (enum type instead of variant suggestion unification ) - #56916 (Fix mutable references in `static mut`) - #56917 (Simplify MIR generation for logical operations) - #56953 (Mark tuple structs as live if their constructors are used) - #56964 (Remove `TokenStream::JointTree`.) - #56966 (Correct strings for raw pointer deref and array access suggestions) - #56999 (AST/HIR: Introduce `ExprKind::Err` for better error recovery in the front-end) - #57020 (Point to cause of `fn` expected return type) - #57032 (fix deprecation warnings in liballoc benches) - #57053 (Fix alignment for array indexing) Failed merges: r? @ghost
Fix alignment for array indexing We need to reduce the alignment with the used offset. If the offset isn't known, use the element size, as this will yield the minimum possible alignment. This handles both direct array indexing, and array repeat expressions. Fixes rust-lang#56927. r? @nagisa
Fix alignment for array indexing We need to reduce the alignment with the used offset. If the offset isn't known, use the element size, as this will yield the minimum possible alignment. This handles both direct array indexing, and array repeat expressions. Fixes rust-lang#56927. r? @nagisa
Rollup of 14 pull requests Successful merges: - #56188 (enum type instead of variant suggestion unification ) - #56342 (Improve docs for collecting into `Option`s) - #56916 (Fix mutable references in `static mut`) - #56917 (Simplify MIR generation for logical operations) - #56939 (Pin stabilization) - #56953 (Mark tuple structs as live if their constructors are used) - #56964 (Remove `TokenStream::JointTree`.) - #56966 (Correct strings for raw pointer deref and array access suggestions) - #57020 (Point to cause of `fn` expected return type) - #57032 (fix deprecation warnings in liballoc benches) - #57053 (Fix alignment for array indexing) - #57062 (Fix a comment) - #57067 (Stabilize min_const_unsafe_fn in 1.33) - #57078 (Ignore two tests on s390x) Failed merges: r? @ghost
[beta] Rollup backports Cherry-picked: * #57053: Fix alignment for array indexing * #57181: resolve: Fix another ICE in import validation * #57185: resolve: Fix one more ICE in import validation * #57282: Wf-check the output type of a function in MIR-typeck * #55318: Ensure that Rustdoc discovers all necessary auto trait bounds * #56838: Call poly_project_and_unify_type on types that contain inference types Rolled up: * #57300: [beta] Update RLS to include 100% CPU on hover bugfix * #57301: beta: bootstrap from latest stable (1.31.1) * #57292: [BETA] Update cargo r? @ghost
We need to reduce the alignment with the used offset. If the offset isn't known, use the element size, as this will yield the minimum possible alignment.
This handles both direct array indexing, and array repeat expressions.
Fixes #56927.
r? @nagisa