Skip to content

Commit 8298811

Browse files
committed
Sync from rust 03a119b
2 parents 68f7b82 + 5dd98a4 commit 8298811

File tree

4 files changed

+39
-35
lines changed

4 files changed

+39
-35
lines changed

src/allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ fn codegen_inner(
3939
if kind == AllocatorKind::Default {
4040
for method in ALLOCATOR_METHODS {
4141
let mut arg_tys = Vec::with_capacity(method.inputs.len());
42-
for ty in method.inputs.iter() {
43-
match *ty {
42+
for input in method.inputs.iter() {
43+
match input.ty {
4444
AllocatorTy::Layout => {
4545
arg_tys.push(usize_ty); // size
4646
arg_tys.push(usize_ty); // align

src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
477477

478478
#[inline]
479479
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
480-
if let layout::LayoutError::SizeOverflow(_) = err {
480+
if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err {
481481
self.0.sess.span_fatal(span, err.to_string())
482482
} else {
483483
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)

src/intrinsics/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,20 @@ fn codegen_regular_intrinsic_call<'tcx>(
11551155
ret.write_cvalue(fx, CValue::by_val(is_eq_value, ret.layout()));
11561156
}
11571157

1158+
sym::compare_bytes => {
1159+
intrinsic_args!(fx, args => (lhs_ptr, rhs_ptr, bytes_val); intrinsic);
1160+
let lhs_ptr = lhs_ptr.load_scalar(fx);
1161+
let rhs_ptr = rhs_ptr.load_scalar(fx);
1162+
let bytes_val = bytes_val.load_scalar(fx);
1163+
1164+
let params = vec![AbiParam::new(fx.pointer_type); 3];
1165+
let returns = vec![AbiParam::new(types::I32)];
1166+
let args = &[lhs_ptr, rhs_ptr, bytes_val];
1167+
// Here we assume that the `memcmp` provided by the target is a NOP for size 0.
1168+
let cmp = fx.lib_call("memcmp", params, returns, args)[0];
1169+
ret.write_cvalue(fx, CValue::by_val(cmp, ret.layout()));
1170+
}
1171+
11581172
sym::const_allocate => {
11591173
intrinsic_args!(fx, args => (_size, _align); intrinsic);
11601174

src/intrinsics/simd.rs

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
117117
});
118118
}
119119

120-
// simd_shuffle32<T, U>(x: T, y: T, idx: [u32; 32]) -> U
121-
_ if intrinsic.as_str().starts_with("simd_shuffle") => {
120+
// simd_shuffle<T, I, U>(x: T, y: T, idx: I) -> U
121+
sym::simd_shuffle => {
122122
let (x, y, idx) = match args {
123123
[x, y, idx] => (x, y, idx),
124124
_ => {
@@ -133,36 +133,26 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
133133
return;
134134
}
135135

136-
// If this intrinsic is the older "simd_shuffleN" form, simply parse the integer.
137-
// If there is no suffix, use the index array length.
138-
let n: u16 = if intrinsic == sym::simd_shuffle {
139-
// Make sure this is actually an array, since typeck only checks the length-suffixed
140-
// version of this intrinsic.
141-
let idx_ty = fx.monomorphize(idx.ty(fx.mir, fx.tcx));
142-
match idx_ty.kind() {
143-
ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => len
144-
.try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all())
145-
.unwrap_or_else(|| {
146-
span_bug!(span, "could not evaluate shuffle index array length")
147-
})
148-
.try_into()
149-
.unwrap(),
150-
_ => {
151-
fx.tcx.sess.span_err(
152-
span,
153-
format!(
154-
"simd_shuffle index must be an array of `u32`, got `{}`",
155-
idx_ty,
156-
),
157-
);
158-
// Prevent verifier error
159-
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
160-
return;
161-
}
136+
// Make sure this is actually an array, since typeck only checks the length-suffixed
137+
// version of this intrinsic.
138+
let idx_ty = fx.monomorphize(idx.ty(fx.mir, fx.tcx));
139+
let n: u16 = match idx_ty.kind() {
140+
ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => len
141+
.try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all())
142+
.unwrap_or_else(|| {
143+
span_bug!(span, "could not evaluate shuffle index array length")
144+
})
145+
.try_into()
146+
.unwrap(),
147+
_ => {
148+
fx.tcx.sess.span_err(
149+
span,
150+
format!("simd_shuffle index must be an array of `u32`, got `{}`", idx_ty),
151+
);
152+
// Prevent verifier error
153+
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
154+
return;
162155
}
163-
} else {
164-
// FIXME remove this case
165-
intrinsic.as_str()["simd_shuffle".len()..].parse().unwrap()
166156
};
167157

168158
assert_eq!(x.layout(), y.layout());
@@ -179,7 +169,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
179169
let indexes = {
180170
use rustc_middle::mir::interpret::*;
181171
let idx_const = crate::constant::mir_operand_get_const_val(fx, idx)
182-
.expect("simd_shuffle* idx not const");
172+
.expect("simd_shuffle idx not const");
183173

184174
let idx_bytes = match idx_const {
185175
ConstValue::ByRef { alloc, offset } => {

0 commit comments

Comments
 (0)