]> git.lizzy.rs Git - rust.git/blob - src/test/ui/inline-asm-bad-operand.rs
rustdoc: Fix handling of compile errors when running `rustdoc --test`
[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 // build-fail
5 // ignore-emscripten
6
7 #![feature(asm)]
8
9 #[repr(C)]
10 struct MyPtr(usize);
11
12 fn main() {
13     issue_37433();
14     issue_37437();
15     issue_40187();
16     issue_54067();
17     multiple_errors();
18 }
19
20 fn issue_37433() {
21     unsafe {
22         asm!("" :: "r"("")); //~ ERROR E0669
23     }
24
25     unsafe {
26         let target = MyPtr(0);
27         asm!("ret" : : "{rdi}"(target)); //~ ERROR E0669
28     }
29 }
30
31 fn issue_37437() {
32     let hello: &str = "hello";
33     // this should fail...
34     unsafe { asm!("" :: "i"(hello)) }; //~ ERROR E0669
35     // but this should succeed.
36     unsafe { asm!("" :: "r"(hello.as_ptr())) };
37 }
38
39 fn issue_40187() {
40     let arr: [u8; 1] = [0; 1];
41     unsafe {
42         asm!("movups $1, %xmm0"::"m"(arr)); //~ ERROR E0669
43     }
44 }
45
46 fn issue_54067() {
47     let addr: Option<u32> = Some(123);
48     unsafe {
49         asm!("mov sp, $0"::"r"(addr)); //~ ERROR E0669
50     }
51 }
52
53 fn multiple_errors() {
54     let addr: (u32, u32) = (1, 2);
55     unsafe {
56         asm!("mov sp, $0"::"r"(addr), //~ ERROR E0669
57                            "r"("hello e0669")); //~ ERROR E0669
58     }
59 }