From: Duncan P. N. Exon Smith Date: Wed, 18 Feb 2015 23:17:51 +0000 (+0000) Subject: IR: Allow MDSubrange to have 'count: -1' X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c2c5e48ad587a99a92ce55265cce20fdb235af70;p=oota-llvm.git 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229769 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 76365ea2233..0d748610742 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -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 diff --git a/test/Assembler/invalid-mdsubrange-count-negative.ll b/test/Assembler/invalid-mdsubrange-count-negative.ll index 99cc8876750..92c0b4e7ca4 100644 --- a/test/Assembler/invalid-mdsubrange-count-negative.ll +++ b/test/Assembler/invalid-mdsubrange-count-negative.ll @@ -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: :[[@LINE+1]]:25: error: value for 'count' too small, limit is -1 +!0 = !MDSubrange(count: -2) diff --git a/test/Assembler/mdsubrange-empty-array.ll b/test/Assembler/mdsubrange-empty-array.ll new file mode 100644 index 00000000000..fa05582a9a9 --- /dev/null +++ b/test/Assembler/mdsubrange-empty-array.ll @@ -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) diff --git a/unittests/IR/MetadataTest.cpp b/unittests/IR/MetadataTest.cpp index fc2ed73d89c..b6ee46a5d7b 100644 --- a/unittests/IR/MetadataTest.cpp +++ b/unittests/IR/MetadataTest.cpp @@ -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) {