MIParser: reject subregister indexes on physregs
authorMatthias Braun <matze@braunis.de>
Sat, 16 Jul 2016 01:36:18 +0000 (01:36 +0000)
committerMatthias Braun <matze@braunis.de>
Sat, 16 Jul 2016 01:36:18 +0000 (01:36 +0000)
llvm-svn: 275658

llvm/lib/CodeGen/MIRParser/MIParser.cpp
llvm/test/CodeGen/MIR/X86/subreg-on-physreg.mir [new file with mode: 0644]

index 0b5c59d..b3fd16f 100644 (file)
@@ -962,6 +962,8 @@ bool MIParser::parseRegisterOperand(MachineOperand &Dest,
   if (Token.is(MIToken::colon)) {
     if (parseSubRegisterIndex(SubReg))
       return true;
+    if (!TargetRegisterInfo::isVirtualRegister(Reg))
+      return error("subregister index expects a virtual register");
   }
   if ((Flags & RegState::Define) == 0) {
     if (consumeIfPresent(MIToken::lparen)) {
diff --git a/llvm/test/CodeGen/MIR/X86/subreg-on-physreg.mir b/llvm/test/CodeGen/MIR/X86/subreg-on-physreg.mir
new file mode 100644 (file)
index 0000000..b856df2
--- /dev/null
@@ -0,0 +1,12 @@
+# RUN: not llc -march=x86-64 -start-after machine-sink -stop-after machine-sink -o /dev/null %s 2>&1 | FileCheck %s
+# This test ensures that an error is reported for subreg index on a physreg.
+--- |
+  define void @t() { ret void }
+...
+---
+name: t
+body: |
+  bb.0:
+    ; CHECK: [[@LINE+1]]:19: subregister index expects a virtual register
+    %eax:sub_8bit = COPY %bl
+...