about summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/array-cmp.rs18
-rw-r--r--tests/codegen/noalias-freeze.rs21
-rw-r--r--tests/codegen/vec-in-place.rs22
3 files changed, 61 insertions, 0 deletions
diff --git a/tests/codegen/array-cmp.rs b/tests/codegen/array-cmp.rs
new file mode 100644
index 00000000000..194c0adf1d2
--- /dev/null
+++ b/tests/codegen/array-cmp.rs
@@ -0,0 +1,18 @@
+// Ensure the asm for array comparisons is properly optimized.
+
+//@ compile-flags: -C opt-level=2
+
+#![crate_type = "lib"]
+
+// CHECK-LABEL: @compare
+// CHECK: start:
+// CHECK-NEXT: ret i1 true
+#[no_mangle]
+pub fn compare() -> bool {
+    let bytes = 12.5f32.to_ne_bytes();
+    bytes == if cfg!(target_endian = "big") {
+        [0x41, 0x48, 0x00, 0x00]
+    } else {
+        [0x00, 0x00, 0x48, 0x41]
+    }
+}
diff --git a/tests/codegen/noalias-freeze.rs b/tests/codegen/noalias-freeze.rs
new file mode 100644
index 00000000000..8086f3afbbc
--- /dev/null
+++ b/tests/codegen/noalias-freeze.rs
@@ -0,0 +1,21 @@
+//@ compile-flags: -Copt-level=1
+
+// References returned by a Frozen pointer type
+// could be marked as "noalias", which caused miscompilation errors.
+// This test runs the most minimal possible code that can reproduce this bug,
+// and checks that noalias does not appear.
+// See https://github.com/rust-lang/rust/issues/46239
+
+#![crate_type = "lib"]
+
+fn project<T>(x: &(T,)) -> &T { &x.0 }
+
+fn dummy() {}
+
+// CHECK-LABEL: @foo(
+// CHECK-NOT: noalias
+#[no_mangle]
+pub fn foo() {
+    let f = (dummy as fn(),);
+    (*project(&f))();
+}
diff --git a/tests/codegen/vec-in-place.rs b/tests/codegen/vec-in-place.rs
index 7a175dc4f7e..c6b77363a4e 100644
--- a/tests/codegen/vec-in-place.rs
+++ b/tests/codegen/vec-in-place.rs
@@ -90,3 +90,25 @@ pub fn vec_iterator_cast_deaggregate_fold(vec: Vec<Baz>) -> Vec<[u64; 4]> {
     // correct.
     vec.into_iter().map(|e| unsafe { std::mem::transmute(e) }).collect()
 }
+
+// CHECK-LABEL: @vec_iterator_cast_unwrap_drop
+#[no_mangle]
+pub fn vec_iterator_cast_unwrap_drop(vec: Vec<Wrapper<String>>) -> Vec<String> {
+    // CHECK-NOT: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
+    // CHECK-NOT: call
+    // CHECK-NOT: %{{.*}} = mul
+    // CHECK-NOT: %{{.*}} = udiv
+
+    vec.into_iter().map(|Wrapper(e)| e).collect()
+}
+
+// CHECK-LABEL: @vec_iterator_cast_wrap_drop
+#[no_mangle]
+pub fn vec_iterator_cast_wrap_drop(vec: Vec<String>) -> Vec<Wrapper<String>> {
+    // CHECK-NOT: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
+    // CHECK-NOT: call
+    // CHECK-NOT: %{{.*}} = mul
+    // CHECK-NOT: %{{.*}} = udiv
+
+    vec.into_iter().map(Wrapper).collect()
+}