Auto merge of #84658 - Amanieu:reserved_regs, r=petrochenkov
Be stricter about rejecting LLVM reserved registers in asm! LLVM will silently produce incorrect code if these registers are used as operands. cc `@rust-lang/wg-inline-asm`
This commit is contained in:
commit
603a42ec54
11 changed files with 66 additions and 27 deletions
|
@ -85,8 +85,6 @@ def_regs! {
|
|||
x15: reg = ["x15", "w15"],
|
||||
x16: reg = ["x16", "w16"],
|
||||
x17: reg = ["x17", "w17"],
|
||||
x18: reg = ["x18", "w18"],
|
||||
x19: reg = ["x19", "w19"],
|
||||
x20: reg = ["x20", "w20"],
|
||||
x21: reg = ["x21", "w21"],
|
||||
x22: reg = ["x22", "w22"],
|
||||
|
@ -96,7 +94,7 @@ def_regs! {
|
|||
x26: reg = ["x26", "w26"],
|
||||
x27: reg = ["x27", "w27"],
|
||||
x28: reg = ["x28", "w28"],
|
||||
x30: reg = ["x30", "w30", "lr"],
|
||||
x30: reg = ["x30", "w30", "lr", "wlr"],
|
||||
v0: vreg, vreg_low16 = ["v0", "b0", "h0", "s0", "d0", "q0"],
|
||||
v1: vreg, vreg_low16 = ["v1", "b1", "h1", "s1", "d1", "q1"],
|
||||
v2: vreg, vreg_low16 = ["v2", "b2", "h2", "s2", "d2", "q2"],
|
||||
|
@ -129,7 +127,11 @@ def_regs! {
|
|||
v29: vreg = ["v29", "b29", "h29", "s29", "d29", "q29"],
|
||||
v30: vreg = ["v30", "b30", "h30", "s30", "d30", "q30"],
|
||||
v31: vreg = ["v31", "b31", "h31", "s31", "d31", "q31"],
|
||||
#error = ["x29", "fp"] =>
|
||||
#error = ["x18", "w18"] =>
|
||||
"x18 is used as a reserved register on some targets and cannot be used as an operand for inline asm",
|
||||
#error = ["x19", "w19"] =>
|
||||
"x19 is used internally by LLVM and cannot be used as an operand for inline asm",
|
||||
#error = ["x29", "w29", "fp", "wfp"] =>
|
||||
"the frame pointer cannot be used as an operand for inline asm",
|
||||
#error = ["sp", "wsp"] =>
|
||||
"the stack pointer cannot be used as an operand for inline asm",
|
||||
|
|
|
@ -98,7 +98,6 @@ def_regs! {
|
|||
r5: reg, reg_thumb = ["r5", "v2"],
|
||||
r7: reg, reg_thumb = ["r7", "v4"] % frame_pointer_r7,
|
||||
r8: reg = ["r8", "v5"],
|
||||
r9: reg = ["r9", "v6", "rfp"],
|
||||
r10: reg = ["r10", "sl"],
|
||||
r11: reg = ["r11", "fp"] % frame_pointer_r11,
|
||||
r12: reg = ["r12", "ip"],
|
||||
|
@ -185,6 +184,8 @@ def_regs! {
|
|||
q15: qreg = ["q15"],
|
||||
#error = ["r6", "v3"] =>
|
||||
"r6 is used internally by LLVM and cannot be used as an operand for inline asm",
|
||||
#error = ["r9", "v6", "rfp"] =>
|
||||
"r9 is used internally by LLVM and cannot be used as an operand for inline asm",
|
||||
#error = ["r13", "sp"] =>
|
||||
"the stack pointer cannot be used as an operand for inline asm",
|
||||
#error = ["r15", "pc"] =>
|
||||
|
|
|
@ -60,7 +60,6 @@ def_regs! {
|
|||
r16: reg = ["r16"],
|
||||
r17: reg = ["r17"],
|
||||
r18: reg = ["r18"],
|
||||
r19: reg = ["r19"],
|
||||
r20: reg = ["r20"],
|
||||
r21: reg = ["r21"],
|
||||
r22: reg = ["r22"],
|
||||
|
@ -70,6 +69,8 @@ def_regs! {
|
|||
r26: reg = ["r26"],
|
||||
r27: reg = ["r27"],
|
||||
r28: reg = ["r28"],
|
||||
#error = ["r19"] =>
|
||||
"r19 is used internally by LLVM and cannot be used as an operand for inline asm",
|
||||
#error = ["r29", "sp"] =>
|
||||
"the stack pointer cannot be used as an operand for inline asm",
|
||||
#error = ["r30", "fr"] =>
|
||||
|
|
|
@ -66,7 +66,6 @@ def_regs! {
|
|||
x5: reg = ["x5", "t0"],
|
||||
x6: reg = ["x6", "t1"],
|
||||
x7: reg = ["x7", "t2"],
|
||||
x9: reg = ["x9", "s1"],
|
||||
x10: reg = ["x10", "a0"],
|
||||
x11: reg = ["x11", "a1"],
|
||||
x12: reg = ["x12", "a2"],
|
||||
|
@ -121,6 +120,8 @@ def_regs! {
|
|||
f29: freg = ["f29", "ft9"],
|
||||
f30: freg = ["f30", "ft10"],
|
||||
f31: freg = ["f31", "ft11"],
|
||||
#error = ["x9", "s1"] =>
|
||||
"s1 is used internally by LLVM and cannot be used as an operand for inline asm",
|
||||
#error = ["x8", "s0", "fp"] =>
|
||||
"the frame pointer cannot be used as an operand for inline asm",
|
||||
#error = ["x2", "sp"] =>
|
||||
|
|
|
@ -152,13 +152,41 @@ fn high_byte(
|
|||
}
|
||||
}
|
||||
|
||||
fn rbx_reserved(
|
||||
arch: InlineAsmArch,
|
||||
_has_feature: impl FnMut(&str) -> bool,
|
||||
_target: &Target,
|
||||
) -> Result<(), &'static str> {
|
||||
match arch {
|
||||
InlineAsmArch::X86 => Ok(()),
|
||||
InlineAsmArch::X86_64 => {
|
||||
Err("rbx is used internally by LLVM and cannot be used as an operand for inline asm")
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn esi_reserved(
|
||||
arch: InlineAsmArch,
|
||||
_has_feature: impl FnMut(&str) -> bool,
|
||||
_target: &Target,
|
||||
) -> Result<(), &'static str> {
|
||||
match arch {
|
||||
InlineAsmArch::X86 => {
|
||||
Err("esi is used internally by LLVM and cannot be used as an operand for inline asm")
|
||||
}
|
||||
InlineAsmArch::X86_64 => Ok(()),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
def_regs! {
|
||||
X86 X86InlineAsmReg X86InlineAsmRegClass {
|
||||
ax: reg, reg_abcd = ["ax", "eax", "rax"],
|
||||
bx: reg, reg_abcd = ["bx", "ebx", "rbx"],
|
||||
bx: reg, reg_abcd = ["bx", "ebx", "rbx"] % rbx_reserved,
|
||||
cx: reg, reg_abcd = ["cx", "ecx", "rcx"],
|
||||
dx: reg, reg_abcd = ["dx", "edx", "rdx"],
|
||||
si: reg = ["si", "esi", "rsi"],
|
||||
si: reg = ["si", "esi", "rsi"] % esi_reserved,
|
||||
di: reg = ["di", "edi", "rdi"],
|
||||
r8: reg = ["r8", "r8w", "r8d"] % x86_64_only,
|
||||
r9: reg = ["r9", "r9w", "r9d"] % x86_64_only,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue