Skip to content

Commit 2c87843

Browse files
committed
Name explicit registers in conflict register errors for inline assembly
1 parent fa14810 commit 2c87843

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

compiler/rustc_ast_lowering/src/asm.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,28 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
374374
_ => None,
375375
};
376376

377+
let reg_str = |idx, default| -> &str {
378+
let (op, _): &(InlineAsmOperand, Span) = &asm.operands[idx];
379+
match op {
380+
InlineAsmOperand::In { reg, .. }
381+
| InlineAsmOperand::Out { reg, .. }
382+
| InlineAsmOperand::InOut { reg, .. }
383+
| InlineAsmOperand::SplitInOut { reg, .. } => {
384+
if let InlineAsmRegOrRegClass::Reg(reg_sym) = reg {
385+
reg_sym.as_str()
386+
} else {
387+
default
388+
}
389+
}
390+
_ => default,
391+
}
392+
};
393+
377394
sess.emit_err(RegisterConflict {
378395
op_span1: op_sp,
379396
op_span2: op_sp2,
380-
reg1_name: reg.name(),
381-
reg2_name: reg2.name(),
397+
reg1_name: reg_str(idx, reg.name()),
398+
reg2_name: reg_str(idx2, reg2.name()),
382399
in_out,
383400
});
384401
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ fn main() {
4848
// (except in/lateout which don't conflict)
4949

5050
asm!("", in("x0") foo, in("w0") bar);
51-
//~^ ERROR register `x0` conflicts with register `x0`
51+
//~^ ERROR register `w0` conflicts with register `x0`
5252
asm!("", in("x0") foo, out("x0") bar);
5353
//~^ ERROR register `x0` conflicts with register `x0`
5454
asm!("", in("w0") foo, lateout("w0") bar);
5555
asm!("", in("v0") foo, in("q0") bar);
56-
//~^ ERROR register `v0` conflicts with register `v0`
56+
//~^ ERROR register `q0` conflicts with register `v0`
5757
asm!("", in("v0") foo, out("q0") bar);
58-
//~^ ERROR register `v0` conflicts with register `v0`
58+
//~^ ERROR register `q0` conflicts with register `v0`
5959
asm!("", in("v0") foo, lateout("q0") bar);
6060
}
6161
}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ error: register class `preg` can only be used as a clobber, not as an input or o
9898
LL | asm!("{}", out(preg) _);
9999
| ^^^^^^^^^^^
100100

101-
error: register `x0` conflicts with register `x0`
101+
error: register `w0` conflicts with register `x0`
102102
--> $DIR/bad-reg.rs:50:32
103103
|
104104
LL | asm!("", in("x0") foo, in("w0") bar);
105-
| ------------ ^^^^^^^^^^^^ register `x0`
105+
| ------------ ^^^^^^^^^^^^ register `w0`
106106
| |
107107
| register `x0`
108108

@@ -120,19 +120,19 @@ help: use `lateout` instead of `out` to avoid conflict
120120
LL | asm!("", in("x0") foo, out("x0") bar);
121121
| ^^^^^^^^^^^^
122122

123-
error: register `v0` conflicts with register `v0`
123+
error: register `q0` conflicts with register `v0`
124124
--> $DIR/bad-reg.rs:55:32
125125
|
126126
LL | asm!("", in("v0") foo, in("q0") bar);
127-
| ------------ ^^^^^^^^^^^^ register `v0`
127+
| ------------ ^^^^^^^^^^^^ register `q0`
128128
| |
129129
| register `v0`
130130

131-
error: register `v0` conflicts with register `v0`
131+
error: register `q0` conflicts with register `v0`
132132
--> $DIR/bad-reg.rs:57:32
133133
|
134134
LL | asm!("", in("v0") foo, out("q0") bar);
135-
| ------------ ^^^^^^^^^^^^^ register `v0`
135+
| ------------ ^^^^^^^^^^^^^ register `q0`
136136
| |
137137
| register `v0`
138138
|

0 commit comments

Comments
 (0)