diff options
| author | Erik Desjardins <erikdesjardins@users.noreply.github.com> | 2020-08-16 19:25:39 -0400 |
|---|---|---|
| committer | Erik Desjardins <erikdesjardins@users.noreply.github.com> | 2020-08-30 14:58:03 -0400 |
| commit | 68217c9e0f1269d29b4c1c72d08fb1b95bf441cd (patch) | |
| tree | 05c7e3f6c8b21b89ac73a89eab0f91744e8004a5 /compiler/rustc_codegen_ssa/src/mir | |
| parent | e9bc3ddb073f2261ac46832d985efe8db863ed6a (diff) | |
| download | rust-68217c9e0f1269d29b4c1c72d08fb1b95bf441cd.tar.gz rust-68217c9e0f1269d29b4c1c72d08fb1b95bf441cd.zip | |
ignore zst offsets instead
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/mir')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mir/place.rs | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index 05656774f0e..7c0eddea522 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -93,15 +93,29 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { let effective_field_align = self.align.restrict_for_offset(offset); let mut simple = || { - // Unions and newtypes only use an offset of 0. - let llval = if offset.bytes() == 0 { - self.llval - } else if let Abi::ScalarPair(ref a, ref b) = self.layout.abi { - // Offsets have to match either first or second field. - assert_eq!(offset, a.value.size(bx.cx()).align_to(b.value.align(bx.cx()).abi)); - bx.struct_gep(self.llval, 1) - } else { - bx.struct_gep(self.llval, bx.cx().backend_field_index(self.layout, ix)) + let llval = match self.layout.abi { + _ if offset.bytes() == 0 => { + // Unions and newtypes only use an offset of 0. + // Also handles the first field of Scalar and ScalarPair layouts. + self.llval + } + Abi::ScalarPair(ref a, ref b) + if offset == a.value.size(bx.cx()).align_to(b.value.align(bx.cx()).abi) => + { + // Offset matches second field. + bx.struct_gep(self.llval, 1) + } + Abi::ScalarPair(..) | Abi::Scalar(_) => { + // ZST fields are not included in Scalar and ScalarPair layouts, so manually offset the pointer. + assert!( + field.is_zst(), + "non-ZST field offset does not match layout: {:?}", + field + ); + let byte_ptr = bx.pointercast(self.llval, bx.cx().type_i8p()); + bx.gep(byte_ptr, &[bx.const_usize(offset.bytes())]) + } + _ => bx.struct_gep(self.llval, bx.cx().backend_field_index(self.layout, ix)), }; PlaceRef { // HACK(eddyb): have to bitcast pointers until LLVM removes pointee types. |
