Skip to content

Commit d6b54a5

Browse files
committed
Sync from rust 5e6de2369c82ed0b36e6b651b041bad5cb5e1ef8
2 parents d1e499a + 5fd3e4d commit d6b54a5

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

src/abi/mod.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,19 @@ fn clif_sig_from_fn_abi<'tcx>(
2222
default_call_conv: CallConv,
2323
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
2424
) -> Signature {
25-
let call_conv = match fn_abi.conv {
25+
let call_conv = conv_to_call_conv(fn_abi.conv, default_call_conv);
26+
27+
let inputs = fn_abi.args.iter().map(|arg_abi| arg_abi.get_abi_param(tcx).into_iter()).flatten();
28+
29+
let (return_ptr, returns) = fn_abi.ret.get_abi_return(tcx);
30+
// Sometimes the first param is an pointer to the place where the return value needs to be stored.
31+
let params: Vec<_> = return_ptr.into_iter().chain(inputs).collect();
32+
33+
Signature { params, returns, call_conv }
34+
}
35+
36+
pub(crate) fn conv_to_call_conv(c: Conv, default_call_conv: CallConv) -> CallConv {
37+
match c {
2638
Conv::Rust | Conv::C => default_call_conv,
2739
Conv::RustCold => CallConv::Cold,
2840
Conv::X86_64SysV => CallConv::SystemV,
@@ -38,15 +50,8 @@ fn clif_sig_from_fn_abi<'tcx>(
3850
| Conv::X86VectorCall
3951
| Conv::AmdGpuKernel
4052
| Conv::AvrInterrupt
41-
| Conv::AvrNonBlockingInterrupt => todo!("{:?}", fn_abi.conv),
42-
};
43-
let inputs = fn_abi.args.iter().map(|arg_abi| arg_abi.get_abi_param(tcx).into_iter()).flatten();
44-
45-
let (return_ptr, returns) = fn_abi.ret.get_abi_return(tcx);
46-
// Sometimes the first param is an pointer to the place where the return value needs to be stored.
47-
let params: Vec<_> = return_ptr.into_iter().chain(inputs).collect();
48-
49-
Signature { params, returns, call_conv }
53+
| Conv::AvrNonBlockingInterrupt => todo!("{:?}", c),
54+
}
5055
}
5156

5257
pub(crate) fn get_function_sig<'tcx>(

src/constant.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
4545
if let Err(err) = fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) {
4646
all_constants_ok = false;
4747
match err {
48-
ErrorHandled::Reported(_) | ErrorHandled::Linted => {
48+
ErrorHandled::Reported(_) => {
4949
fx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
5050
}
5151
ErrorHandled::TooGeneric => {
@@ -126,7 +126,7 @@ pub(crate) fn codegen_const_value<'tcx>(
126126
ty: Ty<'tcx>,
127127
) -> CValue<'tcx> {
128128
let layout = fx.layout_of(ty);
129-
assert!(!layout.is_unsized(), "sized const value");
129+
assert!(layout.is_sized(), "unsized const value");
130130

131131
if layout.is_zst() {
132132
return CValue::by_ref(crate::Pointer::dangling(layout.align.pref), layout);
@@ -393,7 +393,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
393393
let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len()).to_vec();
394394
data_ctx.define(bytes.into_boxed_slice());
395395

396-
for &(offset, alloc_id) in alloc.provenance().iter() {
396+
for &(offset, alloc_id) in alloc.provenance().ptrs().iter() {
397397
let addend = {
398398
let endianness = tcx.data_layout.endian;
399399
let offset = offset.bytes() as usize;
@@ -426,7 +426,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
426426
{
427427
tcx.sess.fatal(&format!(
428428
"Allocation {:?} contains reference to TLS value {:?}",
429-
alloc, def_id
429+
alloc_id, def_id
430430
));
431431
}
432432

src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl DebugContext {
5959

6060
let producer = format!(
6161
"cg_clif (rustc {}, cranelift {})",
62-
rustc_interface::util::version_str().unwrap_or("unknown version"),
62+
rustc_interface::util::rustc_version_str().unwrap_or("unknown version"),
6363
cranelift_codegen::VERSION,
6464
);
6565
let comp_dir = tcx

src/main_shim.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ pub(crate) fn maybe_create_entry_wrapper(
6363
AbiParam::new(m.target_config().pointer_type()),
6464
],
6565
returns: vec![AbiParam::new(m.target_config().pointer_type() /*isize*/)],
66-
call_conv: CallConv::triple_default(m.isa().triple()),
66+
call_conv: crate::conv_to_call_conv(
67+
tcx.sess.target.options.entry_abi,
68+
CallConv::triple_default(m.isa().triple()),
69+
),
6770
};
6871

69-
let cmain_func_id = m.declare_function("main", Linkage::Export, &cmain_sig).unwrap();
72+
let entry_name = tcx.sess.target.options.entry_name.as_ref();
73+
let cmain_func_id = m.declare_function(entry_name, Linkage::Export, &cmain_sig).unwrap();
7074

7175
let instance = Instance::mono(tcx, rust_main_def_id).polymorphize(tcx);
7276

src/value_and_place.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn codegen_field<'tcx>(
1919
};
2020

2121
if let Some(extra) = extra {
22-
if !field_layout.is_unsized() {
22+
if field_layout.is_sized() {
2323
return simple(fx);
2424
}
2525
match field_layout.ty.kind() {
@@ -364,7 +364,7 @@ impl<'tcx> CPlace<'tcx> {
364364
fx: &mut FunctionCx<'_, '_, 'tcx>,
365365
layout: TyAndLayout<'tcx>,
366366
) -> CPlace<'tcx> {
367-
assert!(!layout.is_unsized());
367+
assert!(layout.is_sized());
368368
if layout.size.bytes() == 0 {
369369
return CPlace {
370370
inner: CPlaceInner::Addr(Pointer::dangling(layout.align.pref), None),
@@ -828,7 +828,7 @@ impl<'tcx> CPlace<'tcx> {
828828
fx: &FunctionCx<'_, '_, 'tcx>,
829829
variant: VariantIdx,
830830
) -> Self {
831-
assert!(!self.layout().is_unsized());
831+
assert!(self.layout().is_sized());
832832
let layout = self.layout().for_variant(fx, variant);
833833
CPlace { inner: self.inner, layout }
834834
}

0 commit comments

Comments
 (0)