From 20e6c1d0139df1ec315bdbfa7c46dc98fafa84ab Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Thu, 10 Feb 2022 18:04:09 +0000 Subject: [PATCH] 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`. --- compiler/rustc_ast_lowering/src/asm.rs | 4 +++- src/test/ui/asm/reg-conflict.rs | 20 ++++++++++++++++++++ src/test/ui/asm/reg-conflict.stderr | 10 ++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/asm/reg-conflict.rs create mode 100644 src/test/ui/asm/reg-conflict.stderr diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index 89d411d4b36fe..5a85356d96daa 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -373,7 +373,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { err.emit(); } Entry::Vacant(v) => { - v.insert(idx); + if r == reg { + v.insert(idx); + } } } }; diff --git a/src/test/ui/asm/reg-conflict.rs b/src/test/ui/asm/reg-conflict.rs new file mode 100644 index 0000000000000..983788a93ccd9 --- /dev/null +++ b/src/test/ui/asm/reg-conflict.rs @@ -0,0 +1,20 @@ +// compile-flags: --target armv7-unknown-linux-gnueabihf +// needs-llvm-components: arm + +#![feature(no_core, lang_items, rustc_attrs)] +#![no_core] + +#[rustc_builtin_macro] +macro_rules! asm { + () => {}; +} +#[lang = "sized"] +trait Sized {} + +fn main() { + unsafe { + asm!("", out("d0") _, out("d1") _); + asm!("", out("d0") _, out("s1") _); + //~^ ERROR register `s1` conflicts with register `d0` + } +} diff --git a/src/test/ui/asm/reg-conflict.stderr b/src/test/ui/asm/reg-conflict.stderr new file mode 100644 index 0000000000000..2395566de3945 --- /dev/null +++ b/src/test/ui/asm/reg-conflict.stderr @@ -0,0 +1,10 @@ +error: register `s1` conflicts with register `d0` + --> $DIR/reg-conflict.rs:17:31 + | +LL | asm!("", out("d0") _, out("s1") _); + | ----------- ^^^^^^^^^^^ register `s1` + | | + | register `d0` + +error: aborting due to previous error +