Skip to content

Commit 80faf20

Browse files
committed
add test for Box::default's stack usage in debug mode
1 parent 2f0ad2a commit 80faf20

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ compile-flags: -Copt-level=0
2+
3+
// Test to make sure that `<Box<T>>::default` does not create too many copies of `T` on the stack.
4+
// in debug mode. This regressed in dd0620b86721ae8cae86736443acd3f72ba6fc32 to
5+
// four `T` allocas.
6+
//
7+
// See https://github.com/rust-lang/rust/issues/136043 for more context.
8+
9+
#![crate_type = "lib"]
10+
11+
#[allow(dead_code)]
12+
pub struct Thing([u8; 1000000]);
13+
14+
impl Default for Thing {
15+
fn default() -> Self {
16+
Thing([0; 1000000])
17+
}
18+
}
19+
20+
// CHECK-COUNT-4: %{{.*}} = alloca {{.*}}1000000
21+
// CHECK-NOT: %{{.*}} = alloca {{.*}}1000000
22+
#[no_mangle]
23+
pub fn box_default_single_copy() -> Box<Thing> {
24+
Box::default()
25+
}

0 commit comments

Comments
 (0)