1
Fork 0

Disallow the use of high byte registes as operands on x86_64

They are still allowed on x86 though.

Fixes #83495
This commit is contained in:
Amanieu d'Antras 2021-04-04 17:44:46 +01:00
parent cbd6ec7604
commit b1bcff0731
8 changed files with 25 additions and 24 deletions

View file

@ -68,7 +68,6 @@ fn frame_pointer_r11(
_arch: InlineAsmArch,
has_feature: impl FnMut(&str) -> bool,
target: &Target,
_allocating: bool,
) -> Result<(), &'static str> {
if !frame_pointer_is_r7(has_feature, target) {
Err("the frame pointer (r11) cannot be used as an operand for inline asm")
@ -81,7 +80,6 @@ fn frame_pointer_r7(
_arch: InlineAsmArch,
has_feature: impl FnMut(&str) -> bool,
target: &Target,
_allocating: bool,
) -> Result<(), &'static str> {
if frame_pointer_is_r7(has_feature, target) {
Err("the frame pointer (r7) cannot be used as an operand for inline asm")

View file

@ -90,7 +90,7 @@ macro_rules! def_regs {
match name {
$(
$($alias)|* | $reg_name => {
$($filter(_arch, &mut _has_feature, _target, false)?;)?
$($filter(_arch, &mut _has_feature, _target)?;)?
Ok(Self::$reg)
}
)*
@ -114,7 +114,7 @@ macro_rules! def_regs {
#[allow(unused_imports)]
use super::{InlineAsmReg, InlineAsmRegClass};
$(
if $($filter(_arch, &mut _has_feature, _target, true).is_ok() &&)? true {
if $($filter(_arch, &mut _has_feature, _target).is_ok() &&)? true {
if let Some(set) = _map.get_mut(&InlineAsmRegClass::$arch($arch_regclass::$class)) {
set.insert(InlineAsmReg::$arch($arch_reg::$reg));
}

View file

@ -52,7 +52,6 @@ fn not_e(
_arch: InlineAsmArch,
mut has_feature: impl FnMut(&str) -> bool,
_target: &Target,
_allocating: bool,
) -> Result<(), &'static str> {
if has_feature("e") {
Err("register can't be used with the `e` target feature")

View file

@ -133,7 +133,6 @@ fn x86_64_only(
arch: InlineAsmArch,
_has_feature: impl FnMut(&str) -> bool,
_target: &Target,
_allocating: bool,
) -> Result<(), &'static str> {
match arch {
InlineAsmArch::X86 => Err("register is only available on x86_64"),
@ -146,13 +145,9 @@ fn high_byte(
arch: InlineAsmArch,
_has_feature: impl FnMut(&str) -> bool,
_target: &Target,
allocating: bool,
) -> Result<(), &'static str> {
match arch {
InlineAsmArch::X86_64 if allocating => {
// The error message isn't actually used...
Err("high byte registers are not allocated by reg_byte")
}
InlineAsmArch::X86_64 => Err("high byte registers cannot be used as an operand on x86_64"),
_ => Ok(()),
}
}