Skip to content

show supported register classes in error message #136239

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 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ ast_lowering_invalid_register =
invalid register `{$reg}`: {$error}

ast_lowering_invalid_register_class =
invalid register class `{$reg_class}`: {$error}
invalid register class `{$reg_class}`: unknown register class
.note = the following register classes are supported on this target: {$supported_register_classes}

ast_lowering_match_arm_with_no_body =
`match` arm with no body
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
InlineAsmRegOrRegClass::RegClass(reg_class) => {
asm::InlineAsmRegOrRegClass::RegClass(if let Some(asm_arch) = asm_arch {
asm::InlineAsmRegClass::parse(asm_arch, reg_class).unwrap_or_else(
|error| {
|supported_register_classes| {
let mut register_classes =
format!("`{}`", supported_register_classes[0]);
for m in &supported_register_classes[1..] {
let _ = write!(register_classes, ", `{m}`");
}
self.dcx().emit_err(InvalidRegisterClass {
op_span: *op_sp,
reg_class,
error,
supported_register_classes: register_classes,
});
asm::InlineAsmRegClass::Err
},
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,13 @@ pub(crate) struct InvalidRegister<'a> {
}

#[derive(Diagnostic)]
#[note]
#[diag(ast_lowering_invalid_register_class)]
pub(crate) struct InvalidRegisterClass<'a> {
pub(crate) struct InvalidRegisterClass {
#[primary_span]
pub op_span: Span,
pub reg_class: Symbol,
pub error: &'a str,
pub supported_register_classes: String,
}

#[derive(Diagnostic)]
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_target/src/asm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ macro_rules! def_reg_class {
}
}

pub fn parse(name: rustc_span::Symbol) -> Result<Self, &'static str> {
pub fn parse(name: rustc_span::Symbol) -> Result<Self, &'static [rustc_span::Symbol]> {
match name {
$(
rustc_span::sym::$class => Ok(Self::$class),
)*
_ => Err("unknown register class"),
_ => Err(&[$(rustc_span::sym::$class),*]),
}
}
}
Expand Down Expand Up @@ -635,7 +635,7 @@ impl InlineAsmRegClass {
}
}

pub fn parse(arch: InlineAsmArch, name: Symbol) -> Result<Self, &'static str> {
pub fn parse(arch: InlineAsmArch, name: Symbol) -> Result<Self, &'static [rustc_span::Symbol]> {
Ok(match arch {
InlineAsmArch::X86 | InlineAsmArch::X86_64 => {
Self::X86(X86InlineAsmRegClass::parse(name)?)
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/asm/aarch64/bad-reg.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error: invalid register class `foo`: unknown register class
|
LL | asm!("{}", in(foo) foo);
| ^^^^^^^^^^^
|
= note: the following register classes are supported on this target: `reg`, `vreg`, `vreg_low16`, `preg`

error: invalid register `foo`: unknown register
--> $DIR/bad-reg.rs:14:18
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/asm/x86_64/bad-reg.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error: invalid register class `foo`: unknown register class
|
LL | asm!("{}", in(foo) foo);
| ^^^^^^^^^^^
|
= note: the following register classes are supported on this target: `reg`, `reg_abcd`, `reg_byte`, `xmm_reg`, `ymm_reg`, `zmm_reg`, `kreg`, `kreg0`, `mmx_reg`, `x87_reg`, `tmm_reg`

error: invalid register `foo`: unknown register
--> $DIR/bad-reg.rs:14:18
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/asm/x86_64/issue-82869.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ error: invalid register class `vreg`: unknown register class
|
LL | asm!("add {:d}, {:d}, d0", out(vreg) c, in(vreg) a, in("d0") {
| ^^^^^^^^^^^
|
= note: the following register classes are supported on this target: `reg`, `reg_abcd`, `reg_byte`, `xmm_reg`, `ymm_reg`, `zmm_reg`, `kreg`, `kreg0`, `mmx_reg`, `x87_reg`, `tmm_reg`

error: invalid register class `vreg`: unknown register class
--> $DIR/issue-82869.rs:11:45
|
LL | asm!("add {:d}, {:d}, d0", out(vreg) c, in(vreg) a, in("d0") {
| ^^^^^^^^^^
|
= note: the following register classes are supported on this target: `reg`, `reg_abcd`, `reg_byte`, `xmm_reg`, `ymm_reg`, `zmm_reg`, `kreg`, `kreg0`, `mmx_reg`, `x87_reg`, `tmm_reg`

error: invalid register `d0`: unknown register
--> $DIR/issue-82869.rs:11:57
Expand Down
Loading