Skip to content

Commit 313715f

Browse files
committed
Auto merge of #147782 - matthiaskrgr:rollup-9728xqu, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang/rust#144438 (Guard HIR lowered contracts with `contract_checks`) - rust-lang/rust#147000 (std: Add Motor OS std library port) - rust-lang/rust#147576 (Fix ICE on offsetted ZST pointer) - rust-lang/rust#147732 (remove duplicate inline macro) - rust-lang/rust#147738 (Don't highlight `let` expressions as having type `bool` in let-chain error messages) - rust-lang/rust#147744 (miri subtree update) - rust-lang/rust#147751 (Use `bit_set::Word` in a couple more places.) - rust-lang/rust#147752 (style-guide: fix typo for empty struct advice) - rust-lang/rust#147773 (`is_ascii` on an empty string or slice returns true) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3bfd067 + 094d74f commit 313715f

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/constant.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use std::cmp::Ordering;
55
use cranelift_module::*;
66
use rustc_data_structures::fx::FxHashSet;
77
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
8-
use rustc_middle::mir::interpret::{AllocId, GlobalAlloc, Scalar, read_target_uint};
8+
use rustc_middle::mir::interpret::{
9+
AllocId, GlobalAlloc, PointerArithmetic, Scalar, read_target_uint,
10+
};
911
use rustc_middle::ty::{ExistentialTraitRef, ScalarInt};
1012

1113
use crate::prelude::*;
@@ -138,8 +140,11 @@ pub(crate) fn codegen_const_value<'tcx>(
138140
let base_addr = match fx.tcx.global_alloc(alloc_id) {
139141
GlobalAlloc::Memory(alloc) => {
140142
if alloc.inner().len() == 0 {
141-
assert_eq!(offset, Size::ZERO);
142-
fx.bcx.ins().iconst(fx.pointer_type, alloc.inner().align.bytes() as i64)
143+
let val = alloc.inner().align.bytes().wrapping_add(offset.bytes());
144+
fx.bcx.ins().iconst(
145+
fx.pointer_type,
146+
fx.tcx.truncate_to_target_usize(val) as i64,
147+
)
143148
} else {
144149
let data_id = data_id_for_alloc_id(
145150
&mut fx.constants_cx,

0 commit comments

Comments
 (0)