From 0ecd2e50146dd4dfac47b20a8e03e43a015b55ce Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Sun, 7 May 2023 02:28:44 +0800 Subject: [PATCH] [X86][MC] Reject `call`/`jmp [offset fn_ref]` in Intel syntax This syntax is confusing and likely invalid. In addition, MASM rejects it and GAS seems to behave oddly with it. Therefore we shall reject this syntax for both unconditional `call` and `jmp` instructions, as discussed in D149579. Depends on D150047 Differential Revision: https://reviews.llvm.org/D150048 --- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp | 4 ++++ llvm/test/MC/X86/intel-syntax-branch.s | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp index 2647117f0273..b30a6466992a 100644 --- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -2656,6 +2656,10 @@ bool X86AsmParser::parseIntelOperand(OperandVector &Operands, StringRef Name) { } } } else if (IsUnconditionalBranch) { + // Treat `call [offset fn_ref]` (or `jmp`) syntax as an error. + if (!PtrInOperand && SM.isOffsetOperator()) + return Error( + Start, "`OFFSET` operator cannot be used in an unconditional branch"); if (PtrInOperand || SM.isBracketUsed()) MaybeDirectBranchDest = false; } diff --git a/llvm/test/MC/X86/intel-syntax-branch.s b/llvm/test/MC/X86/intel-syntax-branch.s index 22b91562ea51..c8dcc9613cc1 100644 --- a/llvm/test/MC/X86/intel-syntax-branch.s +++ b/llvm/test/MC/X86/intel-syntax-branch.s @@ -61,6 +61,11 @@ jmp [fn_ref] .ifdef ERR + call [offset fn_ref] + // ERR-32: {{.*}}.s:[[#@LINE-1]]:8: error: `OFFSET` operator cannot be used in an unconditional branch + jmp [offset fn_ref] + // ERR-32: {{.*}}.s:[[#@LINE-1]]:7: error: `OFFSET` operator cannot be used in an unconditional branch + call offset fn_ref // ERR-32: {{.*}}.s:[[#@LINE-1]]:3: error: invalid operand for instruction jmp offset fn_ref -- 2.34.1