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.

llvm-svn: 229769
This commit is contained in:
Duncan P. N. Exon Smith 2015-02-18 23:17:51 +00:00
parent 7bb0738d82
commit 5c9a17732b
4 changed files with 28 additions and 3 deletions

View File

@ -3276,7 +3276,7 @@ bool LLParser::ParseGenericDebugNode(MDNode *&Result, bool IsDistinct) {
/// ::= !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

View File

@ -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)

View File

@ -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)

View File

@ -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) {