-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #73227 - camelid:multiple-asm-options, r=Amanieu
Allow multiple `asm!` options groups and report an error on duplicate options Fixes #73193 Cc @joshtriplett @Amanieu - [x] Allow multiple options - [x] Update existing test - [x] Add new tests - [x] Check for duplicate options - [x] Add duplicate options tests - [x] Finalize suggestion format for duplicate options error
- Loading branch information
Showing
7 changed files
with
236 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// compile-flags: -O | ||
// only-x86_64 | ||
|
||
#![crate_type = "rlib"] | ||
#![feature(asm)] | ||
|
||
// CHECK-LABEL: @pure | ||
// CHECK-NOT: asm | ||
// CHECK: ret void | ||
#[no_mangle] | ||
pub unsafe fn pure(x: i32) { | ||
let y: i32; | ||
asm!("", out("ax") y, in("bx") x, options(pure), options(nomem)); | ||
} | ||
|
||
pub static mut VAR: i32 = 0; | ||
pub static mut DUMMY_OUTPUT: i32 = 0; | ||
|
||
// CHECK-LABEL: @readonly | ||
// CHECK: call i32 asm | ||
// CHECK: ret i32 1 | ||
#[no_mangle] | ||
pub unsafe fn readonly() -> i32 { | ||
VAR = 1; | ||
asm!("", out("ax") DUMMY_OUTPUT, options(pure), options(readonly)); | ||
VAR | ||
} | ||
|
||
// CHECK-LABEL: @nomem | ||
// CHECK-NOT: store | ||
// CHECK: call i32 asm | ||
// CHECK: store | ||
// CHECK: ret i32 2 | ||
#[no_mangle] | ||
pub unsafe fn nomem() -> i32 { | ||
VAR = 1; | ||
asm!("", out("ax") DUMMY_OUTPUT, options(pure), options(nomem)); | ||
VAR = 2; | ||
VAR | ||
} | ||
|
||
// CHECK-LABEL: @not_nomem | ||
// CHECK: store | ||
// CHECK: call i32 asm | ||
// CHECK: store | ||
// CHECK: ret i32 2 | ||
#[no_mangle] | ||
pub unsafe fn not_nomem() -> i32 { | ||
VAR = 1; | ||
asm!("", out("ax") DUMMY_OUTPUT, options(pure), options(readonly)); | ||
VAR = 2; | ||
VAR | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// only-x86_64 | ||
// run-rustfix | ||
|
||
#![feature(asm)] | ||
|
||
fn main() { | ||
unsafe { | ||
asm!("", options(nomem, )); | ||
//~^ ERROR the `nomem` option was already provided | ||
asm!("", options(att_syntax, )); | ||
//~^ ERROR the `att_syntax` option was already provided | ||
asm!("", options(nostack, att_syntax), options()); | ||
//~^ ERROR the `nostack` option was already provided | ||
asm!("", options(nostack, ), options(), options()); | ||
//~^ ERROR the `nostack` option was already provided | ||
//~| ERROR the `nostack` option was already provided | ||
//~| ERROR the `nostack` option was already provided | ||
asm!( | ||
"", | ||
options(nomem, noreturn), | ||
options(att_syntax, ), //~ ERROR the `noreturn` option was already provided | ||
options( nostack), //~ ERROR the `nomem` option was already provided | ||
options(), //~ ERROR the `noreturn` option was already provided | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// only-x86_64 | ||
// run-rustfix | ||
|
||
#![feature(asm)] | ||
|
||
fn main() { | ||
unsafe { | ||
asm!("", options(nomem, nomem)); | ||
//~^ ERROR the `nomem` option was already provided | ||
asm!("", options(att_syntax, att_syntax)); | ||
//~^ ERROR the `att_syntax` option was already provided | ||
asm!("", options(nostack, att_syntax), options(nostack)); | ||
//~^ ERROR the `nostack` option was already provided | ||
asm!("", options(nostack, nostack), options(nostack), options(nostack)); | ||
//~^ ERROR the `nostack` option was already provided | ||
//~| ERROR the `nostack` option was already provided | ||
//~| ERROR the `nostack` option was already provided | ||
asm!( | ||
"", | ||
options(nomem, noreturn), | ||
options(att_syntax, noreturn), //~ ERROR the `noreturn` option was already provided | ||
options(nomem, nostack), //~ ERROR the `nomem` option was already provided | ||
options(noreturn), //~ ERROR the `noreturn` option was already provided | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
error: the `nomem` option was already provided | ||
--> $DIR/duplicate-options.rs:8:33 | ||
| | ||
LL | asm!("", options(nomem, nomem)); | ||
| ^^^^^ this option was already provided | ||
|
||
error: the `att_syntax` option was already provided | ||
--> $DIR/duplicate-options.rs:10:38 | ||
| | ||
LL | asm!("", options(att_syntax, att_syntax)); | ||
| ^^^^^^^^^^ this option was already provided | ||
|
||
error: the `nostack` option was already provided | ||
--> $DIR/duplicate-options.rs:12:56 | ||
| | ||
LL | asm!("", options(nostack, att_syntax), options(nostack)); | ||
| ^^^^^^^ this option was already provided | ||
|
||
error: the `nostack` option was already provided | ||
--> $DIR/duplicate-options.rs:14:35 | ||
| | ||
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack)); | ||
| ^^^^^^^ this option was already provided | ||
|
||
error: the `nostack` option was already provided | ||
--> $DIR/duplicate-options.rs:14:53 | ||
| | ||
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack)); | ||
| ^^^^^^^ this option was already provided | ||
|
||
error: the `nostack` option was already provided | ||
--> $DIR/duplicate-options.rs:14:71 | ||
| | ||
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack)); | ||
| ^^^^^^^ this option was already provided | ||
|
||
error: the `noreturn` option was already provided | ||
--> $DIR/duplicate-options.rs:21:33 | ||
| | ||
LL | options(att_syntax, noreturn), | ||
| ^^^^^^^^ this option was already provided | ||
|
||
error: the `nomem` option was already provided | ||
--> $DIR/duplicate-options.rs:22:21 | ||
| | ||
LL | options(nomem, nostack), | ||
| ^^^^^ this option was already provided | ||
|
||
error: the `noreturn` option was already provided | ||
--> $DIR/duplicate-options.rs:23:21 | ||
| | ||
LL | options(noreturn), | ||
| ^^^^^^^^ this option was already provided | ||
|
||
error: aborting due to 9 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.