about summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorThe Miri Conjob Bot <miri@cron.bot>2024-02-06 05:17:05 +0000
committerThe Miri Conjob Bot <miri@cron.bot>2024-02-06 05:17:05 +0000
commit08e774179e237ec9235760104eb01c3fa481b3fe (patch)
tree78f8824f1d20458c113d6148421ee9b9e8482910 /tests/codegen
parenteaa2da5d921225266d714d8d28b87cc8d131bcae (diff)
parentf3b9d47a46c6d237665801155aa3e26c5f49958b (diff)
downloadrust-08e774179e237ec9235760104eb01c3fa481b3fe.tar.gz
rust-08e774179e237ec9235760104eb01c3fa481b3fe.zip
Merge from rustc
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/is_val_statically_known.rs38
-rw-r--r--tests/codegen/pow_of_two.rs55
2 files changed, 38 insertions, 55 deletions
diff --git a/tests/codegen/is_val_statically_known.rs b/tests/codegen/is_val_statically_known.rs
index 44187d4f667..8f084f6c54b 100644
--- a/tests/codegen/is_val_statically_known.rs
+++ b/tests/codegen/is_val_statically_known.rs
@@ -46,3 +46,41 @@ pub fn _bool_false(b: bool) -> i32 {
     // CHECK: ret i32 2
     _bool(b)
 }
+
+#[inline]
+pub fn _iref(a: &u8) -> i32 {
+    if unsafe { is_val_statically_known(a) } { 5 } else { 4 }
+}
+
+// CHECK-LABEL: @_iref_borrow(
+#[no_mangle]
+pub fn _iref_borrow() -> i32 {
+    // CHECK: ret i32 4
+    _iref(&0)
+}
+
+// CHECK-LABEL: @_iref_arg(
+#[no_mangle]
+pub fn _iref_arg(a: &u8) -> i32 {
+    // CHECK: ret i32 4
+    _iref(a)
+}
+
+#[inline]
+pub fn _slice_ref(a: &[u8]) -> i32 {
+    if unsafe { is_val_statically_known(a) } { 7 } else { 6 }
+}
+
+// CHECK-LABEL: @_slice_ref_borrow(
+#[no_mangle]
+pub fn _slice_ref_borrow() -> i32 {
+    // CHECK: ret i32 6
+    _slice_ref(&[0;3])
+}
+
+// CHECK-LABEL: @_slice_ref_arg(
+#[no_mangle]
+pub fn _slice_ref_arg(a: &[u8]) -> i32 {
+    // CHECK: ret i32 6
+    _slice_ref(a)
+}
diff --git a/tests/codegen/pow_of_two.rs b/tests/codegen/pow_of_two.rs
deleted file mode 100644
index 372360dfd12..00000000000
--- a/tests/codegen/pow_of_two.rs
+++ /dev/null
@@ -1,55 +0,0 @@
-// compile-flags: --crate-type=lib -Zmerge-functions=disabled -O -C overflow-checks=false
-
-// CHECK-LABEL: @a(
-#[no_mangle]
-pub fn a(exp: u32) -> u64 {
-    // CHECK: %{{[^ ]+}} = icmp ugt i32 %exp, 64
-    // CHECK: %{{[^ ]+}} = zext{{( nneg)?}} i32 %exp to i64
-    // CHECK: %{{[^ ]+}} = shl nuw i64 {{[^ ]+}}, %{{[^ ]+}}
-    // CHECK: ret i64 %{{[^ ]+}}
-    2u64.pow(exp)
-}
-
-// CHECK-LABEL: @b(
-#[no_mangle]
-pub fn b(exp: u32) -> i64 {
-    // CHECK: %{{[^ ]+}} = icmp ugt i32 %exp, 64
-    // CHECK: %{{[^ ]+}} = zext{{( nneg)?}} i32 %exp to i64
-    // CHECK: %{{[^ ]+}} = shl nuw i64 {{[^ ]+}}, %{{[^ ]+}}
-    // CHECK: ret i64 %{{[^ ]+}}
-    2i64.pow(exp)
-}
-
-// CHECK-LABEL: @c(
-#[no_mangle]
-pub fn c(exp: u32) -> u32 {
-    // CHECK: %{{[^ ]+}} = icmp ugt i32 %exp, 16
-    // CHECK: %{{[^ ]+}} = shl nuw nsw i32 %exp, 1
-    // CHECK: %{{[^ ]+}} = shl nuw i32 1, %{{[^ ]+}}
-    // CHECK: %{{[^ ]+}} = select i1 %{{[^ ]+}}, i32 0, i32 %{{[^ ]+}}
-    // CHECK: ret i32 %{{[^ ]+}}
-    4u32.pow(exp)
-}
-
-// CHECK-LABEL: @d(
-#[no_mangle]
-pub fn d(exp: u32) -> u32 {
-    // CHECK: %{{[^ ]+}} = icmp ugt i32 %exp, 6
-    // CHECK: %{{[^ ]+}} = mul nuw nsw i32 %exp, 5
-    // CHECK: %{{[^ ]+}} = shl nuw nsw i32 1, %{{[^ ]+}}
-    // CHECK: %{{[^ ]+}} = select i1 {{[^ ]+}}, i32 0, i32 %{{[^ ]+}}
-    // CHECK: ret i32 %{{[^ ]+}}
-    32u32.pow(exp)
-}
-
-// CHECK-LABEL: @e(
-#[no_mangle]
-pub fn e(exp: u32) -> i32 {
-    // CHECK: %{{[^ ]+}} = icmp ugt i32 %exp, 6
-    // CHECK: %{{[^ ]+}} = mul nuw {{(nsw )?}}i32 %exp, 5
-    // CHECK: %{{[^ ]+}} = shl nuw {{(nsw )?}}i32 1, %{{[^ ]+}}
-    // CHECK: %{{[^ ]+}} = select i1 {{[^ ]+}}, i32 0, i32 %{{[^ ]+}}
-    // CHECK: ret i32 %{{[^ ]+}}
-    32i32.pow(exp)
-}
-// note: d and e are expected to yield the same IR