Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 820bba1

Browse files
committed
Add codegen test for multiple asm! options
1 parent 27cc7c7 commit 820bba1

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// compile-flags: -O
2+
// only-x86_64
3+
4+
#![crate_type = "rlib"]
5+
#![feature(asm)]
6+
7+
// CHECK-LABEL: @pure
8+
// CHECK-NOT: asm
9+
// CHECK: ret void
10+
#[no_mangle]
11+
pub unsafe fn pure(x: i32) {
12+
let y: i32;
13+
asm!("", out("ax") y, in("bx") x, options(pure), options(nomem));
14+
}
15+
16+
pub static mut VAR: i32 = 0;
17+
pub static mut DUMMY_OUTPUT: i32 = 0;
18+
19+
// CHECK-LABEL: @readonly
20+
// CHECK: call i32 asm
21+
// CHECK: ret i32 1
22+
#[no_mangle]
23+
pub unsafe fn readonly() -> i32 {
24+
VAR = 1;
25+
asm!("", out("ax") DUMMY_OUTPUT, options(pure), options(readonly));
26+
VAR
27+
}
28+
29+
// CHECK-LABEL: @nomem
30+
// CHECK-NOT: store
31+
// CHECK: call i32 asm
32+
// CHECK: store
33+
// CHECK: ret i32 2
34+
#[no_mangle]
35+
pub unsafe fn nomem() -> i32 {
36+
VAR = 1;
37+
asm!("", out("ax") DUMMY_OUTPUT, options(pure), options(nomem));
38+
VAR = 2;
39+
VAR
40+
}
41+
42+
// CHECK-LABEL: @not_nomem
43+
// CHECK: store
44+
// CHECK: call i32 asm
45+
// CHECK: store
46+
// CHECK: ret i32 2
47+
#[no_mangle]
48+
pub unsafe fn not_nomem() -> i32 {
49+
VAR = 1;
50+
asm!("", out("ax") DUMMY_OUTPUT, options(pure), options(readonly));
51+
VAR = 2;
52+
VAR
53+
}

0 commit comments

Comments
 (0)