about summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-01-19 08:04:26 +0000
committerbors <bors@rust-lang.org>2023-01-19 08:04:26 +0000
commit705a96d39bbd97ac0cc8ae119b0f3c097ab62fc0 (patch)
treee150d8f5821c55d5d84905ee20560b9aba175264 /tests/codegen
parent65d2f2a5f9c323c88d1068e8e90d0b47a20d491c (diff)
parent50e9f2e6e87911659b6ae63230a5797f4cdf28e1 (diff)
downloadrust-705a96d39bbd97ac0cc8ae119b0f3c097ab62fc0.tar.gz
rust-705a96d39bbd97ac0cc8ae119b0f3c097ab62fc0.zip
Auto merge of #106989 - clubby789:is-zero-num, r=scottmcm
Implement `alloc::vec::IsZero` for `Option<$NUM>` types

Fixes #106911

Mirrors the `NonZero$NUM` implementations with an additional `assert_zero_valid`.
`None::<i32>` doesn't stricly satisfy `IsZero` but for the purpose of allocating we can produce more efficient codegen.
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/vec-calloc.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/codegen/vec-calloc.rs b/tests/codegen/vec-calloc.rs
index 442cdd41dc6..4481a9d1e99 100644
--- a/tests/codegen/vec-calloc.rs
+++ b/tests/codegen/vec-calloc.rs
@@ -161,6 +161,23 @@ pub fn vec_option_bool(n: usize) -> Vec<Option<bool>> {
     vec![Some(false); n]
 }
 
+// CHECK-LABEL: @vec_option_i32
+#[no_mangle]
+pub fn vec_option_i32(n: usize) -> Vec<Option<i32>> {
+    // CHECK-NOT: call {{.*}}alloc::vec::from_elem
+    // CHECK-NOT: call {{.*}}reserve
+    // CHECK-NOT: call {{.*}}__rust_alloc(
+
+    // CHECK: call {{.*}}__rust_alloc_zeroed(
+
+    // CHECK-NOT: call {{.*}}alloc::vec::from_elem
+    // CHECK-NOT: call {{.*}}reserve
+    // CHECK-NOT: call {{.*}}__rust_alloc(
+
+    // CHECK: ret void
+    vec![None; n]
+}
+
 // Ensure that __rust_alloc_zeroed gets the right attributes for LLVM to optimize it away.
 // CHECK: declare noalias noundef ptr @__rust_alloc_zeroed(i64 noundef, i64 allocalign noundef) unnamed_addr [[RUST_ALLOC_ZEROED_ATTRS:#[0-9]+]]