Repository navigation
Preserve explicit register names in inline asm diagnostics #160068
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
rust-bors
merged 2 commits into
rust-lang:main
from
qaijuang:fix-asm-register-alias-diagnostic
Sep 25, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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,51 @@ | ||
| // Check that inline assembly diagnostics use the explicit register name from the source. | ||
| // | ||
| // On 32-bit x86, vector registers 8 and higher are unavailable. Registers 16 through 31 | ||
| // share a canonical `zmm` representation, but diagnostics must still use the `xmm`, `ymm`, | ||
| // or `zmm` name that the user wrote. | ||
| // | ||
| // Regression test for <https://github.com/rust-lang/rust/issues/159409>. | ||
|
|
||
| //@ add-minicore | ||
| //@ revisions: x86 x86_64 | ||
| //@[x86] compile-flags: --target i686-unknown-linux-gnu | ||
| //@[x86] needs-llvm-components: x86 | ||
| //@[x86] check-fail | ||
| //@[x86_64] compile-flags: --target x86_64-unknown-linux-gnu | ||
| //@[x86_64] needs-llvm-components: x86 | ||
| //@[x86_64] check-pass | ||
| //@ ignore-backends: gcc | ||
|
|
||
| #![feature(no_core)] | ||
| #![no_core] | ||
|
|
||
| extern crate minicore; | ||
| use minicore::*; | ||
|
|
||
| fn main() { | ||
| unsafe { | ||
| // Register 15 is the last register with separate canonical representations. | ||
| asm!("", lateout("xmm15") _); | ||
| //[x86]~^ ERROR cannot use register `xmm15` | ||
| asm!("", lateout("ymm15") _); | ||
| //[x86]~^ ERROR cannot use register `ymm15` | ||
| asm!("", lateout("zmm15") _); | ||
| //[x86]~^ ERROR cannot use register `zmm15` | ||
|
|
||
| // Register 16 is the first register whose aliases share the canonical `zmm` representation. | ||
| asm!("", lateout("xmm16") _); | ||
| //[x86]~^ ERROR cannot use register `xmm16` | ||
| asm!("", lateout("ymm16") _); | ||
| //[x86]~^ ERROR cannot use register `ymm16` | ||
| asm!("", lateout("zmm16") _); | ||
| //[x86]~^ ERROR cannot use register `zmm16` | ||
|
|
||
| // Register 31 is the upper boundary of the affected register range. | ||
| asm!("", lateout("xmm31") _); | ||
| //[x86]~^ ERROR cannot use register `xmm31` | ||
| asm!("", lateout("ymm31") _); | ||
| //[x86]~^ ERROR cannot use register `ymm31` | ||
| asm!("", lateout("zmm31") _); | ||
| //[x86]~^ ERROR cannot use register `zmm31` | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
tests/ui/asm/x86-explicit-register-alias-diagnostic.x86.stderr
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: cannot use register `xmm15`: register is only available on x86_64 | ||
| --> $DIR/x86-explicit-register-alias-diagnostic.rs:28:18 | ||
| | | ||
| LL | asm!("", lateout("xmm15") _); | ||
| | ^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: cannot use register `ymm15`: register is only available on x86_64 | ||
| --> $DIR/x86-explicit-register-alias-diagnostic.rs:30:18 | ||
| | | ||
| LL | asm!("", lateout("ymm15") _); | ||
| | ^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: cannot use register `zmm15`: register is only available on x86_64 | ||
| --> $DIR/x86-explicit-register-alias-diagnostic.rs:32:18 | ||
| | | ||
| LL | asm!("", lateout("zmm15") _); | ||
| | ^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: cannot use register `xmm16`: register is only available on x86_64 | ||
| --> $DIR/x86-explicit-register-alias-diagnostic.rs:36:18 | ||
| | | ||
| LL | asm!("", lateout("xmm16") _); | ||
| | ^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: cannot use register `ymm16`: register is only available on x86_64 | ||
| --> $DIR/x86-explicit-register-alias-diagnostic.rs:38:18 | ||
| | | ||
| LL | asm!("", lateout("ymm16") _); | ||
| | ^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: cannot use register `zmm16`: register is only available on x86_64 | ||
| --> $DIR/x86-explicit-register-alias-diagnostic.rs:40:18 | ||
| | | ||
| LL | asm!("", lateout("zmm16") _); | ||
| | ^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: cannot use register `xmm31`: register is only available on x86_64 | ||
| --> $DIR/x86-explicit-register-alias-diagnostic.rs:44:18 | ||
| | | ||
| LL | asm!("", lateout("xmm31") _); | ||
| | ^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: cannot use register `ymm31`: register is only available on x86_64 | ||
| --> $DIR/x86-explicit-register-alias-diagnostic.rs:46:18 | ||
| | | ||
| LL | asm!("", lateout("ymm31") _); | ||
| | ^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: cannot use register `zmm31`: register is only available on x86_64 | ||
| --> $DIR/x86-explicit-register-alias-diagnostic.rs:48:18 | ||
| | | ||
| LL | asm!("", lateout("zmm31") _); | ||
| | ^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: aborting due to 9 previous errors | ||
|
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason it shouldn't, instead of this scheme of re-adding it in metadata?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see or find any reason why it shouldn't
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I see how the PR looks like in that form instead, then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be duplicating the
InlineAsmRegOrRegClasstype and impl in HiR, is it acceptable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exact HiR impl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either variants seems fine to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@workingjubilee let me know the direction we are taking.