Add support for empty metadata nodes: !{}.
authorDan Gohman <gohman@apple.com>
Tue, 13 Jul 2010 19:33:27 +0000 (19:33 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 13 Jul 2010 19:33:27 +0000 (19:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108259 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AsmParser/LLParser.cpp
lib/Bitcode/Reader/BitcodeReader.cpp
lib/VMCore/Metadata.cpp
test/Feature/metadata.ll

index 67521814b0c6aa12dddc9f38d76ea82034221b1e..8c4d7348eb1bf3c0fedc7640f36c8096351c358c 100644 (file)
@@ -3983,6 +3983,10 @@ int LLParser::ParseInsertValue(Instruction *&Inst, PerFunctionState &PFS) {
 ///   ::= 'null' | TypeAndValue
 bool LLParser::ParseMDNodeVector(SmallVectorImpl<Value*> &Elts,
                                  PerFunctionState *PFS) {
+  // Check for an empty list.
+  if (Lex.getKind() == lltok::rbrace)
+    return false;
+
   do {
     // Null is a special case since it is typeless.
     if (EatIfPresent(lltok::kw_null)) {
index 527ae49b7143d6f645b23deb633bd082a2d3bb75..b3f0776d29d548dbf7b54d2530b75b66fedd065a 100644 (file)
@@ -820,7 +820,7 @@ bool BitcodeReader::ParseMetadata() {
       IsFunctionLocal = true;
       // fall-through
     case bitc::METADATA_NODE: {
-      if (Record.empty() || Record.size() % 2 == 1)
+      if (Record.size() % 2 == 1)
         return Error("Invalid METADATA_NODE record");
 
       unsigned Size = Record.size();
@@ -834,7 +834,8 @@ bool BitcodeReader::ParseMetadata() {
         else
           Elts.push_back(NULL);
       }
-      Value *V = MDNode::getWhenValsUnresolved(Context, &Elts[0], Elts.size(),
+      Value *V = MDNode::getWhenValsUnresolved(Context,
+                                               Elts.data(), Elts.size(),
                                                IsFunctionLocal);
       IsFunctionLocal = false;
       MDValueList.AssignValue(V, NextMDValueNo++);
index 1d3a058693035d61fcab06b6dbe8c8e7cd01da04..3100d4ac7c9c3de089651a8c3870562534f1591a 100644 (file)
@@ -78,7 +78,8 @@ void MDNodeOperand::allUsesReplacedWith(Value *NV) {
 /// getOperandPtr - Helper function to get the MDNodeOperand's coallocated on
 /// the end of the MDNode.
 static MDNodeOperand *getOperandPtr(MDNode *N, unsigned Op) {
-  assert(Op < N->getNumOperands() && "Invalid operand number");
+  // Use <= instead of < to permit a one-past-the-end address.
+  assert(Op <= N->getNumOperands() && "Invalid operand number");
   return reinterpret_cast<MDNodeOperand*>(N+1)+Op;
 }
 
index 3e2cd3c4c0b20ba3ed4f47fdc3db8a3f8997fa93..b34c947df4d1fc4aadce53678a6b23ffc847685f 100644 (file)
@@ -10,4 +10,5 @@ declare void @llvm.zonk(metadata, i64, metadata) nounwind readnone
 
 !named = !{!0}
 !0 = metadata !{i8** null}
-!1 = metadata !{i8* null}
+!1 = metadata !{i8* null, metadata !2}
+!2 = metadata !{}