From 2f2d3b2fd4d38f1ea0c63eb8e880085a2ccf0987 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 12 Oct 2020 12:03:18 +0200 Subject: [PATCH] Avoid iadd for ptr const val with zero offset --- src/constant.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 94ecc3096b38..1b514958a480 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); } }