rust/tests/codegen/issues/issue-112509-slice-get-andthen-get.rs

17 lines
480 B
Rust
Raw Normal View History

2024-05-20 13:38:45 -05:00
//@ compile-flags: -O
#![crate_type = "lib"]
// CHECK-LABEL: @write_u8_variant_a
// CHECK-NEXT: {{.*}}:
2024-05-20 13:38:45 -05:00
// CHECK-NEXT: icmp ugt
// CHECK-NEXT: getelementptr
// CHECK-NEXT: select i1 {{.+}} null
// CHECK-NEXT: insertvalue
// CHECK-NEXT: insertvalue
// CHECK-NEXT: ret
2024-05-20 13:38:45 -05:00
#[no_mangle]
pub fn write_u8_variant_a(bytes: &mut [u8], buf: u8, offset: usize) -> Option<&mut [u8]> {
2024-05-20 13:38:45 -05:00
let buf = buf.to_le_bytes();
bytes.get_mut(offset..).and_then(|bytes| bytes.get_mut(..buf.len()))
2024-05-20 13:38:45 -05:00
}