Auto merge of #121298 - nikic:writable, r=cuviper
Set writable and dead_on_unwind attributes for sret arguments Set the `writable` and `dead_on_unwind` attributes for `sret` arguments. This allows call slot optimization to remove more memcpy's. See https://llvm.org/docs/LangRef.html#parameter-attributes for the specification of these attributes. In short, the statement we're making here is that: * The return slot is writable. * The return slot will not be read if the function unwinds. Fixes https://github.com/rust-lang/rust/issues/90595.
This commit is contained in:
commit
284f94f9c0
7 changed files with 33 additions and 4 deletions
|
@ -197,7 +197,7 @@ pub fn notunpin_box(x: Box<NotUnpin>) -> Box<NotUnpin> {
|
|||
x
|
||||
}
|
||||
|
||||
// CHECK: @struct_return(ptr noalias nocapture noundef sret([32 x i8]) align 4 dereferenceable(32){{( %_0)?}})
|
||||
// CHECK: @struct_return(ptr{{( dead_on_unwind)?}} noalias nocapture noundef{{( writable)?}} sret([32 x i8]) align 4 dereferenceable(32){{( %_0)?}})
|
||||
#[no_mangle]
|
||||
pub fn struct_return() -> S {
|
||||
S {
|
||||
|
|
|
@ -260,7 +260,7 @@ pub struct IntDoubleInt {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn f_int_double_int_s_arg(a: IntDoubleInt) {}
|
||||
|
||||
// CHECK: define void @f_ret_int_double_int_s(ptr noalias nocapture noundef sret([24 x i8]) align 8 dereferenceable(24) %_0)
|
||||
// CHECK: define void @f_ret_int_double_int_s(ptr{{( dead_on_unwind)?}} noalias nocapture noundef{{( writable)?}} sret([24 x i8]) align 8 dereferenceable(24) %_0)
|
||||
#[no_mangle]
|
||||
pub extern "C" fn f_ret_int_double_int_s() -> IntDoubleInt {
|
||||
IntDoubleInt { a: 1, b: 2., c: 3 }
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
//@ compile-flags: -O
|
||||
//@ needs-unwind
|
||||
//@ min-llvm-version: 18
|
||||
#![feature(c_unwind)]
|
||||
#![crate_type = "lib"]
|
||||
|
||||
|
@ -23,8 +25,8 @@ extern "C-unwind" {
|
|||
}
|
||||
|
||||
pub fn new_from_uninit_unwind() -> Foo {
|
||||
// CHECK-LABEL: new_from_uninit
|
||||
// CHECK: call void @llvm.memcpy.
|
||||
// CHECK-LABEL: new_from_uninit_unwind
|
||||
// CHECK-NOT: call void @llvm.memcpy.
|
||||
let mut x = std::mem::MaybeUninit::uninit();
|
||||
unsafe {
|
||||
init_unwind(x.as_mut_ptr());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue