about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoshua Wong <joshuawong@anticentri.st>2024-10-09 14:24:05 -0400
committerJoshua Wong <joshuawong@anticentri.st>2024-10-10 09:47:26 -0400
commit8a1462265f839607f96acea4bed183736598422d (patch)
tree5dba422a8f8bf877566ff3552839d4d775991829
parenta1eceec00b2684f947481696ae2322e20d59db60 (diff)
downloadrust-8a1462265f839607f96acea4bed183736598422d.tar.gz
rust-8a1462265f839607f96acea4bed183736598422d.zip
add initial tests for placement new changes
-rw-r--r--tests/codegen/placement-new.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/codegen/placement-new.rs b/tests/codegen/placement-new.rs
new file mode 100644
index 00000000000..68260a65a3f
--- /dev/null
+++ b/tests/codegen/placement-new.rs
@@ -0,0 +1,27 @@
+//@ compile-flags: -O
+#![crate_type = "lib"]
+
+// Test to check that types with "complex" destructors, but trivial `Default` impls
+// are constructed directly into the allocation in `Box::default` and `Arc::default`.
+
+use std::sync::Arc;
+
+// CHECK-LABEL: @box_default_inplace
+#[no_mangle]
+pub fn box_default_inplace() -> Box<(String, String)> {
+    // CHECK: [[ALLOCA:%.*]] = alloca
+    // CHECK: [[BOX:%.*]] = {{.*}}call {{.*}}__rust_alloc(
+    // CHECK: call void @llvm.memcpy{{.*}}(ptr {{.*}}[[BOX]], ptr {{.*}}[[ALLOCA]]
+    // CHECK: ret ptr [[BOX]]
+    Box::default()
+}
+
+// CHECK-LABEL: @arc_default_inplace
+#[no_mangle]
+pub fn arc_default_inplace() -> Arc<(String, String)> {
+    // CHECK: [[ALLOCA:%.*]] = alloca
+    // CHECK: [[ARC:%.*]] = {{.*}}call {{.*}}__rust_alloc(
+    // CHECK: call void @llvm.memcpy
+    // CHECK: ret ptr [[ARC]]
+    Arc::default()
+}