Skip to content

Commit 71ae2f0

Browse files
committed
Auto merge of #3069 - rust-lang:rustup-2023-09-21, r=RalfJung
Automatic sync from rustc
2 parents 401d897 + 901ff8e commit 71ae2f0

File tree

9 files changed

+373
-566
lines changed

9 files changed

+373
-566
lines changed

Cargo.lock

+52-36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ doctest = false # and no doc tests
1919

2020
[dependencies]
2121
getrandom = { version = "0.2", features = ["std"] }
22-
env_logger = "0.9"
22+
env_logger = "0.10"
2323
log = "0.4"
2424
rand = "0.8"
2525
smallvec = "1.7"

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19dd9535408db0f1ff3d16613619076aef524d19
1+
4fda889bf8735755573b27e6116ce025f3ded5f9

src/helpers.rs

+36-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::mir;
1414
use rustc_middle::ty::{
1515
self,
1616
layout::{IntegerExt as _, LayoutOf, TyAndLayout},
17-
Ty, TyCtxt,
17+
IntTy, Ty, TyCtxt, UintTy,
1818
};
1919
use rustc_span::{def_id::CrateNum, sym, Span, Symbol};
2020
use rustc_target::abi::{Align, FieldIdx, FieldsShape, Integer, Size, Variants};
@@ -1066,6 +1066,24 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
10661066
),
10671067
}
10681068
}
1069+
1070+
/// Returns an integer type that is twice wide as `ty`
1071+
fn get_twice_wide_int_ty(&self, ty: Ty<'tcx>) -> Ty<'tcx> {
1072+
let this = self.eval_context_ref();
1073+
match ty.kind() {
1074+
// Unsigned
1075+
ty::Uint(UintTy::U8) => this.tcx.types.u16,
1076+
ty::Uint(UintTy::U16) => this.tcx.types.u32,
1077+
ty::Uint(UintTy::U32) => this.tcx.types.u64,
1078+
ty::Uint(UintTy::U64) => this.tcx.types.u128,
1079+
// Signed
1080+
ty::Int(IntTy::I8) => this.tcx.types.i16,
1081+
ty::Int(IntTy::I16) => this.tcx.types.i32,
1082+
ty::Int(IntTy::I32) => this.tcx.types.i64,
1083+
ty::Int(IntTy::I64) => this.tcx.types.i128,
1084+
_ => span_bug!(this.cur_span(), "unexpected type: {ty:?}"),
1085+
}
1086+
}
10691087
}
10701088

10711089
impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
@@ -1151,3 +1169,20 @@ pub fn get_local_crates(tcx: TyCtxt<'_>) -> Vec<CrateNum> {
11511169
pub fn target_os_is_unix(target_os: &str) -> bool {
11521170
matches!(target_os, "linux" | "macos" | "freebsd" | "android")
11531171
}
1172+
1173+
pub(crate) fn bool_to_simd_element(b: bool, size: Size) -> Scalar<Provenance> {
1174+
// SIMD uses all-1 as pattern for "true". In two's complement,
1175+
// -1 has all its bits set to one and `from_int` will truncate or
1176+
// sign-extend it to `size` as required.
1177+
let val = if b { -1 } else { 0 };
1178+
Scalar::from_int(val, size)
1179+
}
1180+
1181+
pub(crate) fn simd_element_to_bool(elem: ImmTy<'_, Provenance>) -> InterpResult<'_, bool> {
1182+
let val = elem.to_scalar().to_int(elem.layout.size)?;
1183+
Ok(match val {
1184+
0 => false,
1185+
-1 => true,
1186+
_ => throw_ub_format!("each element of a SIMD mask must be all-0-bits or all-1-bits"),
1187+
})
1188+
}

src/shims/backtrace.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
8888
this.write_pointer(ptr, &place)?;
8989
}
9090

91-
this.write_immediate(
92-
Immediate::new_slice(Scalar::from_maybe_pointer(alloc.ptr(), this), len, this),
93-
dest,
94-
)?;
91+
this.write_immediate(Immediate::new_slice(alloc.ptr(), len, this), dest)?;
9592
}
9693
// storage for pointers is allocated by the caller
9794
1 => {

src/shims/intrinsics/simd.rs

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use rustc_apfloat::{Float, Round};
22
use rustc_middle::ty::layout::{HasParamEnv, LayoutOf};
33
use rustc_middle::{mir, ty, ty::FloatTy};
4-
use rustc_target::abi::{Endian, HasDataLayout, Size};
4+
use rustc_target::abi::{Endian, HasDataLayout};
55

66
use crate::*;
7-
use helpers::check_arg_count;
7+
use helpers::{bool_to_simd_element, check_arg_count, simd_element_to_bool};
88

99
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
1010
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
@@ -612,21 +612,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
612612
}
613613
}
614614

615-
fn bool_to_simd_element(b: bool, size: Size) -> Scalar<Provenance> {
616-
// SIMD uses all-1 as pattern for "true"
617-
let val = if b { -1 } else { 0 };
618-
Scalar::from_int(val, size)
619-
}
620-
621-
fn simd_element_to_bool(elem: ImmTy<'_, Provenance>) -> InterpResult<'_, bool> {
622-
let val = elem.to_scalar().to_int(elem.layout.size)?;
623-
Ok(match val {
624-
0 => false,
625-
-1 => true,
626-
_ => throw_ub_format!("each element of a SIMD mask must be all-0-bits or all-1-bits"),
627-
})
628-
}
629-
630615
fn simd_bitmask_index(idx: u32, vec_len: u32, endianness: Endian) -> u32 {
631616
assert!(idx < vec_len);
632617
match endianness {

0 commit comments

Comments
 (0)