[hexagon] change AsmParser assertion to error
authorBrian Cain <bcain@quicinc.com>
Fri, 3 May 2019 16:50:38 +0000 (16:50 +0000)
committerBrian Cain <bcain@quicinc.com>
Fri, 3 May 2019 16:50:38 +0000 (16:50 +0000)
For immediates that can't be evaluated in assembler-mapped instructions, we
should return 'invalid operand' instead of assert.

llvm-svn: 359905

llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp
llvm/test/MC/Hexagon/hex-immediates.s [new file with mode: 0644]
llvm/test/MC/Hexagon/inval_immed.s [new file with mode: 0644]

index d5a49a4..a77e289 100644 (file)
@@ -1683,8 +1683,8 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
     int64_t Value;
     MCExpr const &Expr = *Imm.getExpr();
     bool Absolute = Expr.evaluateAsAbsolute(Value);
-    assert(Absolute);
-    (void)Absolute;
+    if (!Absolute)
+      return Match_InvalidOperand;
     if (!HexagonMCInstrInfo::mustExtend(Expr) &&
         ((Value <= -256) || Value >= 256))
       return Match_InvalidOperand;
@@ -1706,8 +1706,8 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
     MCInst TmpInst;
     int64_t Value;
     bool Absolute = Imm.getExpr()->evaluateAsAbsolute(Value);
-    assert(Absolute);
-    (void)Absolute;
+    if (!Absolute)
+      return Match_InvalidOperand;
     if (Value == 0) { // convert to $Rd = $Rs
       TmpInst.setOpcode(Hexagon::A2_tfr);
       MCOperand &Rd = Inst.getOperand(0);
@@ -1736,8 +1736,8 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
     MCOperand &Imm = Inst.getOperand(2);
     int64_t Value;
     bool Absolute = Imm.getExpr()->evaluateAsAbsolute(Value);
-    assert(Absolute);
-    (void)Absolute;
+    if (!Absolute)
+      return Match_InvalidOperand;
     if (Value == 0) { // convert to $Rdd = combine ($Rs[0], $Rs[1])
       MCInst TmpInst;
       unsigned int RegPairNum = RI->getEncodingValue(Rss.getReg());
@@ -1860,8 +1860,8 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
     MCOperand &Imm = Inst.getOperand(2);
     int64_t Value;
     bool Absolute = Imm.getExpr()->evaluateAsAbsolute(Value);
-    assert(Absolute);
-    (void)Absolute;
+    if (!Absolute)
+      return Match_InvalidOperand;
     if (Value == 0)
       Inst.setOpcode(Hexagon::S2_vsathub);
     else {
@@ -1880,8 +1880,8 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
     MCOperand &Imm = Inst.getOperand(2);
     int64_t Value;
     bool Absolute = Imm.getExpr()->evaluateAsAbsolute(Value);
-    assert(Absolute);
-    (void)Absolute;
+    if (!Absolute)
+      return Match_InvalidOperand;
     if (Value == 0) {
       MCInst TmpInst;
       unsigned int RegPairNum = RI->getEncodingValue(Rss.getReg());
diff --git a/llvm/test/MC/Hexagon/hex-immediates.s b/llvm/test/MC/Hexagon/hex-immediates.s
new file mode 100644 (file)
index 0000000..8a0ed9a
--- /dev/null
@@ -0,0 +1,6 @@
+# RUN: llvm-mc -filetype=obj -arch=hexagon %s | llvm-objdump -d --print-imm-hex - | FileCheck %s
+
+# CHECK: r3 = ##0x70000240
+r3 = ##1879048768
+# CHECK: r3 = ##-0x70000240
+r3 = ##-1879048768
diff --git a/llvm/test/MC/Hexagon/inval_immed.s b/llvm/test/MC/Hexagon/inval_immed.s
new file mode 100644 (file)
index 0000000..12600b0
--- /dev/null
@@ -0,0 +1,6 @@
+# RUN: not llvm-mc -filetype=asm -arch=hexagon %s 2>%t; FileCheck %s < %t
+
+    .text
+r0 = mpyi(r0,#m9)
+
+# CHECK: error: invalid operand for instruction