diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-04-25 22:41:34 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-04-27 22:44:42 -0700 |
| commit | e1da77c76d63f442acadcfbda4e42701887d6324 (patch) | |
| tree | 6ea4d5c183b07a5c9f08cb891cb2f83bfdb4b797 /compiler/rustc_codegen_ssa/src/mir | |
| parent | 8bcfc0e597294f48549ed446f89415150516d030 (diff) | |
| download | rust-e1da77c76d63f442acadcfbda4e42701887d6324.tar.gz rust-e1da77c76d63f442acadcfbda4e42701887d6324.zip | |
Also use `mir::Offset` for pointer `add`
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/mir')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 94de19a9c29..64452472eec 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -819,8 +819,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { .builtin_deref(true) .unwrap_or_else(|| bug!("deref of non-pointer {:?}", input_ty)) .ty; - let llty = bx.cx().backend_type(bx.cx().layout_of(pointee_type)); - bx.inbounds_gep(llty, lhs, &[rhs]) + let pointee_layout = bx.cx().layout_of(pointee_type); + if pointee_layout.is_zst() { + // `Offset` works in terms of the size of pointee, + // so offsetting a pointer to ZST is a noop. + lhs + } else { + let llty = bx.cx().backend_type(pointee_layout); + bx.inbounds_gep(llty, lhs, &[rhs]) + } } mir::BinOp::Shl => common::build_unchecked_lshift(bx, lhs, rhs), mir::BinOp::Shr => common::build_unchecked_rshift(bx, input_ty, lhs, rhs), |
