Skip to content

Commit 20e6c1d

Browse files
committed
Fix incorrect register conflict detection in asm!
This would previously incorrectly reject two subregisters that were distinct but part of the same larger register, for example `al` and `ah`.
1 parent 502d6aa commit 20e6c1d

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
373373
err.emit();
374374
}
375375
Entry::Vacant(v) => {
376-
v.insert(idx);
376+
if r == reg {
377+
v.insert(idx);
378+
}
377379
}
378380
}
379381
};

src/test/ui/asm/reg-conflict.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// compile-flags: --target armv7-unknown-linux-gnueabihf
2+
// needs-llvm-components: arm
3+
4+
#![feature(no_core, lang_items, rustc_attrs)]
5+
#![no_core]
6+
7+
#[rustc_builtin_macro]
8+
macro_rules! asm {
9+
() => {};
10+
}
11+
#[lang = "sized"]
12+
trait Sized {}
13+
14+
fn main() {
15+
unsafe {
16+
asm!("", out("d0") _, out("d1") _);
17+
asm!("", out("d0") _, out("s1") _);
18+
//~^ ERROR register `s1` conflicts with register `d0`
19+
}
20+
}

src/test/ui/asm/reg-conflict.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: register `s1` conflicts with register `d0`
2+
--> $DIR/reg-conflict.rs:17:31
3+
|
4+
LL | asm!("", out("d0") _, out("s1") _);
5+
| ----------- ^^^^^^^^^^^ register `s1`
6+
| |
7+
| register `d0`
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)