]> git.lizzy.rs Git - rust.git/blob - src/test/ui/inline-asm-bad-operand.rs
Rollup merge of #55734 - teresy:shorthand-fields, r=davidtwco
[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 #![feature(asm)]
15
16 #[repr(C)]
17 struct MyPtr(usize);
18
19 fn main() {
20     issue_37433();
21     issue_37437();
22     issue_40187();
23     issue_54067();
24     multiple_errors();
25 }
26
27 fn issue_37433() {
28     unsafe {
29         asm!("" :: "r"("")); //~ ERROR E0669
30     }
31
32     unsafe {
33         let target = MyPtr(0);
34         asm!("ret" : : "{rdi}"(target)); //~ ERROR E0669
35     }
36 }
37
38 fn issue_37437() {
39     let hello: &str = "hello";
40     // this should fail...
41     unsafe { asm!("" :: "i"(hello)) }; //~ ERROR E0669
42     // but this should succeed.
43     unsafe { asm!("" :: "r"(hello.as_ptr())) };
44 }
45
46 fn issue_40187() {
47     let arr: [u8; 1] = [0; 1];
48     unsafe {
49         asm!("movups $1, %xmm0"::"m"(arr)); //~ ERROR E0669
50     }
51 }
52
53 fn issue_54067() {
54     let addr: Option<u32> = Some(123);
55     unsafe {
56         asm!("mov sp, $0"::"r"(addr)); //~ ERROR E0669
57     }
58 }
59
60 fn multiple_errors() {
61     let addr: (u32, u32) = (1, 2);
62     unsafe {
63         asm!("mov sp, $0"::"r"(addr), //~ ERROR E0669
64                            "r"("hello e0669")); //~ ERROR E0669
65     }
66 }