]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #106989 - clubby789:is-zero-num, r=scottmcm
authorbors <bors@rust-lang.org>
Thu, 19 Jan 2023 08:04:26 +0000 (08:04 +0000)
committerbors <bors@rust-lang.org>
Thu, 19 Jan 2023 08:04:26 +0000 (08:04 +0000)
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.

1  2 
tests/codegen/vec-calloc.rs

index 442cdd41dc66f866258aa800148300a571f300ed,9cc5bd4fd1a997789be548567c4d671031606c5f..4481a9d1e9983c0991c63f58bb6c23ecad1b3d00
@@@ -161,7 -161,24 +161,24 @@@ pub fn vec_option_bool(n: usize) -> Vec
      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 ptr @__rust_alloc_zeroed(i64, i64 allocalign) unnamed_addr [[RUST_ALLOC_ZEROED_ATTRS:#[0-9]+]]
 +// CHECK: declare noalias noundef ptr @__rust_alloc_zeroed(i64 noundef, i64 allocalign noundef) unnamed_addr [[RUST_ALLOC_ZEROED_ATTRS:#[0-9]+]]
  
  // CHECK-DAG: attributes [[RUST_ALLOC_ZEROED_ATTRS]] = { {{.*}} allockind("alloc,zeroed,aligned") allocsize(0) uwtable "alloc-family"="__rust_alloc" {{.*}} }