[PATCH] D13316: Visibly fail if attempting to encode register AH, BH, CH, DH in a REX-prefixed instruction.

Douglas Katzman via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 10 12:32:22 PST 2015


dougk updated this revision to Diff 39845.
dougk added a comment.

Simpler fix per Craig Topper


http://reviews.llvm.org/D13316

Files:
  lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
  test/MC/X86/encoder-fail.s

Index: test/MC/X86/encoder-fail.s
===================================================================
--- /dev/null
+++ test/MC/X86/encoder-fail.s
@@ -0,0 +1,3 @@
+// RUN: not llvm-mc -triple x86_64-unknown-unknown --show-encoding %s 2>&1 | FileCheck %s
+// CHECK: LLVM ERROR: Cannot encode high byte register in REX-prefixed instruction
+ movzx %dh, %rsi
Index: lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
===================================================================
--- lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
+++ lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
@@ -988,6 +988,8 @@
 static unsigned DetermineREXPrefix(const MCInst &MI, uint64_t TSFlags,
                                    const MCInstrDesc &Desc) {
   unsigned REX = 0;
+  bool UsesHighByteReg = false;
+
   if (TSFlags & X86II::REX_W)
     REX |= 1 << 3; // set REX.W
 
@@ -1004,6 +1006,8 @@
     const MCOperand &MO = MI.getOperand(i);
     if (!MO.isReg()) continue;
     unsigned Reg = MO.getReg();
+    if (Reg == X86::AH || Reg == X86::BH || Reg == X86::CH || Reg == X86::DH)
+      UsesHighByteReg = true;
     if (!X86II::isX86_64NonExtLowByteReg(Reg)) continue;
     // FIXME: The caller of DetermineREXPrefix slaps this prefix onto anything
     // that returns non-zero.
@@ -1073,6 +1077,9 @@
     }
     break;
   }
+  if (REX && UsesHighByteReg)
+    report_fatal_error("Cannot encode high byte register in REX-prefixed instruction");
+
   return REX;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13316.39845.patch
Type: text/x-patch
Size: 1462 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151110/e0611659/attachment.bin>


More information about the llvm-commits mailing list