Skip to content

Commit fbd30ea

Browse files
committed
show supported register classes
in inline assembly, show the supported register classes when an invalid one is found
1 parent cf577f3 commit fbd30ea

File tree

7 files changed

+23
-8
lines changed

7 files changed

+23
-8
lines changed

compiler/rustc_ast_lowering/messages.ftl

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ ast_lowering_invalid_register =
112112
invalid register `{$reg}`: {$error}
113113
114114
ast_lowering_invalid_register_class =
115-
invalid register class `{$reg_class}`: {$error}
115+
invalid register class `{$reg_class}`: unknown register class
116+
.note = the following register classes are supported on this target: {$supported_register_classes}
116117
117118
ast_lowering_match_arm_with_no_body =
118119
`match` arm with no body

compiler/rustc_ast_lowering/src/asm.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
152152
InlineAsmRegOrRegClass::RegClass(reg_class) => {
153153
asm::InlineAsmRegOrRegClass::RegClass(if let Some(asm_arch) = asm_arch {
154154
asm::InlineAsmRegClass::parse(asm_arch, reg_class).unwrap_or_else(
155-
|error| {
155+
|supported_register_classes| {
156+
let mut register_classes =
157+
format!("`{}`", supported_register_classes[0]);
158+
for m in &supported_register_classes[1..] {
159+
let _ = write!(register_classes, ", `{m}`");
160+
}
156161
self.dcx().emit_err(InvalidRegisterClass {
157162
op_span: *op_sp,
158163
reg_class,
159-
error,
164+
supported_register_classes: register_classes,
160165
});
161166
asm::InlineAsmRegClass::Err
162167
},

compiler/rustc_ast_lowering/src/errors.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,13 @@ pub(crate) struct InvalidRegister<'a> {
212212
}
213213

214214
#[derive(Diagnostic)]
215+
#[note]
215216
#[diag(ast_lowering_invalid_register_class)]
216-
pub(crate) struct InvalidRegisterClass<'a> {
217+
pub(crate) struct InvalidRegisterClass {
217218
#[primary_span]
218219
pub op_span: Span,
219220
pub reg_class: Symbol,
220-
pub error: &'a str,
221+
pub supported_register_classes: String,
221222
}
222223

223224
#[derive(Diagnostic)]

compiler/rustc_target/src/asm/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ macro_rules! def_reg_class {
3939
}
4040
}
4141

42-
pub fn parse(name: rustc_span::Symbol) -> Result<Self, &'static str> {
42+
pub fn parse(name: rustc_span::Symbol) -> Result<Self, &'static [rustc_span::Symbol]> {
4343
match name {
4444
$(
4545
rustc_span::sym::$class => Ok(Self::$class),
4646
)*
47-
_ => Err("unknown register class"),
47+
_ => Err(&[$(rustc_span::sym::$class),*]),
4848
}
4949
}
5050
}
@@ -635,7 +635,7 @@ impl InlineAsmRegClass {
635635
}
636636
}
637637

638-
pub fn parse(arch: InlineAsmArch, name: Symbol) -> Result<Self, &'static str> {
638+
pub fn parse(arch: InlineAsmArch, name: Symbol) -> Result<Self, &'static [rustc_span::Symbol]> {
639639
Ok(match arch {
640640
InlineAsmArch::X86 | InlineAsmArch::X86_64 => {
641641
Self::X86(X86InlineAsmRegClass::parse(name)?)

tests/ui/asm/aarch64/bad-reg.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: invalid register class `foo`: unknown register class
33
|
44
LL | asm!("{}", in(foo) foo);
55
| ^^^^^^^^^^^
6+
|
7+
= note: the following register classes are supported on this target: `reg`, `vreg`, `vreg_low16`, `preg`
68

79
error: invalid register `foo`: unknown register
810
--> $DIR/bad-reg.rs:14:18

tests/ui/asm/x86_64/bad-reg.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: invalid register class `foo`: unknown register class
33
|
44
LL | asm!("{}", in(foo) foo);
55
| ^^^^^^^^^^^
6+
|
7+
= 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`
68

79
error: invalid register `foo`: unknown register
810
--> $DIR/bad-reg.rs:14:18

tests/ui/asm/x86_64/issue-82869.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ error: invalid register class `vreg`: unknown register class
33
|
44
LL | asm!("add {:d}, {:d}, d0", out(vreg) c, in(vreg) a, in("d0") {
55
| ^^^^^^^^^^^
6+
|
7+
= 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`
68

79
error: invalid register class `vreg`: unknown register class
810
--> $DIR/issue-82869.rs:11:45
911
|
1012
LL | asm!("add {:d}, {:d}, d0", out(vreg) c, in(vreg) a, in("d0") {
1113
| ^^^^^^^^^^
14+
|
15+
= 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`
1216

1317
error: invalid register `d0`: unknown register
1418
--> $DIR/issue-82869.rs:11:57

0 commit comments

Comments
 (0)