2020-05-26 19:07:59 +00:00
|
|
|
// only-x86_64
|
|
|
|
// build-fail
|
2021-03-20 00:00:00 +00:00
|
|
|
// compile-flags: -Ccodegen-units=1
|
2021-12-10 00:15:33 +00:00
|
|
|
|
|
|
|
use std::arch::asm;
|
2020-05-26 19:07:59 +00:00
|
|
|
|
|
|
|
// Checks that inline asm errors are mapped to the correct line in the source code.
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
unsafe {
|
|
|
|
asm!("invalid_instruction");
|
|
|
|
//~^ ERROR: invalid instruction mnemonic 'invalid_instruction'
|
|
|
|
|
|
|
|
asm!("
|
|
|
|
invalid_instruction
|
|
|
|
");
|
|
|
|
//~^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
|
|
|
|
|
|
|
|
asm!(r#"
|
|
|
|
invalid_instruction
|
|
|
|
"#);
|
|
|
|
//~^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
|
|
|
|
|
|
|
|
asm!("
|
|
|
|
mov eax, eax
|
|
|
|
invalid_instruction
|
|
|
|
mov eax, eax
|
|
|
|
");
|
|
|
|
//~^^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
|
|
|
|
|
|
|
|
asm!(r#"
|
|
|
|
mov eax, eax
|
|
|
|
invalid_instruction
|
|
|
|
mov eax, eax
|
|
|
|
"#);
|
|
|
|
//~^^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
|
|
|
|
|
|
|
|
asm!(concat!("invalid", "_", "instruction"));
|
|
|
|
//~^ ERROR: invalid instruction mnemonic 'invalid_instruction'
|
2020-06-09 13:37:59 +00:00
|
|
|
|
|
|
|
asm!("movaps %xmm3, (%esi, 2)", options(att_syntax));
|
|
|
|
//~^ WARN: scale factor without index register is ignored
|
asm: Allow multiple template strings; interpret them as newline-separated
Allow the `asm!` macro to accept a series of template arguments, and
interpret them as if they were concatenated with a '\n' between them.
This allows writing an `asm!` where each line of assembly appears in a
separate template string argument.
This syntax makes it possible for rustfmt to reliably format and indent
each line of assembly, without risking changes to the inside of a
template string. It also avoids the complexity of having the user
carefully format and indent a multi-line string (including where to put
the surrounding quotes), and avoids the extra indentation and lines of a
call to `concat!`.
For example, rewriting the second example from the [blog post on the new
inline assembly
syntax](https://blog.rust-lang.org/inside-rust/2020/06/08/new-inline-asm.html)
using multiple template strings:
```rust
fn main() {
let mut bits = [0u8; 64];
for value in 0..=1024u64 {
let popcnt;
unsafe {
asm!(
" popcnt {popcnt}, {v}",
"2:",
" blsi rax, {v}",
" jz 1f",
" xor {v}, rax",
" tzcnt rax, rax",
" stosb",
" jmp 2b",
"1:",
v = inout(reg) value => _,
popcnt = out(reg) popcnt,
out("rax") _, // scratch
inout("rdi") bits.as_mut_ptr() => _,
);
}
println!("bits of {}: {:?}", value, &bits[0..popcnt]);
}
}
```
Note that all the template strings must appear before all other
arguments; you cannot, for instance, provide a series of template
strings intermixed with the corresponding operands.
In order to get srcloc mappings right for macros that generate
multi-line string literals, create one line_span for each
line in the string literal, each pointing to the macro.
Make `rustc_parse_format::Parser::curarg` `pub`, so that we can
propagate it from one template string argument to the next.
2020-06-15 06:33:55 +00:00
|
|
|
|
|
|
|
asm!(
|
|
|
|
"invalid_instruction",
|
|
|
|
);
|
|
|
|
//~^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
|
|
|
|
|
|
|
|
asm!(
|
|
|
|
"mov eax, eax",
|
|
|
|
"invalid_instruction",
|
|
|
|
"mov eax, eax",
|
|
|
|
);
|
|
|
|
//~^^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
|
|
|
|
|
|
|
|
asm!(
|
|
|
|
"mov eax, eax\n",
|
|
|
|
"invalid_instruction",
|
|
|
|
"mov eax, eax",
|
|
|
|
);
|
|
|
|
//~^^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
|
|
|
|
|
|
|
|
asm!(
|
|
|
|
"mov eax, eax",
|
|
|
|
concat!("invalid", "_", "instruction"),
|
|
|
|
"mov eax, eax",
|
|
|
|
);
|
|
|
|
//~^^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
|
|
|
|
|
|
|
|
asm!(
|
|
|
|
concat!("mov eax", ", ", "eax"),
|
|
|
|
concat!("invalid", "_", "instruction"),
|
|
|
|
concat!("mov eax", ", ", "eax"),
|
|
|
|
);
|
|
|
|
//~^^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
|
|
|
|
|
|
|
|
// Make sure template strings get separated
|
|
|
|
asm!(
|
|
|
|
"invalid_instruction1",
|
|
|
|
"invalid_instruction2",
|
|
|
|
);
|
|
|
|
//~^^^ ERROR: invalid instruction mnemonic 'invalid_instruction1'
|
|
|
|
//~^^^ ERROR: invalid instruction mnemonic 'invalid_instruction2'
|
|
|
|
|
|
|
|
asm!(
|
|
|
|
concat!(
|
|
|
|
"invalid", "_", "instruction1", "\n",
|
|
|
|
"invalid", "_", "instruction2",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
//~^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction1'
|
|
|
|
//~^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction2'
|
|
|
|
|
|
|
|
asm!(
|
|
|
|
concat!(
|
|
|
|
"invalid", "_", "instruction1", "\n",
|
|
|
|
"invalid", "_", "instruction2",
|
|
|
|
),
|
|
|
|
concat!(
|
|
|
|
"invalid", "_", "instruction3", "\n",
|
|
|
|
"invalid", "_", "instruction4",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
//~^^^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction1'
|
|
|
|
//~^^^^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction2'
|
|
|
|
//~^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction3'
|
|
|
|
//~^^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction4'
|
|
|
|
|
|
|
|
asm!(
|
|
|
|
concat!(
|
|
|
|
"invalid", "_", "instruction1", "\n",
|
|
|
|
"invalid", "_", "instruction2", "\n",
|
|
|
|
),
|
|
|
|
concat!(
|
|
|
|
"invalid", "_", "instruction3", "\n",
|
|
|
|
"invalid", "_", "instruction4", "\n",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
//~^^^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction1'
|
|
|
|
//~^^^^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction2'
|
|
|
|
//~^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction3'
|
|
|
|
//~^^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction4'
|
2022-07-12 20:54:47 +00:00
|
|
|
|
|
|
|
asm!(
|
|
|
|
"",
|
|
|
|
"\n",
|
|
|
|
"invalid_instruction"
|
|
|
|
);
|
|
|
|
//~^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
|
2020-05-26 19:07:59 +00:00
|
|
|
}
|
|
|
|
}
|