about summary refs log tree commit diff
path: root/tests/codegen-llvm/dead_on_return.rs
blob: 3c1940d6ba7c97768f72c3fd113ce0cc1563819c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//@ compile-flags: -C opt-level=3
//@ min-llvm-version: 21

#![crate_type = "lib"]
#![allow(unused_assignments, unused_variables)]

// Check that the old string is deallocated, but a new one is not initialized.
#[unsafe(no_mangle)]
pub fn test_str_new(mut s: String) {
    // CHECK-LABEL: @test_str_new
    // CHECK: __rust_dealloc
    // CHECK-NOT: store
    s = String::new();
}

#[unsafe(no_mangle)]
pub fn test_str_take(mut x: String) -> String {
    // CHECK-LABEL: @test_str_take
    // CHECK-NEXT: {{.*}}:
    // CHECK-NEXT: call void @llvm.memcpy
    // CHECK-NEXT: ret
    core::mem::take(&mut x)
}

#[unsafe(no_mangle)]
pub fn test_array_store(mut x: [u32; 100]) {
    // CHECK-LABEL: @test_array_store
    // CHECK-NEXT: {{.*}}:
    // CHECK-NEXT: ret
    x[0] = 1;
}