Auto merge of #89316 - asquared31415:multiple-clobber-abi, r=Amanieu
Add support for specifying multiple clobber_abi in `asm!` r? `@Amanieu` cc #72016 `@rustbot` label: +A-inline-assembly +F-asm
This commit is contained in:
commit
220ed09b26
14 changed files with 379 additions and 165 deletions
|
|
@ -319,7 +319,7 @@ fn call_foo(arg: i32) -> i32 {
|
|||
|
||||
Note that the `fn` or `static` item does not need to be public or `#[no_mangle]`: the compiler will automatically insert the appropriate mangled symbol name into the assembly code.
|
||||
|
||||
By default, `asm!` assumes that any register not specified as an output will have its contents preserved by the assembly code. The [`clobber_abi`](#abi-clobbers) argument to `asm!` tells the compiler to automatically insert the necessary clobber operands according to the given calling convention ABI: any register which is not fully preserved in that ABI will be treated as clobbered.
|
||||
By default, `asm!` assumes that any register not specified as an output will have its contents preserved by the assembly code. The [`clobber_abi`](#abi-clobbers) argument to `asm!` tells the compiler to automatically insert the necessary clobber operands according to the given calling convention ABI: any register which is not fully preserved in that ABI will be treated as clobbered. Multiple `clobber_abi` arguments may be provided and all clobbers from all specified ABIs will be inserted.
|
||||
|
||||
## Register template modifiers
|
||||
|
||||
|
|
@ -453,10 +453,10 @@ reg_spec := <register class> / "<explicit register>"
|
|||
operand_expr := expr / "_" / expr "=>" expr / expr "=>" "_"
|
||||
reg_operand := dir_spec "(" reg_spec ")" operand_expr
|
||||
operand := reg_operand / "const" const_expr / "sym" path
|
||||
clobber_abi := "clobber_abi(" <abi> ")"
|
||||
clobber_abi := "clobber_abi(" <abi> *["," <abi>] [","] ")"
|
||||
option := "pure" / "nomem" / "readonly" / "preserves_flags" / "noreturn" / "nostack" / "att_syntax" / "raw"
|
||||
options := "options(" option *["," option] [","] ")"
|
||||
asm := "asm!(" format_string *("," format_string) *("," [ident "="] operand) ["," clobber_abi] *("," options) [","] ")"
|
||||
asm := "asm!(" format_string *("," format_string) *("," [ident "="] operand) *("," clobber_abi) *("," options) [","] ")"
|
||||
```
|
||||
|
||||
Inline assembly is currently supported on the following architectures:
|
||||
|
|
@ -802,6 +802,8 @@ As stated in the previous section, passing an input value smaller than the regis
|
|||
|
||||
The `clobber_abi` keyword can be used to apply a default set of clobbers to an `asm` block. This will automatically insert the necessary clobber constraints as needed for calling a function with a particular calling convention: if the calling convention does not fully preserve the value of a register across a call then a `lateout("reg") _` is implicitly added to the operands list.
|
||||
|
||||
`clobber_abi` may be specified any number of times. It will insert a clobber for all unique registers in the union of all specified calling conventions.
|
||||
|
||||
Generic register class outputs are disallowed by the compiler when `clobber_abi` is used: all outputs must specify an explicit register. Explicit register outputs have precedence over the implicit clobbers inserted by `clobber_abi`: a clobber will only be inserted for a register if that register is not used as an output.
|
||||
The following ABIs can be used with `clobber_abi`:
|
||||
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ fn main() {
|
|||
asm!("", clobber_abi(foo));
|
||||
//~^ ERROR expected string literal
|
||||
asm!("", clobber_abi("C" foo));
|
||||
//~^ ERROR expected `)`, found `foo`
|
||||
//~^ ERROR expected one of `)` or `,`, found `foo`
|
||||
asm!("", clobber_abi("C", foo));
|
||||
//~^ ERROR expected `)`, found `,`
|
||||
//~^ ERROR expected string literal
|
||||
asm!("{}", clobber_abi("C"), const foo);
|
||||
//~^ ERROR arguments are not allowed after clobber_abi
|
||||
//~^^ ERROR attempt to use a non-constant value in a constant
|
||||
|
|
@ -50,8 +50,6 @@ fn main() {
|
|||
//~^ ERROR clobber_abi is not allowed after options
|
||||
asm!("{}", options(), clobber_abi("C"), const foo);
|
||||
//~^ ERROR clobber_abi is not allowed after options
|
||||
asm!("", clobber_abi("C"), clobber_abi("C"));
|
||||
//~^ ERROR clobber_abi specified multiple times
|
||||
asm!("{a}", a = const foo, a = const bar);
|
||||
//~^ ERROR duplicate argument named `a`
|
||||
//~^^ ERROR argument never used
|
||||
|
|
@ -110,9 +108,9 @@ global_asm!("{}", options(), const FOO);
|
|||
global_asm!("", clobber_abi(FOO));
|
||||
//~^ ERROR expected string literal
|
||||
global_asm!("", clobber_abi("C" FOO));
|
||||
//~^ ERROR expected `)`, found `FOO`
|
||||
//~^ ERROR expected one of `)` or `,`, found `FOO`
|
||||
global_asm!("", clobber_abi("C", FOO));
|
||||
//~^ ERROR expected `)`, found `,`
|
||||
//~^ ERROR expected string literal
|
||||
global_asm!("{}", clobber_abi("C"), const FOO);
|
||||
//~^ ERROR arguments are not allowed after clobber_abi
|
||||
//~^^ ERROR `clobber_abi` cannot be used with `global_asm!`
|
||||
|
|
@ -120,8 +118,6 @@ global_asm!("", options(), clobber_abi("C"));
|
|||
//~^ ERROR clobber_abi is not allowed after options
|
||||
global_asm!("{}", options(), clobber_abi("C"), const FOO);
|
||||
//~^ ERROR clobber_abi is not allowed after options
|
||||
global_asm!("", clobber_abi("C"), clobber_abi("C"));
|
||||
//~^ ERROR clobber_abi specified multiple times
|
||||
global_asm!("{a}", a = const FOO, a = const BAR);
|
||||
//~^ ERROR duplicate argument named `a`
|
||||
//~^^ ERROR argument never used
|
||||
|
|
|
|||
|
|
@ -96,17 +96,17 @@ error: expected string literal
|
|||
LL | asm!("", clobber_abi(foo));
|
||||
| ^^^ not a string literal
|
||||
|
||||
error: expected `)`, found `foo`
|
||||
error: expected one of `)` or `,`, found `foo`
|
||||
--> $DIR/parse-error.rs:42:34
|
||||
|
|
||||
LL | asm!("", clobber_abi("C" foo));
|
||||
| ^^^ expected `)`
|
||||
| ^^^ expected one of `)` or `,`
|
||||
|
||||
error: expected `)`, found `,`
|
||||
--> $DIR/parse-error.rs:44:33
|
||||
error: expected string literal
|
||||
--> $DIR/parse-error.rs:44:35
|
||||
|
|
||||
LL | asm!("", clobber_abi("C", foo));
|
||||
| ^ expected `)`
|
||||
| ^^^ not a string literal
|
||||
|
||||
error: arguments are not allowed after clobber_abi
|
||||
--> $DIR/parse-error.rs:46:38
|
||||
|
|
@ -132,16 +132,8 @@ LL | asm!("{}", options(), clobber_abi("C"), const foo);
|
|||
| |
|
||||
| options
|
||||
|
||||
error: clobber_abi specified multiple times
|
||||
--> $DIR/parse-error.rs:53:36
|
||||
|
|
||||
LL | asm!("", clobber_abi("C"), clobber_abi("C"));
|
||||
| ---------------- ^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| clobber_abi previously specified here
|
||||
|
||||
error: duplicate argument named `a`
|
||||
--> $DIR/parse-error.rs:55:36
|
||||
--> $DIR/parse-error.rs:53:36
|
||||
|
|
||||
LL | asm!("{a}", a = const foo, a = const bar);
|
||||
| ------------- ^^^^^^^^^^^^^ duplicate argument
|
||||
|
|
@ -149,7 +141,7 @@ LL | asm!("{a}", a = const foo, a = const bar);
|
|||
| previously here
|
||||
|
||||
error: argument never used
|
||||
--> $DIR/parse-error.rs:55:36
|
||||
--> $DIR/parse-error.rs:53:36
|
||||
|
|
||||
LL | asm!("{a}", a = const foo, a = const bar);
|
||||
| ^^^^^^^^^^^^^ argument never used
|
||||
|
|
@ -157,13 +149,13 @@ LL | asm!("{a}", a = const foo, a = const bar);
|
|||
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {1} */"`
|
||||
|
||||
error: explicit register arguments cannot have names
|
||||
--> $DIR/parse-error.rs:60:18
|
||||
--> $DIR/parse-error.rs:58:18
|
||||
|
|
||||
LL | asm!("", a = in("x0") foo);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: named arguments cannot follow explicit register arguments
|
||||
--> $DIR/parse-error.rs:62:35
|
||||
--> $DIR/parse-error.rs:60:35
|
||||
|
|
||||
LL | asm!("{a}", in("x0") foo, a = const bar);
|
||||
| ------------ ^^^^^^^^^^^^^ named argument
|
||||
|
|
@ -171,7 +163,7 @@ LL | asm!("{a}", in("x0") foo, a = const bar);
|
|||
| explicit register argument
|
||||
|
||||
error: named arguments cannot follow explicit register arguments
|
||||
--> $DIR/parse-error.rs:65:35
|
||||
--> $DIR/parse-error.rs:63:35
|
||||
|
|
||||
LL | asm!("{a}", in("x0") foo, a = const bar);
|
||||
| ------------ ^^^^^^^^^^^^^ named argument
|
||||
|
|
@ -179,7 +171,7 @@ LL | asm!("{a}", in("x0") foo, a = const bar);
|
|||
| explicit register argument
|
||||
|
||||
error: positional arguments cannot follow named arguments or explicit register arguments
|
||||
--> $DIR/parse-error.rs:68:35
|
||||
--> $DIR/parse-error.rs:66:35
|
||||
|
|
||||
LL | asm!("{1}", in("x0") foo, const bar);
|
||||
| ------------ ^^^^^^^^^ positional argument
|
||||
|
|
@ -187,19 +179,19 @@ LL | asm!("{1}", in("x0") foo, const bar);
|
|||
| explicit register argument
|
||||
|
||||
error: expected one of `clobber_abi`, `const`, `in`, `inlateout`, `inout`, `lateout`, `options`, `out`, or `sym`, found `""`
|
||||
--> $DIR/parse-error.rs:71:29
|
||||
--> $DIR/parse-error.rs:69:29
|
||||
|
|
||||
LL | asm!("", options(), "");
|
||||
| ^^ expected one of 9 possible tokens
|
||||
|
||||
error: expected one of `clobber_abi`, `const`, `in`, `inlateout`, `inout`, `lateout`, `options`, `out`, or `sym`, found `"{}"`
|
||||
--> $DIR/parse-error.rs:73:33
|
||||
--> $DIR/parse-error.rs:71:33
|
||||
|
|
||||
LL | asm!("{}", in(reg) foo, "{}", out(reg) foo);
|
||||
| ^^^^ expected one of 9 possible tokens
|
||||
|
||||
error: asm template must be a string literal
|
||||
--> $DIR/parse-error.rs:75:14
|
||||
--> $DIR/parse-error.rs:73:14
|
||||
|
|
||||
LL | asm!(format!("{{{}}}", 0), in(reg) foo);
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -207,7 +199,7 @@ LL | asm!(format!("{{{}}}", 0), in(reg) foo);
|
|||
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: asm template must be a string literal
|
||||
--> $DIR/parse-error.rs:77:21
|
||||
--> $DIR/parse-error.rs:75:21
|
||||
|
|
||||
LL | asm!("{1}", format!("{{{}}}", 0), in(reg) foo, out(reg) bar);
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -215,79 +207,79 @@ 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: _ cannot be used for input operands
|
||||
--> $DIR/parse-error.rs:79:28
|
||||
--> $DIR/parse-error.rs:77:28
|
||||
|
|
||||
LL | asm!("{}", in(reg) _);
|
||||
| ^
|
||||
|
||||
error: _ cannot be used for input operands
|
||||
--> $DIR/parse-error.rs:81:31
|
||||
--> $DIR/parse-error.rs:79:31
|
||||
|
|
||||
LL | asm!("{}", inout(reg) _);
|
||||
| ^
|
||||
|
||||
error: _ cannot be used for input operands
|
||||
--> $DIR/parse-error.rs:83:35
|
||||
--> $DIR/parse-error.rs:81:35
|
||||
|
|
||||
LL | asm!("{}", inlateout(reg) _);
|
||||
| ^
|
||||
|
||||
error: requires at least a template string argument
|
||||
--> $DIR/parse-error.rs:90:1
|
||||
--> $DIR/parse-error.rs:88:1
|
||||
|
|
||||
LL | global_asm!();
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: asm template must be a string literal
|
||||
--> $DIR/parse-error.rs:92:13
|
||||
--> $DIR/parse-error.rs:90:13
|
||||
|
|
||||
LL | global_asm!(FOO);
|
||||
| ^^^
|
||||
|
||||
error: expected token: `,`
|
||||
--> $DIR/parse-error.rs:94:18
|
||||
--> $DIR/parse-error.rs:92:18
|
||||
|
|
||||
LL | global_asm!("{}" FOO);
|
||||
| ^^^ expected `,`
|
||||
|
||||
error: expected operand, options, or additional template string
|
||||
--> $DIR/parse-error.rs:96:19
|
||||
--> $DIR/parse-error.rs:94:19
|
||||
|
|
||||
LL | global_asm!("{}", FOO);
|
||||
| ^^^ expected operand, options, or additional template string
|
||||
|
||||
error: expected expression, found end of macro arguments
|
||||
--> $DIR/parse-error.rs:98:24
|
||||
--> $DIR/parse-error.rs:96:24
|
||||
|
|
||||
LL | global_asm!("{}", const);
|
||||
| ^ expected expression
|
||||
|
||||
error: expected one of `,`, `.`, `?`, or an operator, found `FOO`
|
||||
--> $DIR/parse-error.rs:100:30
|
||||
--> $DIR/parse-error.rs:98:30
|
||||
|
|
||||
LL | global_asm!("{}", const(reg) FOO);
|
||||
| ^^^ expected one of `,`, `.`, `?`, or an operator
|
||||
|
||||
error: expected one of `)`, `att_syntax`, or `raw`, found `FOO`
|
||||
--> $DIR/parse-error.rs:102:25
|
||||
--> $DIR/parse-error.rs:100:25
|
||||
|
|
||||
LL | global_asm!("", options(FOO));
|
||||
| ^^^ expected one of `)`, `att_syntax`, or `raw`
|
||||
|
||||
error: expected one of `)`, `att_syntax`, or `raw`, found `nomem`
|
||||
--> $DIR/parse-error.rs:104:25
|
||||
--> $DIR/parse-error.rs:102:25
|
||||
|
|
||||
LL | global_asm!("", options(nomem FOO));
|
||||
| ^^^^^ expected one of `)`, `att_syntax`, or `raw`
|
||||
|
||||
error: expected one of `)`, `att_syntax`, or `raw`, found `nomem`
|
||||
--> $DIR/parse-error.rs:106:25
|
||||
--> $DIR/parse-error.rs:104:25
|
||||
|
|
||||
LL | global_asm!("", options(nomem, FOO));
|
||||
| ^^^^^ expected one of `)`, `att_syntax`, or `raw`
|
||||
|
||||
error: arguments are not allowed after options
|
||||
--> $DIR/parse-error.rs:108:30
|
||||
--> $DIR/parse-error.rs:106:30
|
||||
|
|
||||
LL | global_asm!("{}", options(), const FOO);
|
||||
| --------- ^^^^^^^^^ argument
|
||||
|
|
@ -295,25 +287,25 @@ LL | global_asm!("{}", options(), const FOO);
|
|||
| previous options
|
||||
|
||||
error: expected string literal
|
||||
--> $DIR/parse-error.rs:110:29
|
||||
--> $DIR/parse-error.rs:108:29
|
||||
|
|
||||
LL | global_asm!("", clobber_abi(FOO));
|
||||
| ^^^ not a string literal
|
||||
|
||||
error: expected `)`, found `FOO`
|
||||
--> $DIR/parse-error.rs:112:33
|
||||
error: expected one of `)` or `,`, found `FOO`
|
||||
--> $DIR/parse-error.rs:110:33
|
||||
|
|
||||
LL | global_asm!("", clobber_abi("C" FOO));
|
||||
| ^^^ expected `)`
|
||||
| ^^^ expected one of `)` or `,`
|
||||
|
||||
error: expected `)`, found `,`
|
||||
--> $DIR/parse-error.rs:114:32
|
||||
error: expected string literal
|
||||
--> $DIR/parse-error.rs:112:34
|
||||
|
|
||||
LL | global_asm!("", clobber_abi("C", FOO));
|
||||
| ^ expected `)`
|
||||
| ^^^ not a string literal
|
||||
|
||||
error: arguments are not allowed after clobber_abi
|
||||
--> $DIR/parse-error.rs:116:37
|
||||
--> $DIR/parse-error.rs:114:37
|
||||
|
|
||||
LL | global_asm!("{}", clobber_abi("C"), const FOO);
|
||||
| ---------------- ^^^^^^^^^ argument
|
||||
|
|
@ -321,13 +313,13 @@ LL | global_asm!("{}", clobber_abi("C"), const FOO);
|
|||
| clobber_abi
|
||||
|
||||
error: `clobber_abi` cannot be used with `global_asm!`
|
||||
--> $DIR/parse-error.rs:116:19
|
||||
--> $DIR/parse-error.rs:114:19
|
||||
|
|
||||
LL | global_asm!("{}", clobber_abi("C"), const FOO);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: clobber_abi is not allowed after options
|
||||
--> $DIR/parse-error.rs:119:28
|
||||
--> $DIR/parse-error.rs:117:28
|
||||
|
|
||||
LL | global_asm!("", options(), clobber_abi("C"));
|
||||
| --------- ^^^^^^^^^^^^^^^^
|
||||
|
|
@ -335,23 +327,15 @@ LL | global_asm!("", options(), clobber_abi("C"));
|
|||
| options
|
||||
|
||||
error: clobber_abi is not allowed after options
|
||||
--> $DIR/parse-error.rs:121:30
|
||||
--> $DIR/parse-error.rs:119:30
|
||||
|
|
||||
LL | global_asm!("{}", options(), clobber_abi("C"), const FOO);
|
||||
| --------- ^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| options
|
||||
|
||||
error: clobber_abi specified multiple times
|
||||
--> $DIR/parse-error.rs:123:35
|
||||
|
|
||||
LL | global_asm!("", clobber_abi("C"), clobber_abi("C"));
|
||||
| ---------------- ^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| clobber_abi previously specified here
|
||||
|
||||
error: duplicate argument named `a`
|
||||
--> $DIR/parse-error.rs:125:35
|
||||
--> $DIR/parse-error.rs:121:35
|
||||
|
|
||||
LL | global_asm!("{a}", a = const FOO, a = const BAR);
|
||||
| ------------- ^^^^^^^^^^^^^ duplicate argument
|
||||
|
|
@ -359,7 +343,7 @@ LL | global_asm!("{a}", a = const FOO, a = const BAR);
|
|||
| previously here
|
||||
|
||||
error: argument never used
|
||||
--> $DIR/parse-error.rs:125:35
|
||||
--> $DIR/parse-error.rs:121:35
|
||||
|
|
||||
LL | global_asm!("{a}", a = const FOO, a = const BAR);
|
||||
| ^^^^^^^^^^^^^ argument never used
|
||||
|
|
@ -367,19 +351,19 @@ LL | global_asm!("{a}", a = const FOO, a = const BAR);
|
|||
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {1} */"`
|
||||
|
||||
error: expected one of `clobber_abi`, `const`, or `options`, found `""`
|
||||
--> $DIR/parse-error.rs:128:28
|
||||
--> $DIR/parse-error.rs:124:28
|
||||
|
|
||||
LL | global_asm!("", options(), "");
|
||||
| ^^ expected one of `clobber_abi`, `const`, or `options`
|
||||
|
||||
error: expected one of `clobber_abi`, `const`, or `options`, found `"{}"`
|
||||
--> $DIR/parse-error.rs:130:30
|
||||
--> $DIR/parse-error.rs:126:30
|
||||
|
|
||||
LL | global_asm!("{}", const FOO, "{}", const FOO);
|
||||
| ^^^^ expected one of `clobber_abi`, `const`, or `options`
|
||||
|
||||
error: asm template must be a string literal
|
||||
--> $DIR/parse-error.rs:132:13
|
||||
--> $DIR/parse-error.rs:128:13
|
||||
|
|
||||
LL | global_asm!(format!("{{{}}}", 0), const FOO);
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -387,7 +371,7 @@ LL | global_asm!(format!("{{{}}}", 0), const FOO);
|
|||
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: asm template must be a string literal
|
||||
--> $DIR/parse-error.rs:134:20
|
||||
--> $DIR/parse-error.rs:130:20
|
||||
|
|
||||
LL | global_asm!("{1}", format!("{{{}}}", 0), const FOO, const BAR);
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -413,7 +397,7 @@ LL | asm!("{}", clobber_abi("C"), const foo);
|
|||
| ^^^ non-constant value
|
||||
|
||||
error[E0435]: attempt to use a non-constant value in a constant
|
||||
--> $DIR/parse-error.rs:55:31
|
||||
--> $DIR/parse-error.rs:53:31
|
||||
|
|
||||
LL | let mut foo = 0;
|
||||
| ---------- help: consider using `const` instead of `let`: `const foo`
|
||||
|
|
@ -422,7 +406,7 @@ LL | asm!("{a}", a = const foo, a = const bar);
|
|||
| ^^^ non-constant value
|
||||
|
||||
error[E0435]: attempt to use a non-constant value in a constant
|
||||
--> $DIR/parse-error.rs:55:46
|
||||
--> $DIR/parse-error.rs:53:46
|
||||
|
|
||||
LL | let mut bar = 0;
|
||||
| ---------- help: consider using `const` instead of `let`: `const bar`
|
||||
|
|
@ -431,7 +415,7 @@ LL | asm!("{a}", a = const foo, a = const bar);
|
|||
| ^^^ non-constant value
|
||||
|
||||
error[E0435]: attempt to use a non-constant value in a constant
|
||||
--> $DIR/parse-error.rs:62:45
|
||||
--> $DIR/parse-error.rs:60:45
|
||||
|
|
||||
LL | let mut bar = 0;
|
||||
| ---------- help: consider using `const` instead of `let`: `const bar`
|
||||
|
|
@ -440,7 +424,7 @@ LL | asm!("{a}", in("x0") foo, a = const bar);
|
|||
| ^^^ non-constant value
|
||||
|
||||
error[E0435]: attempt to use a non-constant value in a constant
|
||||
--> $DIR/parse-error.rs:65:45
|
||||
--> $DIR/parse-error.rs:63:45
|
||||
|
|
||||
LL | let mut bar = 0;
|
||||
| ---------- help: consider using `const` instead of `let`: `const bar`
|
||||
|
|
@ -449,7 +433,7 @@ LL | asm!("{a}", in("x0") foo, a = const bar);
|
|||
| ^^^ non-constant value
|
||||
|
||||
error[E0435]: attempt to use a non-constant value in a constant
|
||||
--> $DIR/parse-error.rs:68:41
|
||||
--> $DIR/parse-error.rs:66:41
|
||||
|
|
||||
LL | let mut bar = 0;
|
||||
| ---------- help: consider using `const` instead of `let`: `const bar`
|
||||
|
|
@ -457,6 +441,6 @@ LL | let mut bar = 0;
|
|||
LL | asm!("{1}", in("x0") foo, const bar);
|
||||
| ^^^ non-constant value
|
||||
|
||||
error: aborting due to 66 previous errors
|
||||
error: aborting due to 64 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0435`.
|
||||
|
|
|
|||
32
src/test/ui/asm/x86_64/bad-clobber-abi.rs
Normal file
32
src/test/ui/asm/x86_64/bad-clobber-abi.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// needs-asm-support
|
||||
// only-x86_64
|
||||
|
||||
// checks various modes of failure for the `clobber_abi` argument (after parsing)
|
||||
|
||||
#![feature(asm)]
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
asm!("", clobber_abi("C"));
|
||||
asm!("", clobber_abi("foo"));
|
||||
//~^ ERROR invalid ABI for `clobber_abi`
|
||||
asm!("", clobber_abi("C", "foo"));
|
||||
//~^ ERROR invalid ABI for `clobber_abi`
|
||||
asm!("", clobber_abi("C", "C"));
|
||||
//~^ ERROR `C` ABI specified multiple times
|
||||
asm!("", clobber_abi("win64", "sysv64"));
|
||||
asm!("", clobber_abi("win64", "efiapi"));
|
||||
//~^ ERROR `win64` ABI specified multiple times
|
||||
asm!("", clobber_abi("C", "foo", "C"));
|
||||
//~^ ERROR invalid ABI for `clobber_abi`
|
||||
//~| ERROR `C` ABI specified multiple times
|
||||
asm!("", clobber_abi("win64", "foo", "efiapi"));
|
||||
//~^ ERROR invalid ABI for `clobber_abi`
|
||||
//~| ERROR `win64` ABI specified multiple times
|
||||
asm!("", clobber_abi("C"), clobber_abi("C"));
|
||||
//~^ ERROR `C` ABI specified multiple times
|
||||
asm!("", clobber_abi("win64"), clobber_abi("sysv64"));
|
||||
asm!("", clobber_abi("win64"), clobber_abi("efiapi"));
|
||||
//~^ ERROR `win64` ABI specified multiple times
|
||||
}
|
||||
}
|
||||
88
src/test/ui/asm/x86_64/bad-clobber-abi.stderr
Normal file
88
src/test/ui/asm/x86_64/bad-clobber-abi.stderr
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
error: invalid ABI for `clobber_abi`
|
||||
--> $DIR/bad-clobber-abi.rs:11:18
|
||||
|
|
||||
LL | asm!("", clobber_abi("foo"));
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the following ABIs are supported on this target: `C`, `system`, `efiapi`, `win64`, `sysv64`
|
||||
|
||||
error: invalid ABI for `clobber_abi`
|
||||
--> $DIR/bad-clobber-abi.rs:13:35
|
||||
|
|
||||
LL | asm!("", clobber_abi("C", "foo"));
|
||||
| ^^^^^
|
||||
|
|
||||
= note: the following ABIs are supported on this target: `C`, `system`, `efiapi`, `win64`, `sysv64`
|
||||
|
||||
error: `C` ABI specified multiple times
|
||||
--> $DIR/bad-clobber-abi.rs:15:35
|
||||
|
|
||||
LL | asm!("", clobber_abi("C", "C"));
|
||||
| --- ^^^
|
||||
| |
|
||||
| previously specified here
|
||||
|
||||
error: `win64` ABI specified multiple times
|
||||
--> $DIR/bad-clobber-abi.rs:18:39
|
||||
|
|
||||
LL | asm!("", clobber_abi("win64", "efiapi"));
|
||||
| ------- ^^^^^^^^
|
||||
| |
|
||||
| previously specified here
|
||||
|
|
||||
= note: these ABIs are equivalent on the current target
|
||||
|
||||
error: invalid ABI for `clobber_abi`
|
||||
--> $DIR/bad-clobber-abi.rs:20:35
|
||||
|
|
||||
LL | asm!("", clobber_abi("C", "foo", "C"));
|
||||
| ^^^^^
|
||||
|
|
||||
= note: the following ABIs are supported on this target: `C`, `system`, `efiapi`, `win64`, `sysv64`
|
||||
|
||||
error: `C` ABI specified multiple times
|
||||
--> $DIR/bad-clobber-abi.rs:20:42
|
||||
|
|
||||
LL | asm!("", clobber_abi("C", "foo", "C"));
|
||||
| --- ^^^
|
||||
| |
|
||||
| previously specified here
|
||||
|
||||
error: invalid ABI for `clobber_abi`
|
||||
--> $DIR/bad-clobber-abi.rs:23:39
|
||||
|
|
||||
LL | asm!("", clobber_abi("win64", "foo", "efiapi"));
|
||||
| ^^^^^
|
||||
|
|
||||
= note: the following ABIs are supported on this target: `C`, `system`, `efiapi`, `win64`, `sysv64`
|
||||
|
||||
error: `win64` ABI specified multiple times
|
||||
--> $DIR/bad-clobber-abi.rs:23:46
|
||||
|
|
||||
LL | asm!("", clobber_abi("win64", "foo", "efiapi"));
|
||||
| ------- ^^^^^^^^
|
||||
| |
|
||||
| previously specified here
|
||||
|
|
||||
= note: these ABIs are equivalent on the current target
|
||||
|
||||
error: `C` ABI specified multiple times
|
||||
--> $DIR/bad-clobber-abi.rs:26:36
|
||||
|
|
||||
LL | asm!("", clobber_abi("C"), clobber_abi("C"));
|
||||
| ---------------- ^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| previously specified here
|
||||
|
||||
error: `win64` ABI specified multiple times
|
||||
--> $DIR/bad-clobber-abi.rs:29:40
|
||||
|
|
||||
LL | asm!("", clobber_abi("win64"), clobber_abi("efiapi"));
|
||||
| -------------------- ^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| previously specified here
|
||||
|
|
||||
= note: these ABIs are equivalent on the current target
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
@ -21,6 +21,9 @@ fn main() {
|
|||
//~^ ERROR invalid ABI for `clobber_abi`
|
||||
asm!("{}", out(reg) foo, clobber_abi("C"));
|
||||
//~^ ERROR asm with `clobber_abi` must specify explicit registers for outputs
|
||||
asm!("{}", out(reg) foo, clobber_abi("C"), clobber_abi("C"));
|
||||
//~^ ERROR asm with `clobber_abi` must specify explicit registers for outputs
|
||||
//~| ERROR `C` ABI specified multiple times
|
||||
asm!("", out("eax") foo, clobber_abi("C"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,38 +36,47 @@ LL | asm!("{}", out(reg) foo, clobber_abi("C"));
|
|||
| |
|
||||
| generic outputs
|
||||
|
||||
error: asm with `clobber_abi` must specify explicit registers for outputs
|
||||
--> $DIR/bad-options.rs:24:20
|
||||
|
|
||||
LL | asm!("{}", out(reg) foo, clobber_abi("C"), clobber_abi("C"));
|
||||
| ^^^^^^^^^^^^ ---------------- ---------------- clobber_abi
|
||||
| | |
|
||||
| | clobber_abi
|
||||
| generic outputs
|
||||
|
||||
error: expected one of `)`, `att_syntax`, or `raw`, found `nomem`
|
||||
--> $DIR/bad-options.rs:28:25
|
||||
--> $DIR/bad-options.rs:31:25
|
||||
|
|
||||
LL | global_asm!("", options(nomem));
|
||||
| ^^^^^ expected one of `)`, `att_syntax`, or `raw`
|
||||
|
||||
error: expected one of `)`, `att_syntax`, or `raw`, found `readonly`
|
||||
--> $DIR/bad-options.rs:30:25
|
||||
--> $DIR/bad-options.rs:33:25
|
||||
|
|
||||
LL | global_asm!("", options(readonly));
|
||||
| ^^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
|
||||
|
||||
error: expected one of `)`, `att_syntax`, or `raw`, found `noreturn`
|
||||
--> $DIR/bad-options.rs:32:25
|
||||
--> $DIR/bad-options.rs:35:25
|
||||
|
|
||||
LL | global_asm!("", options(noreturn));
|
||||
| ^^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
|
||||
|
||||
error: expected one of `)`, `att_syntax`, or `raw`, found `pure`
|
||||
--> $DIR/bad-options.rs:34:25
|
||||
--> $DIR/bad-options.rs:37:25
|
||||
|
|
||||
LL | global_asm!("", options(pure));
|
||||
| ^^^^ expected one of `)`, `att_syntax`, or `raw`
|
||||
|
||||
error: expected one of `)`, `att_syntax`, or `raw`, found `nostack`
|
||||
--> $DIR/bad-options.rs:36:25
|
||||
--> $DIR/bad-options.rs:39:25
|
||||
|
|
||||
LL | global_asm!("", options(nostack));
|
||||
| ^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
|
||||
|
||||
error: expected one of `)`, `att_syntax`, or `raw`, found `preserves_flags`
|
||||
--> $DIR/bad-options.rs:38:25
|
||||
--> $DIR/bad-options.rs:41:25
|
||||
|
|
||||
LL | global_asm!("", options(preserves_flags));
|
||||
| ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
|
||||
|
|
@ -80,5 +89,13 @@ LL | asm!("", clobber_abi("foo"));
|
|||
|
|
||||
= note: the following ABIs are supported on this target: `C`, `system`, `efiapi`, `win64`, `sysv64`
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
error: `C` ABI specified multiple times
|
||||
--> $DIR/bad-options.rs:24:52
|
||||
|
|
||||
LL | asm!("{}", out(reg) foo, clobber_abi("C"), clobber_abi("C"));
|
||||
| ---------------- ^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| previously specified here
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
|
||||
|
|
|
|||
33
src/test/ui/asm/x86_64/multiple-clobber-abi.rs
Normal file
33
src/test/ui/asm/x86_64/multiple-clobber-abi.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// run-pass
|
||||
// needs-asm-support
|
||||
// only-x86_64
|
||||
|
||||
// Checks that multiple clobber_abi options can be used
|
||||
|
||||
#![feature(asm, asm_sym)]
|
||||
|
||||
extern "sysv64" fn foo(x: i32) -> i32 {
|
||||
x + 16
|
||||
}
|
||||
|
||||
extern "win64" fn bar(x: i32) -> i32 {
|
||||
x / 2
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = 8;
|
||||
let y: i32;
|
||||
// call `foo` with `x` as the input, and then `bar` with the output of `foo`
|
||||
// and output that to `y`
|
||||
unsafe {
|
||||
asm!(
|
||||
"call {}; mov rcx, rax; call {}",
|
||||
sym foo,
|
||||
sym bar,
|
||||
in("rdi") x,
|
||||
out("rax") y,
|
||||
clobber_abi("sysv64", "win64"),
|
||||
);
|
||||
}
|
||||
assert_eq!((x, y), (8, 12));
|
||||
}
|
||||
|
|
@ -37,12 +37,14 @@ fn main() {
|
|||
asm!("{}", options(), const foo);
|
||||
//~^ ERROR arguments are not allowed after options
|
||||
//~^^ ERROR attempt to use a non-constant value in a constant
|
||||
asm!("", clobber_abi());
|
||||
//~^ ERROR at least one abi must be provided
|
||||
asm!("", clobber_abi(foo));
|
||||
//~^ ERROR expected string literal
|
||||
asm!("", clobber_abi("C" foo));
|
||||
//~^ ERROR expected `)`, found `foo`
|
||||
//~^ ERROR expected one of `)` or `,`, found `foo`
|
||||
asm!("", clobber_abi("C", foo));
|
||||
//~^ ERROR expected `)`, found `,`
|
||||
//~^ ERROR expected string literal
|
||||
asm!("{}", clobber_abi("C"), const foo);
|
||||
//~^ ERROR arguments are not allowed after clobber_abi
|
||||
//~^^ ERROR attempt to use a non-constant value in a constant
|
||||
|
|
@ -50,8 +52,6 @@ fn main() {
|
|||
//~^ ERROR clobber_abi is not allowed after options
|
||||
asm!("{}", options(), clobber_abi("C"), const foo);
|
||||
//~^ ERROR clobber_abi is not allowed after options
|
||||
asm!("", clobber_abi("C"), clobber_abi("C"));
|
||||
//~^ ERROR clobber_abi specified multiple times
|
||||
asm!("{a}", a = const foo, a = const bar);
|
||||
//~^ ERROR duplicate argument named `a`
|
||||
//~^^ ERROR argument never used
|
||||
|
|
@ -110,9 +110,9 @@ global_asm!("{}", options(), const FOO);
|
|||
global_asm!("", clobber_abi(FOO));
|
||||
//~^ ERROR expected string literal
|
||||
global_asm!("", clobber_abi("C" FOO));
|
||||
//~^ ERROR expected `)`, found `FOO`
|
||||
//~^ ERROR expected one of `)` or `,`, found `FOO`
|
||||
global_asm!("", clobber_abi("C", FOO));
|
||||
//~^ ERROR expected `)`, found `,`
|
||||
//~^ ERROR expected string literal
|
||||
global_asm!("{}", clobber_abi("C"), const FOO);
|
||||
//~^ ERROR arguments are not allowed after clobber_abi
|
||||
//~^^ ERROR `clobber_abi` cannot be used with `global_asm!`
|
||||
|
|
@ -121,7 +121,7 @@ global_asm!("", options(), clobber_abi("C"));
|
|||
global_asm!("{}", options(), clobber_abi("C"), const FOO);
|
||||
//~^ ERROR clobber_abi is not allowed after options
|
||||
global_asm!("", clobber_abi("C"), clobber_abi("C"));
|
||||
//~^ ERROR clobber_abi specified multiple times
|
||||
//~^ ERROR `clobber_abi` cannot be used with `global_asm!`
|
||||
global_asm!("{a}", a = const FOO, a = const BAR);
|
||||
//~^ ERROR duplicate argument named `a`
|
||||
//~^^ ERROR argument never used
|
||||
|
|
|
|||
|
|
@ -90,26 +90,32 @@ LL | asm!("{}", options(), const foo);
|
|||
| |
|
||||
| previous options
|
||||
|
||||
error: expected string literal
|
||||
error: at least one abi must be provided as an argument to `clobber_abi`
|
||||
--> $DIR/parse-error.rs:40:30
|
||||
|
|
||||
LL | asm!("", clobber_abi());
|
||||
| ^
|
||||
|
||||
error: expected string literal
|
||||
--> $DIR/parse-error.rs:42:30
|
||||
|
|
||||
LL | asm!("", clobber_abi(foo));
|
||||
| ^^^ not a string literal
|
||||
|
||||
error: expected `)`, found `foo`
|
||||
--> $DIR/parse-error.rs:42:34
|
||||
error: expected one of `)` or `,`, found `foo`
|
||||
--> $DIR/parse-error.rs:44:34
|
||||
|
|
||||
LL | asm!("", clobber_abi("C" foo));
|
||||
| ^^^ expected `)`
|
||||
| ^^^ expected one of `)` or `,`
|
||||
|
||||
error: expected `)`, found `,`
|
||||
--> $DIR/parse-error.rs:44:33
|
||||
error: expected string literal
|
||||
--> $DIR/parse-error.rs:46:35
|
||||
|
|
||||
LL | asm!("", clobber_abi("C", foo));
|
||||
| ^ expected `)`
|
||||
| ^^^ not a string literal
|
||||
|
||||
error: arguments are not allowed after clobber_abi
|
||||
--> $DIR/parse-error.rs:46:38
|
||||
--> $DIR/parse-error.rs:48:38
|
||||
|
|
||||
LL | asm!("{}", clobber_abi("C"), const foo);
|
||||
| ---------------- ^^^^^^^^^ argument
|
||||
|
|
@ -117,7 +123,7 @@ LL | asm!("{}", clobber_abi("C"), const foo);
|
|||
| clobber_abi
|
||||
|
||||
error: clobber_abi is not allowed after options
|
||||
--> $DIR/parse-error.rs:49:29
|
||||
--> $DIR/parse-error.rs:51:29
|
||||
|
|
||||
LL | asm!("", options(), clobber_abi("C"));
|
||||
| --------- ^^^^^^^^^^^^^^^^
|
||||
|
|
@ -125,21 +131,13 @@ LL | asm!("", options(), clobber_abi("C"));
|
|||
| options
|
||||
|
||||
error: clobber_abi is not allowed after options
|
||||
--> $DIR/parse-error.rs:51:31
|
||||
--> $DIR/parse-error.rs:53:31
|
||||
|
|
||||
LL | asm!("{}", options(), clobber_abi("C"), const foo);
|
||||
| --------- ^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| options
|
||||
|
||||
error: clobber_abi specified multiple times
|
||||
--> $DIR/parse-error.rs:53:36
|
||||
|
|
||||
LL | asm!("", clobber_abi("C"), clobber_abi("C"));
|
||||
| ---------------- ^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| clobber_abi previously specified here
|
||||
|
||||
error: duplicate argument named `a`
|
||||
--> $DIR/parse-error.rs:55:36
|
||||
|
|
||||
|
|
@ -300,17 +298,17 @@ error: expected string literal
|
|||
LL | global_asm!("", clobber_abi(FOO));
|
||||
| ^^^ not a string literal
|
||||
|
||||
error: expected `)`, found `FOO`
|
||||
error: expected one of `)` or `,`, found `FOO`
|
||||
--> $DIR/parse-error.rs:112:33
|
||||
|
|
||||
LL | global_asm!("", clobber_abi("C" FOO));
|
||||
| ^^^ expected `)`
|
||||
| ^^^ expected one of `)` or `,`
|
||||
|
||||
error: expected `)`, found `,`
|
||||
--> $DIR/parse-error.rs:114:32
|
||||
error: expected string literal
|
||||
--> $DIR/parse-error.rs:114:34
|
||||
|
|
||||
LL | global_asm!("", clobber_abi("C", FOO));
|
||||
| ^ expected `)`
|
||||
| ^^^ not a string literal
|
||||
|
||||
error: arguments are not allowed after clobber_abi
|
||||
--> $DIR/parse-error.rs:116:37
|
||||
|
|
@ -342,13 +340,11 @@ LL | global_asm!("{}", options(), clobber_abi("C"), const FOO);
|
|||
| |
|
||||
| options
|
||||
|
||||
error: clobber_abi specified multiple times
|
||||
--> $DIR/parse-error.rs:123:35
|
||||
error: `clobber_abi` cannot be used with `global_asm!`
|
||||
--> $DIR/parse-error.rs:123:17
|
||||
|
|
||||
LL | global_asm!("", clobber_abi("C"), clobber_abi("C"));
|
||||
| ---------------- ^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| clobber_abi previously specified here
|
||||
| ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: duplicate argument named `a`
|
||||
--> $DIR/parse-error.rs:125:35
|
||||
|
|
@ -404,7 +400,7 @@ LL | asm!("{}", options(), const foo);
|
|||
| ^^^ non-constant value
|
||||
|
||||
error[E0435]: attempt to use a non-constant value in a constant
|
||||
--> $DIR/parse-error.rs:46:44
|
||||
--> $DIR/parse-error.rs:48:44
|
||||
|
|
||||
LL | let mut foo = 0;
|
||||
| ---------- help: consider using `const` instead of `let`: `const foo`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue