Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b03d0b8

Browse files
committed
Sync from rust 0288f2e
2 parents 8071ec7 + 1351de3 commit b03d0b8

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/constant.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
use cranelift_module::*;
44
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
55
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
6-
use rustc_middle::mir::interpret::{read_target_uint, AllocId, ConstValue, GlobalAlloc, Scalar};
6+
use rustc_middle::mir::interpret::{read_target_uint, AllocId, GlobalAlloc, Scalar};
7+
use rustc_middle::mir::ConstValue;
78

89
use crate::prelude::*;
910

@@ -62,9 +63,9 @@ pub(crate) fn codegen_tls_ref<'tcx>(
6263

6364
pub(crate) fn eval_mir_constant<'tcx>(
6465
fx: &FunctionCx<'_, '_, 'tcx>,
65-
constant: &Constant<'tcx>,
66+
constant: &ConstOperand<'tcx>,
6667
) -> (ConstValue<'tcx>, Ty<'tcx>) {
67-
let cv = fx.monomorphize(constant.literal);
68+
let cv = fx.monomorphize(constant.const_);
6869
// This cannot fail because we checked all required_consts in advance.
6970
let val = cv
7071
.eval(fx.tcx, ty::ParamEnv::reveal_all(), Some(constant.span))
@@ -74,7 +75,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
7475

7576
pub(crate) fn codegen_constant_operand<'tcx>(
7677
fx: &mut FunctionCx<'_, '_, 'tcx>,
77-
constant: &Constant<'tcx>,
78+
constant: &ConstOperand<'tcx>,
7879
) -> CValue<'tcx> {
7980
let (const_val, ty) = eval_mir_constant(fx, constant);
8081
codegen_const_value(fx, const_val, ty)
@@ -182,15 +183,11 @@ pub(crate) fn codegen_const_value<'tcx>(
182183
.offset_i64(fx, i64::try_from(offset.bytes()).unwrap()),
183184
layout,
184185
),
185-
ConstValue::Slice { data, start, end } => {
186+
ConstValue::Slice { data, meta } => {
186187
let alloc_id = fx.tcx.reserve_and_set_memory_alloc(data);
187-
let ptr = pointer_for_allocation(fx, alloc_id)
188-
.offset_i64(fx, i64::try_from(start).unwrap())
189-
.get_addr(fx);
190-
let len = fx
191-
.bcx
192-
.ins()
193-
.iconst(fx.pointer_type, i64::try_from(end.checked_sub(start).unwrap()).unwrap());
188+
let ptr = pointer_for_allocation(fx, alloc_id).get_addr(fx);
189+
// FIXME: the `try_from` here can actually fail, e.g. for very long ZST slices.
190+
let len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(meta).unwrap());
194191
CValue::by_val_pair(ptr, len, layout)
195192
}
196193
}

src/inline_asm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ pub(crate) fn codegen_inline_asm<'tcx>(
252252
CInlineAsmOperand::Const { value }
253253
}
254254
InlineAsmOperand::SymFn { ref value } => {
255-
let literal = fx.monomorphize(value.literal);
256-
if let ty::FnDef(def_id, args) = *literal.ty().kind() {
255+
let const_ = fx.monomorphize(value.const_);
256+
if let ty::FnDef(def_id, args) = *const_.ty().kind() {
257257
let instance = ty::Instance::resolve_for_fn_ptr(
258258
fx.tcx,
259259
ty::ParamEnv::reveal_all(),

0 commit comments

Comments
 (0)