[PATCH] D39062: [MIPS] Don't assert when attempting to expand ld/sd macro with symbol reference

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 18 11:12:49 PDT 2017


arichardson created this revision.

Previously we would assert when handling an expression like `sd $2, SYMBOL`
because the MipsAsmParser::expandLoadStoreDMacro() assummes input in the
form of `sd $2, offset($1)`.


https://reviews.llvm.org/D39062

Files:
  lib/Target/Mips/AsmParser/MipsAsmParser.cpp
  test/MC/Mips/macro-sd.s


Index: test/MC/Mips/macro-sd.s
===================================================================
--- /dev/null
+++ test/MC/Mips/macro-sd.s
@@ -0,0 +1,24 @@
+# RUN: llvm-mc -triple mips-unknown-freebsd -show-encoding %s | FileCheck %s
+# RUN: not llvm-mc -triple mips-unknown-freebsd -show-encoding %s -defsym=BAD_MACRO=1 2>&1 | FileCheck -check-prefix=ERR %s
+.data
+.globl fenvp
+fenvp:
+.space 8
+
+
+.set noreorder
+.text
+_start:
+
+.ifdef BAD_MACRO
+# These are not expected to work:
+sd $6, fenvp  # ERR: macro-sd.s:[[@LINE]]:1: error: offset for sd macro is not an immediate
+ld $6, fenvp  # ERR: macro-sd.s:[[@LINE]]:1: error: offset for ld macro is not an immediate
+.else
+sd $6, 0($2)
+# CHECK:      sw      $6, 0($2)               # encoding: [0xac,0x46,0x00,0x00]
+# CHECK-NEXT: sw      $7, 4($2)               # encoding: [0xac,0x47,0x00,0x04]
+ld $6, 0($2)
+# CHECK:      lw      $6, 0($2)               # encoding: [0x8c,0x46,0x00,0x00]
+# CHECK-NEXT: lw      $7, 4($2)               # encoding: [0x8c,0x47,0x00,0x04]
+.endif
Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp
===================================================================
--- lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -4784,8 +4784,11 @@
 
   warnIfRegIndexIsAT(FirstReg, IDLoc);
 
-  assert(Inst.getOperand(2).isImm() &&
-         "Offset for load macro is not immediate!");
+  if (!Inst.getOperand(2).isImm()) {
+    const StringRef InstName = (IsLoad ? "ld" : "sd");
+    return Error(IDLoc,
+                 "offset for " + InstName + " macro is not an immediate");
+  }
 
   MCOperand &FirstOffset = Inst.getOperand(2);
   signed NextOffset = FirstOffset.getImm() + 4;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39062.119508.patch
Type: text/x-patch
Size: 1719 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171018/6efa0777/attachment.bin>


More information about the llvm-commits mailing list