[PATCH] D150048: [X86][MC] Reject `call`/`jmp [offset fn_ref]` in Intel syntax

Alvin Wong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat May 6 11:41:17 PDT 2023


alvinhochun created this revision.
alvinhochun added reviewers: epastor, hans, thakis, MaskRay, ayzhao.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
alvinhochun requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.

Depends on D150047 <https://reviews.llvm.org/D150047>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150048

Files:
  llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
  llvm/test/MC/X86/intel-syntax-branch-fail.s
  llvm/test/MC/X86/intel-syntax-branch.s


Index: llvm/test/MC/X86/intel-syntax-branch.s
===================================================================
--- llvm/test/MC/X86/intel-syntax-branch.s
+++ llvm/test/MC/X86/intel-syntax-branch.s
@@ -57,13 +57,4 @@
   // CHECK-32: calll *fn_ref
   // CHECK-32: jmpl *fn_ref
 
-  t7:
-  // FIXME: MASM does not accept this syntax and GAS assembles this as a direct
-  //        call/jump instead of indirect. Consider making this syntax an error?
-  call [offset fn_ref]
-  jmp [offset fn_ref]
-  // CHECK-32-LABEL: t7:
-  // CHECK-32: calll *fn_ref
-  // CHECK-32: jmpl *fn_ref
-
 .endif
Index: llvm/test/MC/X86/intel-syntax-branch-fail.s
===================================================================
--- llvm/test/MC/X86/intel-syntax-branch-fail.s
+++ llvm/test/MC/X86/intel-syntax-branch-fail.s
@@ -1,10 +1,9 @@
 // RUN: not llvm-mc -triple i686-unknown-unknown -x86-asm-syntax=intel %s 2>&1 | FileCheck %s
 
-// TODO: Consider making this syntax an error?
-// call [offset fn_ref]
-// // TODO-CHECK: {{.*}}intel-syntax-branch-fail.s:[[#@LINE+-1]]:1: error: `OFFSET` operator cannot be used in an unconditional branch
-// jmp [offset fn_ref]
-// // TODO-CHECK: {{.*}}intel-syntax-branch-fail.s:[[#@LINE+-1]]:1: error: `OFFSET` operator cannot be used in an unconditional branch
+call [offset fn_ref]
+// CHECK: {{.*}}intel-syntax-branch-fail.s:[[#@LINE+-1]]:6: error: `OFFSET` operator cannot be used in an unconditional branch
+jmp [offset fn_ref]
+// CHECK: {{.*}}intel-syntax-branch-fail.s:[[#@LINE+-1]]:5: error: `OFFSET` operator cannot be used in an unconditional branch
 
 call offset fn_ref
 // CHECK: {{.*}}intel-syntax-branch-fail.s:[[#@LINE+-1]]:1: error: invalid operand for instruction
Index: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
===================================================================
--- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -2658,11 +2658,10 @@
       }
     }
   } else if (IsUnconditionalBranch) {
-    // TODO: Consider making the `call [offset fn_ref]` syntax an error?
-#if 0
+    //  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");
-#endif
+      return Error(
+          Start, "`OFFSET` operator cannot be used in an unconditional branch");
     if (PtrInOperand || SM.isBracketUsed())
       MaybeDirectBranchDest = false;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150048.520115.patch
Type: text/x-patch
Size: 2503 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230506/46a0c613/attachment.bin>


More information about the llvm-commits mailing list