From 4b65d19694121bb863f64ac099abfd54db0b1591 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Mon, 10 Aug 2015 23:45:02 +0000 Subject: [PATCH] MIR Parser: Report an error when a fixed stack object is redefined. llvm-svn: 244534 --- include/llvm/CodeGen/MIRYamlMapping.h | 2 +- lib/CodeGen/MIRParser/MIRParser.cpp | 8 +++-- .../fixed-stack-object-redefinition-error.mir | 30 +++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 test/CodeGen/MIR/X86/fixed-stack-object-redefinition-error.mir diff --git a/include/llvm/CodeGen/MIRYamlMapping.h b/include/llvm/CodeGen/MIRYamlMapping.h index 43c4a5dd6e3..b3018e44fd9 100644 --- a/include/llvm/CodeGen/MIRYamlMapping.h +++ b/include/llvm/CodeGen/MIRYamlMapping.h @@ -245,7 +245,7 @@ template <> struct MappingTraits { /// MachineFrameInfo class. struct FixedMachineStackObject { enum ObjectType { DefaultType, SpillSlot }; - unsigned ID; + UnsignedValue ID; ObjectType Type = DefaultType; int64_t Offset = 0; uint64_t Size = 0; diff --git a/lib/CodeGen/MIRParser/MIRParser.cpp b/lib/CodeGen/MIRParser/MIRParser.cpp index 0679ec02c98..6bd72301840 100644 --- a/lib/CodeGen/MIRParser/MIRParser.cpp +++ b/lib/CodeGen/MIRParser/MIRParser.cpp @@ -489,8 +489,12 @@ bool MIRParserImpl::initializeFrameInfo(MachineFunction &MF, else ObjectIdx = MFI.CreateFixedSpillStackObject(Object.Size, Object.Offset); MFI.setObjectAlignment(ObjectIdx, Object.Alignment); - // TODO: Report an error when objects are redefined. - PFS.FixedStackObjectSlots.insert(std::make_pair(Object.ID, ObjectIdx)); + if (!PFS.FixedStackObjectSlots.insert(std::make_pair(Object.ID.Value, + ObjectIdx)) + .second) + return error(Object.ID.SourceRange.Start, + Twine("redefinition of fixed stack object '%fixed-stack.") + + Twine(Object.ID.Value) + "'"); if (parseCalleeSavedRegister(MF, PFS, CSIInfo, Object.CalleeSavedRegister, ObjectIdx)) return true; diff --git a/test/CodeGen/MIR/X86/fixed-stack-object-redefinition-error.mir b/test/CodeGen/MIR/X86/fixed-stack-object-redefinition-error.mir new file mode 100644 index 00000000000..5f88bc428f1 --- /dev/null +++ b/test/CodeGen/MIR/X86/fixed-stack-object-redefinition-error.mir @@ -0,0 +1,30 @@ +# RUN: not llc -march=x86 -start-after branch-folder -stop-after branch-folder -o /dev/null %s 2>&1 | FileCheck %s + +--- | + + define i32 @test(i32 %a, i32 %b) #0 { + entry: + %c = add i32 %a, %b + ret i32 %c + } + + attributes #0 = { "no-frame-pointer-elim"="false" } + +... +--- +name: test +tracksRegLiveness: true +frameInfo: + maxAlignment: 4 +fixedStack: + - { id: 0, offset: 4, size: 4, alignment: 4, isImmutable: true, isAliased: false } +# CHECK: [[@LINE+1]]:11: redefinition of fixed stack object '%fixed-stack.0' + - { id: 0, offset: 0, size: 4, alignment: 16, isImmutable: true, isAliased: false } +body: + - id: 0 + name: entry + instructions: + - '%eax = MOV32rm %esp, 1, _, 4, _' + - '%eax = ADD32rm killed %eax, %esp, 1, _, 8, _, implicit-def dead %eflags' + - 'RETL %eax' +...