From 2bc631660b1b209b32092f262734b11be2759481 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Thu, 30 Jul 2015 21:54:10 +0000 Subject: [PATCH] MIR Parser: Report an error when a virtual register is redefined. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243695 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MIRYamlMapping.h | 2 +- lib/CodeGen/MIRParser/MIRParser.cpp | 8 ++++-- .../virtual-register-redefinition-error.mir | 28 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 test/CodeGen/MIR/X86/virtual-register-redefinition-error.mir diff --git a/include/llvm/CodeGen/MIRYamlMapping.h b/include/llvm/CodeGen/MIRYamlMapping.h index 7ef4c6b6e39..c986f57cd95 100644 --- a/include/llvm/CodeGen/MIRYamlMapping.h +++ b/include/llvm/CodeGen/MIRYamlMapping.h @@ -131,7 +131,7 @@ namespace llvm { namespace yaml { struct VirtualRegisterDefinition { - unsigned ID; + UnsignedValue ID; StringValue Class; StringValue PreferredRegister; // TODO: Serialize the target specific register hints. diff --git a/lib/CodeGen/MIRParser/MIRParser.cpp b/lib/CodeGen/MIRParser/MIRParser.cpp index a179c593380..7966f389d3e 100644 --- a/lib/CodeGen/MIRParser/MIRParser.cpp +++ b/lib/CodeGen/MIRParser/MIRParser.cpp @@ -414,9 +414,11 @@ bool MIRParserImpl::initializeRegisterInfo(MachineFunction &MF, Twine("use of undefined register class '") + VReg.Class.Value + "'"); unsigned Reg = RegInfo.createVirtualRegister(RC); - // TODO: Report an error when the same virtual register with the same ID is - // redefined. - PFS.VirtualRegisterSlots.insert(std::make_pair(VReg.ID, Reg)); + if (!PFS.VirtualRegisterSlots.insert(std::make_pair(VReg.ID.Value, Reg)) + .second) + return error(VReg.ID.SourceRange.Start, + Twine("redefinition of virtual register '%") + + Twine(VReg.ID.Value) + "'"); if (!VReg.PreferredRegister.Value.empty()) { unsigned PreferredReg = 0; if (parseNamedRegisterReference(PreferredReg, SM, MF, diff --git a/test/CodeGen/MIR/X86/virtual-register-redefinition-error.mir b/test/CodeGen/MIR/X86/virtual-register-redefinition-error.mir new file mode 100644 index 00000000000..baadeaee3d4 --- /dev/null +++ b/test/CodeGen/MIR/X86/virtual-register-redefinition-error.mir @@ -0,0 +1,28 @@ +# RUN: not llc -march=x86-64 -start-after machine-sink -stop-after machine-sink -o /dev/null %s 2>&1 | FileCheck %s + +--- | + + define i32 @test(i32 %a) { + body: + ret i32 %a + } + +... +--- +name: test +isSSA: true +tracksRegLiveness: true +registers: + - { id: 0, class: gr32 } +# CHECK: [[@LINE+1]]:11: redefinition of virtual register '%0' + - { id: 0, class: gr32 } +body: + - id: 0 + name: body + liveins: [ '%edi' ] + instructions: + - '%0 = COPY %edi' + - '%eax = COPY %0' + - 'RETQ %eax' +... + -- 2.34.1