summaryrefslogtreecommitdiffstats
path: root/src/test/codegen/asm-options.rs
blob: 963b60cfe35b706b9c34baf64f3e61f2ceac3941 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// compile-flags: -O
// only-x86_64

#![crate_type = "rlib"]

use std::arch::asm;

// CHECK-LABEL: @pure
// CHECK-NOT: asm
// CHECK: ret void
#[no_mangle]
pub unsafe fn pure(x: i32) {
    let y: i32;
    asm!("", out("ax") y, in("cx") x, options(pure, nomem));
}

// CHECK-LABEL: @noreturn
// CHECK: call void asm
// CHECK-NEXT: unreachable
#[no_mangle]
pub unsafe fn noreturn() {
    asm!("", options(noreturn));
}

pub static mut VAR: i32 = 0;
pub static mut DUMMY_OUTPUT: i32 = 0;

// CHECK-LABEL: @readonly
// CHECK: call i32 asm
// CHECK: ret i32 1
#[no_mangle]
pub unsafe fn readonly() -> i32 {
    VAR = 1;
    asm!("", out("ax") DUMMY_OUTPUT, options(pure, readonly));
    VAR
}

// CHECK-LABEL: @not_readonly
// CHECK: call i32 asm
// CHECK: ret i32 %
#[no_mangle]
pub unsafe fn not_readonly() -> i32 {
    VAR = 1;
    asm!("", out("ax") DUMMY_OUTPUT, options());
    VAR
}

// CHECK-LABEL: @nomem
// CHECK-NOT: store
// CHECK: call i32 asm
// CHECK: store
// CHECK: ret i32 2
#[no_mangle]
pub unsafe fn nomem() -> i32 {
    VAR = 1;
    asm!("", out("ax") DUMMY_OUTPUT, options(pure, nomem));
    VAR = 2;
    VAR
}

// CHECK-LABEL: @nomem_nopure
// CHECK-NOT: store
// CHECK: call i32 asm
// CHECK: store
// CHECK: ret i32 2
#[no_mangle]
pub unsafe fn nomem_nopure() -> i32 {
    VAR = 1;
    asm!("", out("ax") DUMMY_OUTPUT, options(nomem));
    VAR = 2;
    VAR
}

// CHECK-LABEL: @not_nomem
// CHECK: store
// CHECK: call i32 asm
// CHECK: store
// CHECK: ret i32 2
#[no_mangle]
pub unsafe fn not_nomem() -> i32 {
    VAR = 1;
    asm!("", out("ax") DUMMY_OUTPUT, options(pure, readonly));
    VAR = 2;
    VAR
}

// CHECK-LABEL: @dont_remove_nonpure
// CHECK: call void asm
// CHECK: call void asm
// CHECK: call void asm
// CHECK: ret void
#[no_mangle]
pub unsafe fn dont_remove_nonpure() {
    asm!("", options());
    asm!("", options(nomem));
    asm!("", options(readonly));
}

// CHECK-LABEL: @raw
// CHECK: call void asm sideeffect inteldialect "{} {}", ""()
#[no_mangle]
pub unsafe fn raw() {
    asm!("{} {}", options(nostack, nomem, preserves_flags, raw));
}