[llvm] r243696 - MIR Parser: Report an error when a constant pool item is redefined.

Alex Lorenz arphaman at gmail.com
Thu Jul 30 15:00:18 PDT 2015


Author: arphaman
Date: Thu Jul 30 17:00:17 2015
New Revision: 243696

URL: http://llvm.org/viewvc/llvm-project?rev=243696&view=rev
Log:
MIR Parser: Report an error when a constant pool item is redefined.

Added:
    llvm/trunk/test/CodeGen/MIR/X86/constant-pool-item-redefinition-error.mir
Modified:
    llvm/trunk/include/llvm/CodeGen/MIRYamlMapping.h
    llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp

Modified: llvm/trunk/include/llvm/CodeGen/MIRYamlMapping.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MIRYamlMapping.h?rev=243696&r1=243695&r2=243696&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MIRYamlMapping.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MIRYamlMapping.h Thu Jul 30 17:00:17 2015
@@ -285,7 +285,7 @@ template <> struct MappingTraits<FixedMa
 };
 
 struct MachineConstantPoolValue {
-  unsigned ID;
+  UnsignedValue ID;
   StringValue Value;
   unsigned Alignment = 0;
 };

Modified: llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp?rev=243696&r1=243695&r2=243696&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp Thu Jul 30 17:00:17 2015
@@ -559,9 +559,12 @@ bool MIRParserImpl::initializeConstantPo
         YamlConstant.Alignment
             ? YamlConstant.Alignment
             : M.getDataLayout().getPrefTypeAlignment(Value->getType());
-    // TODO: Report an error when the same constant pool value ID is redefined.
-    ConstantPoolSlots.insert(std::make_pair(
-        YamlConstant.ID, ConstantPool.getConstantPoolIndex(Value, Alignment)));
+    unsigned Index = ConstantPool.getConstantPoolIndex(Value, Alignment);
+    if (!ConstantPoolSlots.insert(std::make_pair(YamlConstant.ID.Value, Index))
+             .second)
+      return error(YamlConstant.ID.SourceRange.Start,
+                   Twine("redefinition of constant pool item '%const.") +
+                       Twine(YamlConstant.ID.Value) + "'");
   }
   return false;
 }

Added: llvm/trunk/test/CodeGen/MIR/X86/constant-pool-item-redefinition-error.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/X86/constant-pool-item-redefinition-error.mir?rev=243696&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/X86/constant-pool-item-redefinition-error.mir (added)
+++ llvm/trunk/test/CodeGen/MIR/X86/constant-pool-item-redefinition-error.mir Thu Jul 30 17:00:17 2015
@@ -0,0 +1,27 @@
+# RUN: not llc -march=x86-64 -start-after branch-folder -stop-after branch-folder -o /dev/null %s 2>&1 | FileCheck %s
+
+--- |
+
+  define double @test(double %a, float %b) {
+  entry:
+    %c = fadd double %a, 3.250000e+00
+    ret double %c
+  }
+
+...
+---
+name:            test
+constants:
+  - id:          0
+    value:       'double 3.250000e+00'
+# CHECK: [[@LINE+1]]:18: redefinition of constant pool item '%const.0'
+  - id:          0
+    value:       'double 3.250000e+00'
+body:
+  - id: 0
+    name: entry
+    instructions:
+      - '%xmm0 = ADDSDrm killed %xmm0, %rip, 1, _, %const.0, _'
+      - 'RETQ %xmm0'
+...
+





More information about the llvm-commits mailing list