[llvm] r229769 - IR: Allow MDSubrange to have 'count: -1'

Duncan P. N. Exon Smith dexonsmith at apple.com
Wed Feb 18 15:17:51 PST 2015


Author: dexonsmith
Date: Wed Feb 18 17:17:51 2015
New Revision: 229769

URL: http://llvm.org/viewvc/llvm-project?rev=229769&view=rev
Log:
IR: Allow MDSubrange to have 'count: -1'

It turns out that `count: -1` is a special value indicating an empty
array, such as `Values` in:

    struct T {
      unsigned Count;
      int Values[];
    };

Handle it.

Added:
    llvm/trunk/test/Assembler/mdsubrange-empty-array.ll
Modified:
    llvm/trunk/lib/AsmParser/LLParser.cpp
    llvm/trunk/test/Assembler/invalid-mdsubrange-count-negative.ll
    llvm/trunk/unittests/IR/MetadataTest.cpp

Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=229769&r1=229768&r2=229769&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Wed Feb 18 17:17:51 2015
@@ -3276,7 +3276,7 @@ bool LLParser::ParseGenericDebugNode(MDN
 ///   ::= !MDSubrange(count: 30, lowerBound: 2)
 bool LLParser::ParseMDSubrange(MDNode *&Result, bool IsDistinct) {
 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED)                                    \
-  REQUIRED(count, MDUnsignedField, (0, UINT64_MAX >> 1));                      \
+  REQUIRED(count, MDSignedField, (-1, -1, INT64_MAX));                         \
   OPTIONAL(lowerBound, MDSignedField, );
   PARSE_MD_FIELDS();
 #undef VISIT_MD_FIELDS

Modified: llvm/trunk/test/Assembler/invalid-mdsubrange-count-negative.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdsubrange-count-negative.ll?rev=229769&r1=229768&r2=229769&view=diff
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdsubrange-count-negative.ll (original)
+++ llvm/trunk/test/Assembler/invalid-mdsubrange-count-negative.ll Wed Feb 18 17:17:51 2015
@@ -1,4 +1,7 @@
 ; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
 
-; CHECK: [[@LINE+1]]:25: error: expected unsigned integer
-!0 = !MDSubrange(count: -3)
+; CHECK-NOT: error
+!0 = !MDSubrange(count: -1)
+
+; CHECK: <stdin>:[[@LINE+1]]:25: error: value for 'count' too small, limit is -1
+!0 = !MDSubrange(count: -2)

Added: llvm/trunk/test/Assembler/mdsubrange-empty-array.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/mdsubrange-empty-array.ll?rev=229769&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/mdsubrange-empty-array.ll (added)
+++ llvm/trunk/test/Assembler/mdsubrange-empty-array.ll Wed Feb 18 17:17:51 2015
@@ -0,0 +1,14 @@
+; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
+; RUN: verify-uselistorder %s
+
+; CHECK: !named = !{!0, !0, !1, !2}
+!named = !{!0, !1, !2, !3}
+
+; CHECK:      !0 = !MDSubrange(count: -1)
+; CHECK-NEXT: !1 = !MDSubrange(count: -1, lowerBound: 4)
+; CHECK-NEXT: !2 = !MDSubrange(count: -1, lowerBound: -5)
+!0 = !MDSubrange(count: -1)
+!1 = !MDSubrange(count: -1, lowerBound: 0)
+
+!2 = !MDSubrange(count: -1, lowerBound: 4)
+!3 = !MDSubrange(count: -1, lowerBound: -5)

Modified: llvm/trunk/unittests/IR/MetadataTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/MetadataTest.cpp?rev=229769&r1=229768&r2=229769&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/MetadataTest.cpp (original)
+++ llvm/trunk/unittests/IR/MetadataTest.cpp Wed Feb 18 17:17:51 2015
@@ -670,6 +670,14 @@ TEST_F(MDSubrangeTest, get) {
   EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
 }
 
+TEST_F(MDSubrangeTest, getEmptyArray) {
+  auto *N = MDSubrange::get(Context, -1, 0);
+  EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag());
+  EXPECT_EQ(-1, N->getCount());
+  EXPECT_EQ(0, N->getLo());
+  EXPECT_EQ(N, MDSubrange::get(Context, -1, 0));
+}
+
 typedef MetadataTest MDEnumeratorTest;
 
 TEST_F(MDEnumeratorTest, get) {





More information about the llvm-commits mailing list