ARM: diagnose invalid system LDM/STM
authorTim Northover <tnorthover@apple.com>
Tue, 12 Nov 2013 21:32:41 +0000 (21:32 +0000)
committerTim Northover <tnorthover@apple.com>
Tue, 12 Nov 2013 21:32:41 +0000 (21:32 +0000)
The system LDM and STM instructions can't usually writeback to the base
register. The one exception is when an LDM is actually an exception-return
(i.e. contains PC in the register list).

(There's already a test that "ldm sp!, {r0-r3, pc}^" works, which is why there
is no positive test).

rdar://problem/15223374

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194512 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/AsmParser/ARMAsmParser.cpp
test/MC/ARM/diagnostics.s

index 727bd26369ce58262a30a235f95b9bf19f0e67e0..e3f9e0dc609a69b8e541aa8116b4e5f49fc52f0f 100644 (file)
@@ -5481,6 +5481,22 @@ validateInstruction(MCInst &Inst,
                    "writeback register not allowed in register list");
     break;
   }
+  case ARM::sysLDMIA_UPD:
+  case ARM::sysLDMDA_UPD:
+  case ARM::sysLDMDB_UPD:
+  case ARM::sysLDMIB_UPD:
+    if (!listContainsReg(Inst, 3, ARM::PC))
+      return Error(Operands[4]->getStartLoc(),
+                   "writeback register only allowed on system LDM "
+                   "if PC in register-list");
+    break;
+  case ARM::sysSTMIA_UPD:
+  case ARM::sysSTMDA_UPD:
+  case ARM::sysSTMDB_UPD:
+  case ARM::sysSTMIB_UPD:
+    return Error(Operands[2]->getStartLoc(),
+                 "system STM cannot have writeback register");
+    break;
   case ARM::tMUL: {
     // The second source operand must be the same register as the destination
     // operand.
index 11c8306b1d7237ee73bdde59bf854585fadccfef..3c26f6d645c83009e18787874133da904c470da2 100644 (file)
 @ CHECK-ERRORS: error: instruction requires: FPARMv8
 @ CHECK-ERRORS: error: instruction requires: FPARMv8
 @ CHECK-ERRORS: error: instruction requires: FPARMv8
+
+        stm sp!, {r0, pc}^
+        ldm sp!, {r0}^
+@ CHECK-ERRORS: error: system STM cannot have writeback register
+@ CHECK-ERRORS: error: writeback register only allowed on system LDM if PC in register-list