OSDN Git Service

MIR Parser: Report an error when parsing duplicate register flags.
authorAlex Lorenz <arphaman@gmail.com>
Wed, 5 Aug 2015 18:09:03 +0000 (18:09 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Wed, 5 Aug 2015 18:09:03 +0000 (18:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244081 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/MIRParser/MIParser.cpp
test/CodeGen/MIR/X86/duplicate-register-flag-error.mir [new file with mode: 0644]

index 7f42013..0663b11 100644 (file)
@@ -474,6 +474,7 @@ bool MIParser::parseRegister(unsigned &Reg) {
 }
 
 bool MIParser::parseRegisterFlag(unsigned &Flags) {
+  const unsigned OldFlags = Flags;
   switch (Token.kind()) {
   case MIToken::kw_implicit:
     Flags |= RegState::Implicit;
@@ -496,11 +497,14 @@ bool MIParser::parseRegisterFlag(unsigned &Flags) {
   case MIToken::kw_debug_use:
     Flags |= RegState::Debug;
     break;
-  // TODO: report an error when we specify the same flag more than once.
   // TODO: parse the other register flags.
   default:
     llvm_unreachable("The current token should be a register flag");
   }
+  if (OldFlags == Flags)
+    // We know that the same flag is specified more than once when the flags
+    // weren't modified.
+    return error("duplicate '" + Token.stringValue() + "' register flag");
   lex();
   return false;
 }
diff --git a/test/CodeGen/MIR/X86/duplicate-register-flag-error.mir b/test/CodeGen/MIR/X86/duplicate-register-flag-error.mir
new file mode 100644 (file)
index 0000000..f9570a4
--- /dev/null
@@ -0,0 +1,38 @@
+# RUN: not llc -march=x86-64 -start-after branch-folder -stop-after branch-folder -o /dev/null %s 2>&1 | FileCheck %s
+
+--- |
+
+  define i32 @foo(i32 %a) {
+  entry:
+    %0 = icmp sle i32 %a, 10
+    br i1 %0, label %less, label %exit
+
+  less:
+    ret i32 0
+
+  exit:
+    ret i32 %a
+  }
+
+...
+---
+name:            foo
+body:
+  - id:          0
+    name:        entry
+    successors:  [ '%bb.1.less', '%bb.2.exit' ]
+    instructions:
+      - 'CMP32ri8 %edi, 10, implicit-def %eflags'
+# CHECK: [[@LINE+1]]:36: duplicate 'implicit' register flag
+      - 'JG_1 %bb.2.exit, implicit implicit %eflags'
+  - id:          1
+    name:        less
+    instructions:
+      - '%eax = MOV32r0 implicit-def %eflags'
+      - 'RETQ %eax'
+  - id:          2
+    name:        exit
+    instructions:
+      - '%eax = COPY %edi'
+      - 'RETQ %eax'
+...