-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Allow multiple asm!
options groups and report an error on duplicate options
#73227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c883fa4
Allow multiple `asm!` options
camelid e614116
Update tests
camelid 1d2acdf
Use `Vec<Span>` instead of `Option<Vec<Span>>`
camelid 27cc7c7
Clean up
camelid 820bba1
Add codegen test for multiple `asm!` options
camelid 2be403c
Warn on duplicate `asm!` options
camelid 7aaadb6
Add UI test for duplicate `asm!` options warning
camelid b94b7e7
Make warning an error; use help instead of suggestion; clean up code
camelid ac54265
Use `span_label`
camelid 7c5b66f
Update duplicate options test
camelid c7da50d
Get option name from symbol instead of snippet
camelid e8be797
Use bitflags function instead of custom one
camelid b00b1a4
Use `span_suggestion` instead of `span_label`
camelid f4dfc61
Add more to duplicate options test
camelid 4ba6697
Make suggestion machine-applicable
camelid 8fe6710
Create a separate, tool-only suggestion for the comma
camelid db9d376
Add documentation
camelid 58f812b
Use `p.token` instead of `p.look_ahead()`
camelid 8d80cc5
Fix duplicate options error
camelid c31785a
Run `./x.py fmt`
camelid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.