2018-10-01 08:13:42 -05:00
|
|
|
// Test that the compiler will catch passing invalid values to inline assembly
|
|
|
|
// operands.
|
|
|
|
|
2019-12-13 21:28:32 -06:00
|
|
|
// build-fail
|
2018-11-02 13:18:19 -05:00
|
|
|
// ignore-emscripten
|
|
|
|
|
2018-10-01 08:13:42 -05:00
|
|
|
#![feature(asm)]
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
struct MyPtr(usize);
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
issue_37433();
|
|
|
|
issue_37437();
|
|
|
|
issue_40187();
|
|
|
|
issue_54067();
|
2018-10-30 16:09:56 -05:00
|
|
|
multiple_errors();
|
2018-10-01 08:13:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_37433() {
|
|
|
|
unsafe {
|
|
|
|
asm!("" :: "r"("")); //~ ERROR E0669
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let target = MyPtr(0);
|
|
|
|
asm!("ret" : : "{rdi}"(target)); //~ ERROR E0669
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_37437() {
|
|
|
|
let hello: &str = "hello";
|
|
|
|
// this should fail...
|
|
|
|
unsafe { asm!("" :: "i"(hello)) }; //~ ERROR E0669
|
|
|
|
// but this should succeed.
|
|
|
|
unsafe { asm!("" :: "r"(hello.as_ptr())) };
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_40187() {
|
|
|
|
let arr: [u8; 1] = [0; 1];
|
|
|
|
unsafe {
|
|
|
|
asm!("movups $1, %xmm0"::"m"(arr)); //~ ERROR E0669
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_54067() {
|
|
|
|
let addr: Option<u32> = Some(123);
|
|
|
|
unsafe {
|
|
|
|
asm!("mov sp, $0"::"r"(addr)); //~ ERROR E0669
|
|
|
|
}
|
|
|
|
}
|
2018-10-30 16:09:56 -05:00
|
|
|
|
|
|
|
fn multiple_errors() {
|
|
|
|
let addr: (u32, u32) = (1, 2);
|
|
|
|
unsafe {
|
|
|
|
asm!("mov sp, $0"::"r"(addr), //~ ERROR E0669
|
|
|
|
"r"("hello e0669")); //~ ERROR E0669
|
|
|
|
}
|
|
|
|
}
|