-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Fix offset used to read the second part of scalar pairs from a const
#159148
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -227,18 +227,19 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { | |||||
| BackendRepr::ScalarPair { | ||||||
| a: a @ abi::Scalar::Initialized { .. }, | ||||||
| b: b @ abi::Scalar::Initialized { .. }, | ||||||
| b_offset, | ||||||
| b_offset: local_b_offset, | ||||||
| } => { | ||||||
| let (a_size, b_size) = (a.size(bx), b.size(bx)); | ||||||
| assert!(b_offset.bytes() > 0); | ||||||
| let alloc_b_offset = offset + local_b_offset; | ||||||
| assert!(alloc_b_offset.bytes() > 0); | ||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not obvious to me what the intent of this rust/compiler/rustc_codegen_ssa/src/mir/operand.rs Lines 230 to 231 in b0cbd79
|
||||||
| let a_val = read_scalar( | ||||||
| offset, | ||||||
| a_size, | ||||||
| a, | ||||||
| bx.scalar_pair_element_backend_type(layout, 0, true), | ||||||
| ); | ||||||
|
Comment on lines
235
to
240
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do have much nicer APIs for reading stuff from a const
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It absolutely sounds interesting, but I'd not want to do it in this PR since I'd rather get back to correct with a simple PR, then do the more-churn-for-better-maintainability separately.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah definitely not for this PR, this was more of a "in case you are interested to clean this up further". |
||||||
| let b_val = read_scalar( | ||||||
| b_offset, | ||||||
| alloc_b_offset, | ||||||
| b_size, | ||||||
| b, | ||||||
| bx.scalar_pair_element_backend_type(layout, 1, true), | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| //@ compile-flags: -O -C no-prepopulate-passes | ||
|
|
||
| #![crate_type = "lib"] | ||
|
|
||
| // Regression test for https://github.com/rust-lang/rust/issues/159116 | ||
| // where a change had started reading at the wrong offset into a const | ||
| // when the sub-object had BackendRepr::ScalarPair | ||
|
|
||
| const PAIRS: [(u16, u16); 3] = [(1, 2), (3, 4), (5, 6)]; | ||
|
|
||
| // CHECK-LABEL: @read_not_first_pair | ||
| #[no_mangle] | ||
| pub fn read_not_first_pair() -> (u16, u16) { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: ret { i16, i16 } { i16 3, i16 4 } | ||
| PAIRS[1] | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
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.
Hooray for over 20 year old techniques.
View changes since the review
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.
whoops.
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.
Ahh yeah, that was easy to miss unfortunately. Needed to look closer I guess, if I wanted to make sure I got it. But yeah, important to just not make things look the same if they aren't.
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.
Yeah. Super easy when scanning to do the "well obviously this
b_offsetis exactly the same as the literally dozens of otherb_offsetvariables I'm touching".Especially when I'm not trying to change anything so am more inclined to trust tests passing that it's right -- but apparently we didn't have any coverage for this block with
offset > 0.