]> git.lizzy.rs Git - rust.git/blob - src/test/ui/inline-asm-bad-operand.rs
Auto merge of #60065 - QuietMisdreavus:async-move-doctests, r=ollie27
[rust.git] / src / test / ui / inline-asm-bad-operand.rs
1 // Test that the compiler will catch passing invalid values to inline assembly
2 // operands.
3
4 // ignore-emscripten
5
6 #![feature(asm)]
7
8 #[repr(C)]
9 struct MyPtr(usize);
10
11 fn main() {
12     issue_37433();
13     issue_37437();
14     issue_40187();
15     issue_54067();
16     multiple_errors();
17 }
18
19 fn issue_37433() {
20     unsafe {
21         asm!("" :: "r"("")); //~ ERROR E0669
22     }
23
24     unsafe {
25         let target = MyPtr(0);
26         asm!("ret" : : "{rdi}"(target)); //~ ERROR E0669
27     }
28 }
29
30 fn issue_37437() {
31     let hello: &str = "hello";
32     // this should fail...
33     unsafe { asm!("" :: "i"(hello)) }; //~ ERROR E0669
34     // but this should succeed.
35     unsafe { asm!("" :: "r"(hello.as_ptr())) };
36 }
37
38 fn issue_40187() {
39     let arr: [u8; 1] = [0; 1];
40     unsafe {
41         asm!("movups $1, %xmm0"::"m"(arr)); //~ ERROR E0669
42     }
43 }
44
45 fn issue_54067() {
46     let addr: Option<u32> = Some(123);
47     unsafe {
48         asm!("mov sp, $0"::"r"(addr)); //~ ERROR E0669
49     }
50 }
51
52 fn multiple_errors() {
53     let addr: (u32, u32) = (1, 2);
54     unsafe {
55         asm!("mov sp, $0"::"r"(addr), //~ ERROR E0669
56                            "r"("hello e0669")); //~ ERROR E0669
57     }
58 }