]> git.lizzy.rs Git - rust.git/blob - src/test/ui/inline-asm-bad-operand.rs
Auto merge of #55626 - nikic:update-emscripten, r=alexcrichton
[rust.git] / src / test / ui / inline-asm-bad-operand.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Test that the compiler will catch passing invalid values to inline assembly
12 // operands.
13
14 // ignore-emscripten
15
16 #![feature(asm)]
17
18 #[repr(C)]
19 struct MyPtr(usize);
20
21 fn main() {
22     issue_37433();
23     issue_37437();
24     issue_40187();
25     issue_54067();
26     multiple_errors();
27 }
28
29 fn issue_37433() {
30     unsafe {
31         asm!("" :: "r"("")); //~ ERROR E0669
32     }
33
34     unsafe {
35         let target = MyPtr(0);
36         asm!("ret" : : "{rdi}"(target)); //~ ERROR E0669
37     }
38 }
39
40 fn issue_37437() {
41     let hello: &str = "hello";
42     // this should fail...
43     unsafe { asm!("" :: "i"(hello)) }; //~ ERROR E0669
44     // but this should succeed.
45     unsafe { asm!("" :: "r"(hello.as_ptr())) };
46 }
47
48 fn issue_40187() {
49     let arr: [u8; 1] = [0; 1];
50     unsafe {
51         asm!("movups $1, %xmm0"::"m"(arr)); //~ ERROR E0669
52     }
53 }
54
55 fn issue_54067() {
56     let addr: Option<u32> = Some(123);
57     unsafe {
58         asm!("mov sp, $0"::"r"(addr)); //~ ERROR E0669
59     }
60 }
61
62 fn multiple_errors() {
63     let addr: (u32, u32) = (1, 2);
64     unsafe {
65         asm!("mov sp, $0"::"r"(addr), //~ ERROR E0669
66                            "r"("hello e0669")); //~ ERROR E0669
67     }
68 }