diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2024-01-11 21:20:15 -0800 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2024-01-12 10:57:58 -0800 |
| commit | b858c591dd85f51bb515f492cfa8a0252339ddb9 (patch) | |
| tree | 6a5c602ab3dc9543bf9d50daf7f697e54f2ef03f /tests/codegen | |
| parent | 62d7ed4a6775c4490e493093ca98ef7c215b835b (diff) | |
| download | rust-b858c591dd85f51bb515f492cfa8a0252339ddb9.tar.gz rust-b858c591dd85f51bb515f492cfa8a0252339ddb9.zip | |
Tune the inlinability of `Result::unwrap`
Diffstat (limited to 'tests/codegen')
| -rw-r--r-- | tests/codegen/infallible-unwrap-in-opt-z.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/codegen/infallible-unwrap-in-opt-z.rs b/tests/codegen/infallible-unwrap-in-opt-z.rs new file mode 100644 index 00000000000..5c57b41532f --- /dev/null +++ b/tests/codegen/infallible-unwrap-in-opt-z.rs @@ -0,0 +1,26 @@ +// compile-flags: -C opt-level=z --edition=2021 +// ignore-debug + +#![crate_type = "lib"] + +// From <https://github.com/rust-lang/rust/issues/115463> + +// CHECK-LABEL: @read_up_to_8( +#[no_mangle] +pub fn read_up_to_8(buf: &[u8]) -> u64 { + // CHECK-NOT: unwrap_failed + if buf.len() < 4 { + // actual instance has more code. + return 0; + } + let lo = u32::from_le_bytes(buf[..4].try_into().unwrap()) as u64; + let hi = u32::from_le_bytes(buf[buf.len() - 4..][..4].try_into().unwrap()) as u64; + lo | (hi << 8 * (buf.len() as u64 - 4)) +} + +// CHECK-LABEL: @checking_unwrap_expectation( +#[no_mangle] +pub fn checking_unwrap_expectation(buf: &[u8]) -> &[u8; 4] { + // CHECK: call void @_ZN4core6result13unwrap_failed17h + buf.try_into().unwrap() +} |
