Add tests for global_asm!

This commit is contained in:
Amanieu d'Antras 2021-04-13 18:11:11 +01:00
parent 5918ee4317
commit 5a229e0e20
20 changed files with 455 additions and 32 deletions

View File

@ -0,0 +1,14 @@
// min-llvm-version: 10.0.1
// only-x86_64
// assembly-output: emit-asm
// compile-flags: -C llvm-args=--x86-asm-syntax=intel
#![feature(asm, global_asm)]
#![crate_type = "rlib"]
// CHECK: mov eax, eax
global_asm!("mov eax, eax");
// CHECK: mov ebx, 5
global_asm!("mov ebx, {}", const 5);
// CHECK: mov ecx, 5
global_asm!("movl ${}, %ecx", const 5, options(att_syntax));

View File

@ -8,6 +8,10 @@
macro_rules! asm {
() => {};
}
#[rustc_builtin_macro]
macro_rules! global_asm {
() => {};
}
#[lang = "sized"]
trait Sized {}
@ -17,3 +21,6 @@ fn main() {
//~^ ERROR asm! is unsupported on this target
}
}
global_asm!("");
//~^ ERROR asm! is unsupported on this target

View File

@ -1,8 +1,16 @@
error[E0472]: asm! is unsupported on this target
--> $DIR/bad-arch.rs:16:9
--> $DIR/bad-arch.rs:20:9
|
LL | asm!("");
| ^^^^^^^^^
error: aborting due to previous error
error[E0472]: asm! is unsupported on this target
--> $DIR/bad-arch.rs:25:1
|
LL | global_asm!("");
| ^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors

View File

@ -1,6 +1,6 @@
// only-x86_64
#![feature(asm)]
#![feature(asm, global_asm)]
fn main() {
let mut foo = 0;
@ -16,3 +16,16 @@ fn main() {
//~^ ERROR asm outputs are not allowed with the `noreturn` option
}
}
global_asm!("", options(nomem));
//~^ ERROR expected one of
global_asm!("", options(readonly));
//~^ ERROR expected one of
global_asm!("", options(noreturn));
//~^ ERROR expected one of
global_asm!("", options(pure));
//~^ ERROR expected one of
global_asm!("", options(nostack));
//~^ ERROR expected one of
global_asm!("", options(preserves_flags));
//~^ ERROR expected one of

View File

@ -28,5 +28,41 @@ error: asm outputs are not allowed with the `noreturn` option
LL | asm!("{}", out(reg) foo, options(noreturn));
| ^^^^^^^^^^^^
error: aborting due to 5 previous errors
error: expected one of `)` or `att_syntax`, found `nomem`
--> $DIR/bad-options.rs:20:25
|
LL | global_asm!("", options(nomem));
| ^^^^^ expected one of `)` or `att_syntax`
error: expected one of `)` or `att_syntax`, found `readonly`
--> $DIR/bad-options.rs:22:25
|
LL | global_asm!("", options(readonly));
| ^^^^^^^^ expected one of `)` or `att_syntax`
error: expected one of `)` or `att_syntax`, found `noreturn`
--> $DIR/bad-options.rs:24:25
|
LL | global_asm!("", options(noreturn));
| ^^^^^^^^ expected one of `)` or `att_syntax`
error: expected one of `)` or `att_syntax`, found `pure`
--> $DIR/bad-options.rs:26:25
|
LL | global_asm!("", options(pure));
| ^^^^ expected one of `)` or `att_syntax`
error: expected one of `)` or `att_syntax`, found `nostack`
--> $DIR/bad-options.rs:28:25
|
LL | global_asm!("", options(nostack));
| ^^^^^^^ expected one of `)` or `att_syntax`
error: expected one of `)` or `att_syntax`, found `preserves_flags`
--> $DIR/bad-options.rs:30:25
|
LL | global_asm!("", options(preserves_flags));
| ^^^^^^^^^^^^^^^ expected one of `)` or `att_syntax`
error: aborting due to 11 previous errors

View File

@ -1,6 +1,6 @@
// only-x86_64
#![feature(asm)]
#![feature(asm, global_asm)]
fn main() {
let mut foo = 0;
@ -26,3 +26,22 @@ fn main() {
//~^ ERROR multiple unused asm arguments
}
}
const FOO: i32 = 1;
global_asm!("{}");
//~^ ERROR invalid reference to argument at index 0
global_asm!("{1}", const FOO);
//~^ ERROR invalid reference to argument at index 1
//~^^ ERROR argument never used
global_asm!("{a}");
//~^ ERROR there is no argument named `a`
global_asm!("{}", a = const FOO);
//~^ ERROR invalid reference to argument at index 0
//~^^ ERROR argument never used
global_asm!("{1}", a = const FOO);
//~^ ERROR invalid reference to argument at index 1
//~^^ ERROR named argument never used
global_asm!("{:foo}", const FOO);
//~^ ERROR asm template modifier must be a single character
global_asm!("", const FOO, const FOO);
//~^ ERROR multiple unused asm arguments

View File

@ -98,5 +98,90 @@ LL | asm!("", in(reg) 0, in(reg) 1);
|
= help: if these arguments are intentionally unused, consider using them in an asm comment: `"/* {0} {1} */"`
error: aborting due to 11 previous errors
error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:31:14
|
LL | global_asm!("{}");
| ^^ from here
|
= note: no arguments were given
error: invalid reference to argument at index 1
--> $DIR/bad-template.rs:33:14
|
LL | global_asm!("{1}", const FOO);
| ^^^ from here
|
= note: there is 1 argument
error: argument never used
--> $DIR/bad-template.rs:33:20
|
LL | global_asm!("{1}", const FOO);
| ^^^^^^^^^ argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`
error: there is no argument named `a`
--> $DIR/bad-template.rs:36:14
|
LL | global_asm!("{a}");
| ^^^
error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:38:14
|
LL | global_asm!("{}", a = const FOO);
| ^^ ------------- named argument
| |
| from here
|
= note: no positional arguments were given
note: named arguments cannot be referenced by position
--> $DIR/bad-template.rs:38:19
|
LL | global_asm!("{}", a = const FOO);
| ^^^^^^^^^^^^^
error: named argument never used
--> $DIR/bad-template.rs:38:19
|
LL | global_asm!("{}", a = const FOO);
| ^^^^^^^^^^^^^ named argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`
error: invalid reference to argument at index 1
--> $DIR/bad-template.rs:41:14
|
LL | global_asm!("{1}", a = const FOO);
| ^^^ from here
|
= note: no positional arguments were given
error: named argument never used
--> $DIR/bad-template.rs:41:20
|
LL | global_asm!("{1}", a = const FOO);
| ^^^^^^^^^^^^^ named argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`
error: asm template modifier must be a single character
--> $DIR/bad-template.rs:44:16
|
LL | global_asm!("{:foo}", const FOO);
| ^^^
error: multiple unused asm arguments
--> $DIR/bad-template.rs:46:17
|
LL | global_asm!("", const FOO, const FOO);
| ^^^^^^^^^ ^^^^^^^^^ argument never used
| |
| argument never used
|
= help: if these arguments are intentionally unused, consider using them in an asm comment: `"/* {0} {1} */"`
error: aborting due to 21 previous errors

View File

@ -2,7 +2,7 @@
// only-x86_64
// run-pass
#![feature(asm)]
#![feature(asm, global_asm)]
fn const_generic<const X: usize>() -> usize {
unsafe {
@ -34,3 +34,7 @@ fn main() {
let d = const_generic::<5>();
assert_eq!(d, 5);
}
global_asm!("mov eax, {}", const 5);
global_asm!("mov eax, {}", const constfn(5));
global_asm!("mov eax, {}", const constfn(5) + constfn(5));

View File

@ -1,7 +1,7 @@
// only-x86_64
// run-rustfix
#![feature(asm)]
#![feature(asm, global_asm)]
fn main() {
unsafe {
@ -24,3 +24,6 @@ fn main() {
);
}
}
global_asm!("", options(att_syntax, ));
//~^ ERROR the `att_syntax` option was already provided

View File

@ -1,7 +1,7 @@
// only-x86_64
// run-rustfix
#![feature(asm)]
#![feature(asm, global_asm)]
fn main() {
unsafe {
@ -24,3 +24,6 @@ fn main() {
);
}
}
global_asm!("", options(att_syntax, att_syntax));
//~^ ERROR the `att_syntax` option was already provided

View File

@ -52,5 +52,11 @@ error: the `noreturn` option was already provided
LL | options(noreturn),
| ^^^^^^^^ this option was already provided
error: aborting due to 9 previous errors
error: the `att_syntax` option was already provided
--> $DIR/duplicate-options.rs:28:37
|
LL | global_asm!("", options(att_syntax, att_syntax));
| ^^^^^^^^^^ this option was already provided
error: aborting due to 10 previous errors

View File

@ -1,5 +1,19 @@
error: unknown directive
--> $DIR/inline-syntax.rs:25:15
.intel_syntax noprefix
^
error: unknown directive
.intel_syntax noprefix
^
error: unknown directive
|
note: instantiated into assembly here
--> <inline asm>:1:1
|
LL | .intel_syntax noprefix
| ^
error: unknown directive
--> $DIR/inline-syntax.rs:29:15
|
LL | asm!(".intel_syntax noprefix", "nop");
| ^
@ -11,7 +25,7 @@ LL | .intel_syntax noprefix
| ^
error: unknown directive
--> $DIR/inline-syntax.rs:28:15
--> $DIR/inline-syntax.rs:32:15
|
LL | asm!(".intel_syntax aaa noprefix", "nop");
| ^
@ -23,7 +37,7 @@ LL | .intel_syntax aaa noprefix
| ^
error: unknown directive
--> $DIR/inline-syntax.rs:31:15
--> $DIR/inline-syntax.rs:35:15
|
LL | asm!(".att_syntax noprefix", "nop");
| ^
@ -35,7 +49,7 @@ LL | .att_syntax noprefix
| ^
error: unknown directive
--> $DIR/inline-syntax.rs:34:15
--> $DIR/inline-syntax.rs:38:15
|
LL | asm!(".att_syntax bbb noprefix", "nop");
| ^
@ -47,7 +61,7 @@ LL | .att_syntax bbb noprefix
| ^
error: unknown directive
--> $DIR/inline-syntax.rs:37:15
--> $DIR/inline-syntax.rs:41:15
|
LL | asm!(".intel_syntax noprefix; nop");
| ^
@ -59,7 +73,7 @@ LL | .intel_syntax noprefix; nop
| ^
error: unknown directive
--> $DIR/inline-syntax.rs:43:13
--> $DIR/inline-syntax.rs:47:13
|
LL | .intel_syntax noprefix
| ^
@ -70,5 +84,5 @@ note: instantiated into assembly here
LL | .intel_syntax noprefix
| ^
error: aborting due to 6 previous errors
error: aborting due to 7 previous errors

View File

@ -16,6 +16,10 @@
macro_rules! asm {
() => {};
}
#[rustc_builtin_macro]
macro_rules! global_asm {
() => {};
}
#[lang = "sized"]
trait Sized {}
@ -47,3 +51,7 @@ pub fn main() {
//[arm]~^^^^ ERROR unknown directive
}
}
global_asm!(".intel_syntax noprefix", "nop");
//[x86_64]~^ WARN avoid using `.intel_syntax`
// Assembler errors don't have line numbers, so no error on ARM

View File

@ -1,40 +1,46 @@
warning: avoid using `.intel_syntax`, Intel syntax is the default
--> $DIR/inline-syntax.rs:25:15
--> $DIR/inline-syntax.rs:55:14
|
LL | asm!(".intel_syntax noprefix", "nop");
| ^^^^^^^^^^^^^^^^^^^^^^
LL | global_asm!(".intel_syntax noprefix", "nop");
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(bad_asm_style)]` on by default
warning: avoid using `.intel_syntax`, Intel syntax is the default
--> $DIR/inline-syntax.rs:28:15
--> $DIR/inline-syntax.rs:29:15
|
LL | asm!(".intel_syntax noprefix", "nop");
| ^^^^^^^^^^^^^^^^^^^^^^
warning: avoid using `.intel_syntax`, Intel syntax is the default
--> $DIR/inline-syntax.rs:32:15
|
LL | asm!(".intel_syntax aaa noprefix", "nop");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
--> $DIR/inline-syntax.rs:31:15
--> $DIR/inline-syntax.rs:35:15
|
LL | asm!(".att_syntax noprefix", "nop");
| ^^^^^^^^^^^^^^^^^^^^
warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
--> $DIR/inline-syntax.rs:34:15
--> $DIR/inline-syntax.rs:38:15
|
LL | asm!(".att_syntax bbb noprefix", "nop");
| ^^^^^^^^^^^^^^^^^^^^^^^^
warning: avoid using `.intel_syntax`, Intel syntax is the default
--> $DIR/inline-syntax.rs:37:15
--> $DIR/inline-syntax.rs:41:15
|
LL | asm!(".intel_syntax noprefix; nop");
| ^^^^^^^^^^^^^^^^^^^^^^
warning: avoid using `.intel_syntax`, Intel syntax is the default
--> $DIR/inline-syntax.rs:43:13
--> $DIR/inline-syntax.rs:47:13
|
LL | .intel_syntax noprefix
| ^^^^^^^^^^^^^^^^^^^^^^
warning: 6 warnings emitted
warning: 7 warnings emitted

View File

@ -1,6 +1,6 @@
// only-x86_64
#![feature(asm)]
#![feature(asm, global_asm)]
fn main() {
let mut foo = 0;
@ -63,3 +63,37 @@ fn main() {
//~^ ERROR asm template must be a string literal
}
}
const FOO: i32 = 1;
const BAR: i32 = 2;
global_asm!();
//~^ ERROR requires at least a template string argument
global_asm!(FOO);
//~^ ERROR asm template must be a string literal
global_asm!("{}" FOO);
//~^ ERROR expected token: `,`
global_asm!("{}", FOO);
//~^ ERROR expected operand, options, or additional template string
global_asm!("{}", const);
//~^ ERROR expected expression, found end of macro arguments
global_asm!("{}", const(reg) FOO);
//~^ ERROR expected one of
global_asm!("", options(FOO));
//~^ ERROR expected one of
global_asm!("", options(nomem FOO));
//~^ ERROR expected one of
global_asm!("", options(nomem, FOO));
//~^ ERROR expected one of
global_asm!("{}", options(), const FOO);
//~^ ERROR arguments are not allowed after options
global_asm!("{a}", a = const FOO, a = const BAR);
//~^ ERROR duplicate argument named `a`
//~^^ ERROR argument never used
global_asm!("", options(), "");
//~^ ERROR expected one of
global_asm!("{}", const FOO, "{}", const FOO);
//~^ ERROR expected one of
global_asm!(format!("{{{}}}", 0), const FOO);
//~^ ERROR asm template must be a string literal
global_asm!("{1}", format!("{{{}}}", 0), const FOO, const BAR);
//~^ ERROR asm template must be a string literal

View File

@ -164,6 +164,112 @@ LL | asm!("{1}", format!("{{{}}}", 0), in(reg) foo, out(reg) bar);
|
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
error: requires at least a template string argument
--> $DIR/parse-error.rs:69:1
|
LL | global_asm!();
| ^^^^^^^^^^^^^^
error: asm template must be a string literal
--> $DIR/parse-error.rs:71:13
|
LL | global_asm!(FOO);
| ^^^
error: expected token: `,`
--> $DIR/parse-error.rs:73:18
|
LL | global_asm!("{}" FOO);
| ^^^ expected `,`
error: expected operand, options, or additional template string
--> $DIR/parse-error.rs:75:19
|
LL | global_asm!("{}", FOO);
| ^^^ expected operand, options, or additional template string
error: expected expression, found end of macro arguments
--> $DIR/parse-error.rs:77:24
|
LL | global_asm!("{}", const);
| ^ expected expression
error: expected one of `,`, `.`, `?`, or an operator, found `FOO`
--> $DIR/parse-error.rs:79:30
|
LL | global_asm!("{}", const(reg) FOO);
| ^^^ expected one of `,`, `.`, `?`, or an operator
error: expected one of `)` or `att_syntax`, found `FOO`
--> $DIR/parse-error.rs:81:25
|
LL | global_asm!("", options(FOO));
| ^^^ expected one of `)` or `att_syntax`
error: expected one of `)` or `att_syntax`, found `nomem`
--> $DIR/parse-error.rs:83:25
|
LL | global_asm!("", options(nomem FOO));
| ^^^^^ expected one of `)` or `att_syntax`
error: expected one of `)` or `att_syntax`, found `nomem`
--> $DIR/parse-error.rs:85:25
|
LL | global_asm!("", options(nomem, FOO));
| ^^^^^ expected one of `)` or `att_syntax`
error: arguments are not allowed after options
--> $DIR/parse-error.rs:87:30
|
LL | global_asm!("{}", options(), const FOO);
| --------- ^^^^^^^^^ argument
| |
| previous options
error: duplicate argument named `a`
--> $DIR/parse-error.rs:89:35
|
LL | global_asm!("{a}", a = const FOO, a = const BAR);
| ------------- ^^^^^^^^^^^^^ duplicate argument
| |
| previously here
error: argument never used
--> $DIR/parse-error.rs:89:35
|
LL | global_asm!("{a}", a = const FOO, a = const BAR);
| ^^^^^^^^^^^^^ argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {1} */"`
error: expected one of `const` or `options`, found `""`
--> $DIR/parse-error.rs:92:28
|
LL | global_asm!("", options(), "");
| ^^ expected one of `const` or `options`
error: expected one of `const` or `options`, found `"{}"`
--> $DIR/parse-error.rs:94:30
|
LL | global_asm!("{}", const FOO, "{}", const FOO);
| ^^^^ expected one of `const` or `options`
error: asm template must be a string literal
--> $DIR/parse-error.rs:96:13
|
LL | global_asm!(format!("{{{}}}", 0), const FOO);
| ^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: asm template must be a string literal
--> $DIR/parse-error.rs:98:20
|
LL | global_asm!("{1}", format!("{{{}}}", 0), const FOO, const BAR);
| ^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/parse-error.rs:37:37
|
@ -218,6 +324,6 @@ LL | let mut bar = 0;
LL | asm!("{1}", in("eax") foo, const bar);
| ^^^ non-constant value
error: aborting due to 31 previous errors
error: aborting due to 47 previous errors
For more information about this error, try `rustc --explain E0435`.

View File

@ -1,6 +1,6 @@
// only-x86_64
#![feature(asm, repr_simd, never_type)]
#![feature(asm, global_asm, repr_simd, never_type)]
#[repr(simd)]
struct SimdNonCopy(f32, f32, f32, f32);
@ -90,3 +90,11 @@ fn main() {
asm!("{}", in(reg) u);
}
}
// Const operands must be integer or floats, and must be constants.
global_asm!("{}", const 0);
global_asm!("{}", const 0i32);
global_asm!("{}", const 0f32);
global_asm!("{}", const 0 as *mut u8);
//~^ ERROR asm `const` arguments must be integer or floating-point values

View File

@ -61,6 +61,12 @@ LL | asm!("{}", inout(reg) r);
|
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
error: asm `const` arguments must be integer or floating-point values
--> $DIR/type-check-2.rs:99:19
|
LL | global_asm!("{}", const 0 as *mut u8);
| ^^^^^^^^^^^^^^^^^^
error: asm `sym` operand must point to a fn or static
--> $DIR/type-check-2.rs:47:24
|
@ -103,7 +109,7 @@ LL | let v: Vec<u64> = vec![0, 1, 2];
LL | asm!("{}", inout(reg) v[0]);
| ^ cannot borrow as mutable
error: aborting due to 14 previous errors
error: aborting due to 15 previous errors
Some errors have detailed explanations: E0381, E0596.
For more information about an error, try `rustc --explain E0381`.

View File

@ -1,7 +1,7 @@
// only-x86_64
// compile-flags: -C target-feature=+avx512f
#![feature(asm)]
#![feature(asm, global_asm)]
use std::arch::x86_64::{_mm256_setzero_ps, _mm_setzero_ps};
@ -69,3 +69,21 @@ fn main() {
asm!("{:r}", inout(reg) main => val_u64);
}
}
// Constants must be... constant
static S: i32 = 1;
const fn const_foo(x: i32) -> i32 {
x
}
const fn const_bar<T>(x: T) -> T {
x
}
global_asm!("{}", const S);
//~^ ERROR constants cannot refer to statics
global_asm!("{}", const const_foo(0));
global_asm!("{}", const const_foo(S));
//~^ ERROR constants cannot refer to statics
global_asm!("{}", const const_bar(0));
global_asm!("{}", const const_bar(S));
//~^ ERROR constants cannot refer to statics

View File

@ -114,5 +114,30 @@ LL | asm!("{:r}", inout(reg) main => val_u32);
|
= note: asm inout arguments must have the same type, unless they are both pointers or integers of the same size
error: aborting due to 9 previous errors; 4 warnings emitted
error[E0013]: constants cannot refer to statics
--> $DIR/type-check-3.rs:82:25
|
LL | global_asm!("{}", const S);
| ^
|
= help: consider extracting the value of the `static` to a `const`, and referring to that
error[E0013]: constants cannot refer to statics
--> $DIR/type-check-3.rs:85:35
|
LL | global_asm!("{}", const const_foo(S));
| ^
|
= help: consider extracting the value of the `static` to a `const`, and referring to that
error[E0013]: constants cannot refer to statics
--> $DIR/type-check-3.rs:88:35
|
LL | global_asm!("{}", const const_bar(S));
| ^
|
= help: consider extracting the value of the `static` to a `const`, and referring to that
error: aborting due to 12 previous errors; 4 warnings emitted
For more information about this error, try `rustc --explain E0013`.