about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2020-10-12 12:03:18 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2020-10-12 12:04:17 +0200
commit2f2d3b2fd4d38f1ea0c63eb8e880085a2ccf0987 (patch)
tree39959373c70db880814696fa70d561395e0e16c6
parentcd2fc77b0ee166be15c71963b036dfc7a65df63d (diff)
downloadrust-2f2d3b2fd4d38f1ea0c63eb8e880085a2ccf0987.tar.gz
rust-2f2d3b2fd4d38f1ea0c63eb8e880085a2ccf0987.zip
Avoid iadd for ptr const val with zero offset
-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);
                 }
             }