about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/constant.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/constant.rs b/src/constant.rs
index 94ecc3096b3..1b514958a48 100644
--- a/src/constant.rs
+++ b/src/constant.rs
@@ -225,10 +225,13 @@ pub(crate) fn trans_const_value<'tcx>(
                         }
                         None => bug!("missing allocation {:?}", ptr.alloc_id),
                     };
-                    let val = fx
-                        .bcx
-                        .ins()
-                        .iadd_imm(base_addr, i64::try_from(ptr.offset.bytes()).unwrap());
+                    let val = if ptr.offset.bytes() != 0 {
+                        fx.bcx
+                            .ins()
+                            .iadd_imm(base_addr, i64::try_from(ptr.offset.bytes()).unwrap())
+                    } else {
+                        base_addr
+                    };
                     return CValue::by_val(val, layout);
                 }
             }