[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
Sun May 7 03:06:07 PDT 2023


alvinhochun updated this revision to Diff 520160.
alvinhochun added a comment.

Rebase and apply suggestions.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150048/new/

https://reviews.llvm.org/D150048

Files:
  llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
  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
@@ -61,6 +61,11 @@
 
 .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
Index: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
===================================================================
--- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -2658,6 +2658,10 @@
       }
     }
   } 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;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150048.520160.patch
Type: text/x-patch
Size: 1227 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230507/101ad024/attachment-0001.bin>


More information about the llvm-commits mailing list