about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-08-08 17:12:20 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-08-08 17:12:20 +0000
commit82988111b91f9190343b6c6710661f61677ca63b (patch)
treed22bee4bb869970a4c0edb9e29e83ec050c42368
parent68f7b826be24b023a625081c43d4e8af7952dd84 (diff)
parent5dd98a4eb1af02defa2ca86d79f54b6837b50c33 (diff)
downloadrust-82988111b91f9190343b6c6710661f61677ca63b.tar.gz
rust-82988111b91f9190343b6c6710661f61677ca63b.zip
Sync from rust 03a119b0b0e310d22d94399b24ed030056050f13
-rw-r--r--src/allocator.rs4
-rw-r--r--src/common.rs2
-rw-r--r--src/intrinsics/mod.rs14
-rw-r--r--src/intrinsics/simd.rs54
4 files changed, 39 insertions, 35 deletions
diff --git a/src/allocator.rs b/src/allocator.rs
index e92280b26b0..4e4c595de82 100644
--- a/src/allocator.rs
+++ b/src/allocator.rs
@@ -39,8 +39,8 @@ fn codegen_inner(
     if kind == AllocatorKind::Default {
         for method in ALLOCATOR_METHODS {
             let mut arg_tys = Vec::with_capacity(method.inputs.len());
-            for ty in method.inputs.iter() {
-                match *ty {
+            for input in method.inputs.iter() {
+                match input.ty {
                     AllocatorTy::Layout => {
                         arg_tys.push(usize_ty); // size
                         arg_tys.push(usize_ty); // align
diff --git a/src/common.rs b/src/common.rs
index 67ea20112fe..3081dcfa2b7 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -477,7 +477,7 @@ impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
 
     #[inline]
     fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
-        if let layout::LayoutError::SizeOverflow(_) = err {
+        if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err {
             self.0.sess.span_fatal(span, err.to_string())
         } else {
             span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs
index e3006b253b7..36e9ba9c7f8 100644
--- a/src/intrinsics/mod.rs
+++ b/src/intrinsics/mod.rs
@@ -1155,6 +1155,20 @@ fn codegen_regular_intrinsic_call<'tcx>(
             ret.write_cvalue(fx, CValue::by_val(is_eq_value, ret.layout()));
         }
 
+        sym::compare_bytes => {
+            intrinsic_args!(fx, args => (lhs_ptr, rhs_ptr, bytes_val); intrinsic);
+            let lhs_ptr = lhs_ptr.load_scalar(fx);
+            let rhs_ptr = rhs_ptr.load_scalar(fx);
+            let bytes_val = bytes_val.load_scalar(fx);
+
+            let params = vec![AbiParam::new(fx.pointer_type); 3];
+            let returns = vec![AbiParam::new(types::I32)];
+            let args = &[lhs_ptr, rhs_ptr, bytes_val];
+            // Here we assume that the `memcmp` provided by the target is a NOP for size 0.
+            let cmp = fx.lib_call("memcmp", params, returns, args)[0];
+            ret.write_cvalue(fx, CValue::by_val(cmp, ret.layout()));
+        }
+
         sym::const_allocate => {
             intrinsic_args!(fx, args => (_size, _align); intrinsic);
 
diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs
index d1c29f24ab9..9863e40b5b7 100644
--- a/src/intrinsics/simd.rs
+++ b/src/intrinsics/simd.rs
@@ -117,8 +117,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
             });
         }
 
-        // simd_shuffle32<T, U>(x: T, y: T, idx: [u32; 32]) -> U
-        _ if intrinsic.as_str().starts_with("simd_shuffle") => {
+        // simd_shuffle<T, I, U>(x: T, y: T, idx: I) -> U
+        sym::simd_shuffle => {
             let (x, y, idx) = match args {
                 [x, y, idx] => (x, y, idx),
                 _ => {
@@ -133,36 +133,26 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
                 return;
             }
 
-            // If this intrinsic is the older "simd_shuffleN" form, simply parse the integer.
-            // If there is no suffix, use the index array length.
-            let n: u16 = if intrinsic == sym::simd_shuffle {
-                // Make sure this is actually an array, since typeck only checks the length-suffixed
-                // version of this intrinsic.
-                let idx_ty = fx.monomorphize(idx.ty(fx.mir, fx.tcx));
-                match idx_ty.kind() {
-                    ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => len
-                        .try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all())
-                        .unwrap_or_else(|| {
-                            span_bug!(span, "could not evaluate shuffle index array length")
-                        })
-                        .try_into()
-                        .unwrap(),
-                    _ => {
-                        fx.tcx.sess.span_err(
-                            span,
-                            format!(
-                                "simd_shuffle index must be an array of `u32`, got `{}`",
-                                idx_ty,
-                            ),
-                        );
-                        // Prevent verifier error
-                        fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
-                        return;
-                    }
+            // Make sure this is actually an array, since typeck only checks the length-suffixed
+            // version of this intrinsic.
+            let idx_ty = fx.monomorphize(idx.ty(fx.mir, fx.tcx));
+            let n: u16 = match idx_ty.kind() {
+                ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => len
+                    .try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all())
+                    .unwrap_or_else(|| {
+                        span_bug!(span, "could not evaluate shuffle index array length")
+                    })
+                    .try_into()
+                    .unwrap(),
+                _ => {
+                    fx.tcx.sess.span_err(
+                        span,
+                        format!("simd_shuffle index must be an array of `u32`, got `{}`", idx_ty),
+                    );
+                    // Prevent verifier error
+                    fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
+                    return;
                 }
-            } else {
-                // FIXME remove this case
-                intrinsic.as_str()["simd_shuffle".len()..].parse().unwrap()
             };
 
             assert_eq!(x.layout(), y.layout());
@@ -179,7 +169,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
             let indexes = {
                 use rustc_middle::mir::interpret::*;
                 let idx_const = crate::constant::mir_operand_get_const_val(fx, idx)
-                    .expect("simd_shuffle* idx not const");
+                    .expect("simd_shuffle idx not const");
 
                 let idx_bytes = match idx_const {
                     ConstValue::ByRef { alloc, offset } => {