[PATCH] D81908: [Mips] Error if a non-immediate operand is used while an immediate is expected

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 19 22:12:08 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGdd48c57da35e: [Mips] Error if a non-immediate operand is used while an immediate is expected (authored by Wang Rui <wangrui at loongson.cn>, committed by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81908

Files:
  llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
  llvm/test/MC/Mips/imm-operand-err.s


Index: llvm/test/MC/Mips/imm-operand-err.s
===================================================================
--- /dev/null
+++ llvm/test/MC/Mips/imm-operand-err.s
@@ -0,0 +1,15 @@
+## Print an error if a non-immediate operand is used while an immediate is expected
+# RUN: not llvm-mc -filetype=obj -triple=mips -o /dev/null %s 2>&1 | FileCheck %s
+# RUN: not llvm-mc -filetype=obj -triple=mips64 -o /dev/null %s 2>&1 | FileCheck %s
+
+# CHECK: [[#@LINE+1]]:16: error: expected an immediate
+  ori  $4, $4, start
+# CHECK: [[#@LINE+1]]:17: error: expected an immediate
+  ori  $4, $4, (start - .)
+
+# CHECK: [[#@LINE+1]]:18: error: expected an immediate
+  addiu  $4, $4, start
+# CHECK: [[#@LINE+1]]:19: error: expected an immediate
+  addiu  $4, $4, (start - .)
+
+start:
Index: llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
===================================================================
--- llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
+++ llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
@@ -723,21 +723,8 @@
     return 0;
   }
 
-  if (Kind == MCExpr::SymbolRef) {
-    Mips::Fixups FixupKind = Mips::Fixups(0);
-
-    switch(cast<MCSymbolRefExpr>(Expr)->getKind()) {
-    default: llvm_unreachable("Unknown fixup kind!");
-      break;
-    case MCSymbolRefExpr::VK_None:
-      // FIXME: This is ok for O32/N32 but not N64.
-      FixupKind = Mips::fixup_Mips_32;
-      break;
-    } // switch
-
-    Fixups.push_back(MCFixup::create(0, Expr, MCFixupKind(FixupKind)));
-    return 0;
-  }
+  if (Kind == MCExpr::SymbolRef)
+    Ctx.reportError(Expr->getLoc(), "expected an immediate");
   return 0;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81908.272236.patch
Type: text/x-patch
Size: 1649 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200620/bcc66413/attachment.bin>


More information about the llvm-commits mailing list