-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #98377 - davidv1992:add-lifetimes-to-argument-temporari…
…es, r=oli-obk Added llvm lifetime annotations to function call argument temporaries. The goal of this change is to ensure that llvm will do stack slot optimization on these temporaries. This ensures that in code like: ```rust const A: [u8; 1024] = [0; 1024]; fn copy_const() { f(A); f(A); } ``` we only use 1024 bytes of stack space, instead of 2048 bytes. I am new to developing for the rust compiler, and as such not entirely sure, but I believe this should be sufficient to close #98156. Also, this does not contain a test case to ensure this keeps working, primarily because I am not sure how to go about testing this. I would love some suggestions as to how that could be approached.
- Loading branch information
Showing
2 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// This test checks that temporaries for indirectly-passed arguments get lifetime markers. | ||
|
||
// compile-flags: -O -C no-prepopulate-passes -Zmir-opt-level=0 | ||
|
||
#![crate_type = "lib"] | ||
|
||
extern "Rust" { | ||
fn f(x: [u8; 1024]); | ||
} | ||
|
||
const A: [u8; 1024] = [0; 1024]; | ||
|
||
// CHECK-LABEL: @const_arg_indirect | ||
#[no_mangle] | ||
pub unsafe fn const_arg_indirect() { | ||
// Ensure that the live ranges for the two argument temporaries don't overlap. | ||
|
||
// CHECK: call void @llvm.lifetime.start | ||
// CHECK: call void @f | ||
// CHECK: call void @llvm.lifetime.end | ||
// CHECK: call void @llvm.lifetime.start | ||
// CHECK: call void @f | ||
// CHECK: call void @llvm.lifetime.end | ||
|
||
f(A); | ||
f(A); | ||
} |