about summary refs log tree commit diff
path: root/tests/codegen/issues
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-05-22 15:06:32 +0000
committerbors <bors@rust-lang.org>2023-05-22 15:06:32 +0000
commit2fe47b966a8ee689d697583be4182262e7b4fd08 (patch)
tree2933eebcfa9f68a6bff70dab8ad086c7352bc06b /tests/codegen/issues
parent03761a50a3b26daded09e6da79252692c9bbad5f (diff)
parent2a466466c768dc56382550a3130674b2eebe227c (diff)
downloadrust-2fe47b966a8ee689d697583be4182262e7b4fd08.tar.gz
rust-2fe47b966a8ee689d697583be4182262e7b4fd08.zip
Auto merge of #111634 - marc0246:arc-new-uninit-bloat, r=thomcc
Fix duplicate `arcinner_layout_for_value_layout` calls when using the uninit `Arc` constructors

What this fixes is the duplicate calls to `arcinner_layout_for_value_layout` seen here: https://godbolt.org/z/jr5Gxozhj

The issue was discovered alongside #111603 but is otherwise unrelated to the duplicate `alloca`s, which remain unsolved. Everything I tried to solve said main issue has failed.

As for the duplicate layout calculations, I also tried slapping `#[inline]` and `#[inline(always)]` on everything in sight but the only thing that worked in the end is to dedup the calls by hand.
Diffstat (limited to 'tests/codegen/issues')
-rw-r--r--tests/codegen/issues/issue-111603.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/codegen/issues/issue-111603.rs b/tests/codegen/issues/issue-111603.rs
new file mode 100644
index 00000000000..90b3c314d2f
--- /dev/null
+++ b/tests/codegen/issues/issue-111603.rs
@@ -0,0 +1,28 @@
+// compile-flags: -O
+
+#![crate_type = "lib"]
+#![feature(get_mut_unchecked, new_uninit)]
+
+use std::sync::Arc;
+
+// CHECK-LABEL: @new_uninit
+#[no_mangle]
+pub fn new_uninit(x: u64) -> Arc<[u64; 1000]> {
+    // CHECK: call alloc::sync::arcinner_layout_for_value_layout
+    // CHECK-NOT: call alloc::sync::arcinner_layout_for_value_layout
+    let mut arc = Arc::new_uninit();
+    unsafe { Arc::get_mut_unchecked(&mut arc) }.write([x; 1000]);
+    unsafe { arc.assume_init() }
+}
+
+// CHECK-LABEL: @new_uninit_slice
+#[no_mangle]
+pub fn new_uninit_slice(x: u64) -> Arc<[u64]> {
+    // CHECK: call alloc::sync::arcinner_layout_for_value_layout
+    // CHECK-NOT: call alloc::sync::arcinner_layout_for_value_layout
+    let mut arc = Arc::new_uninit_slice(1000);
+    for elem in unsafe { Arc::get_mut_unchecked(&mut arc) } {
+        elem.write(x);
+    }
+    unsafe { arc.assume_init() }
+}