Skip to content

[X86][MC] Report error when the instruction length exceeds 15 bytes #83708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1924,8 +1924,8 @@ void X86MCCodeEmitter::encodeInstruction(const MCInst &MI,
if ((TSFlags & X86II::OpMapMask) == X86II::ThreeDNow)
emitByte(X86II::getBaseOpcodeFor(TSFlags), CB);

assert(CB.size() - StartByte <= 15 &&
"The size of instruction must be no longer than 15.");
if (CB.size() - StartByte > 15)
Ctx.reportError(MI.getLoc(), "instruction length exceeds the limit of 15");
#ifndef NDEBUG
// FIXME: Verify.
if (/*!Desc.isVariadic() &&*/ CurOp != NumOps) {
Expand Down
25 changes: 25 additions & 0 deletions llvm/test/MC/X86/apx/long-instruction-err.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# RUN: not llvm-mc -triple x86_64 -show-encoding %s 2>&1 | FileCheck %s

# CHECK: [[#@LINE+2]]:1: error: instruction length exceeds the limit of 15
# CHECK: addq $1234, %cs:-96, %rax
addq $1234, %cs:-96, %rax

# CHECK: [[#@LINE+2]]:1: error: instruction length exceeds the limit of 15
# CHECK: subq $1234, %fs:257(%rbx, %rcx), %rax
subq $1234, %fs:257(%rbx, %rcx), %rax

# CHECK: [[#@LINE+2]]:1: error: instruction length exceeds the limit of 15
# CHECK: orq $1234, 257(%ebx, %ecx), %rax
orq $1234, 257(%ebx, %ecx), %rax

# CHECK: [[#@LINE+2]]:1: error: instruction length exceeds the limit of 15
# CHECK: xorq $1234, %gs:257(%ebx), %rax
xorq $1234, %gs:257(%ebx), %rax

# CHECK: [[#@LINE+2]]:1: error: instruction length exceeds the limit of 15
# CHECK: {nf} andq $1234, %cs:-96
{nf} andq $1234, %cs:-96

# CHECK: [[#@LINE+2]]:1: error: instruction length exceeds the limit of 15
# CHECK: {evex} adcq $1234, %cs:-96
{evex} adcq $1234, %cs:-96