2022-12-22 20:18:30 +09:00
|
|
|
// min-llvm-version: 15.0
|
2023-04-05 21:15:32 +02:00
|
|
|
// only-64bit llvm appears to use stores instead of memset on 32bit
|
2023-01-07 19:03:07 +09:00
|
|
|
// compile-flags: -C opt-level=3 -Z merge-functions=disabled
|
2022-12-22 20:18:30 +09:00
|
|
|
|
|
|
|
// The below two functions ensure that both `String::new()` and `"".to_string()`
|
|
|
|
// produce the identical code.
|
|
|
|
|
|
|
|
#![crate_type = "lib"]
|
|
|
|
|
2023-01-07 19:03:07 +09:00
|
|
|
// CHECK-LABEL: define void @string_new
|
2022-12-22 20:18:30 +09:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn string_new() -> String {
|
2023-02-16 01:49:00 +01:00
|
|
|
// CHECK: store ptr inttoptr
|
2023-01-07 19:03:07 +09:00
|
|
|
// CHECK-NEXT: getelementptr
|
2023-02-16 01:49:00 +01:00
|
|
|
// CHECK-NEXT: call void @llvm.memset
|
2023-01-07 19:03:07 +09:00
|
|
|
// CHECK-NEXT: ret void
|
2022-12-22 20:18:30 +09:00
|
|
|
String::new()
|
|
|
|
}
|
|
|
|
|
2022-12-22 20:45:36 +09:00
|
|
|
// CHECK-LABEL: define void @empty_to_string
|
2022-12-22 20:18:30 +09:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn empty_to_string() -> String {
|
2023-04-05 21:15:32 +02:00
|
|
|
// CHECK: store ptr inttoptr
|
|
|
|
// CHECK-NEXT: getelementptr
|
2023-02-16 01:49:00 +01:00
|
|
|
// CHECK-NEXT: call void @llvm.memset
|
2022-12-22 20:18:30 +09:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
"".to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
// The below two functions ensure that both `vec![]` and `vec![].clone()`
|
|
|
|
// produce the identical code.
|
|
|
|
|
|
|
|
// CHECK-LABEL: @empty_vec
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn empty_vec() -> Vec<u8> {
|
2023-02-16 01:49:00 +01:00
|
|
|
// CHECK: store ptr inttoptr
|
2022-12-22 20:18:30 +09:00
|
|
|
// CHECK-NEXT: getelementptr
|
2023-02-16 01:49:00 +01:00
|
|
|
// CHECK-NEXT: call void @llvm.memset
|
2022-12-22 20:18:30 +09:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
vec![]
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @empty_vec_clone
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn empty_vec_clone() -> Vec<u8> {
|
2023-02-16 01:49:00 +01:00
|
|
|
// CHECK: store ptr inttoptr
|
2022-12-22 20:18:30 +09:00
|
|
|
// CHECK-NEXT: getelementptr
|
2023-02-16 01:49:00 +01:00
|
|
|
// CHECK-NEXT: call void @llvm.memset
|
2022-12-22 20:18:30 +09:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
vec![].clone()
|
|
|
|
}
|