[llvm] 0ecd2e5 - [X86][MC] Reject `call`/`jmp [offset fn_ref]` in Intel syntax
Alvin Wong via llvm-commits
llvm-commits at lists.llvm.org
Mon May 8 09:08:10 PDT 2023
Author: Alvin Wong
Date: 2023-05-09T00:07:40+08:00
New Revision: 0ecd2e50146dd4dfac47b20a8e03e43a015b55ce
URL: https://github.com/llvm/llvm-project/commit/0ecd2e50146dd4dfac47b20a8e03e43a015b55ce
DIFF: https://github.com/llvm/llvm-project/commit/0ecd2e50146dd4dfac47b20a8e03e43a015b55ce.diff
LOG: [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
Added:
Modified:
llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
llvm/test/MC/X86/intel-syntax-branch.s
Removed:
################################################################################
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
More information about the llvm-commits
mailing list