From 2ac1d3a2c90395899528bc2ee06448051a016c9d Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 13 Jul 2010 19:33:27 +0000 Subject: [PATCH] Add support for empty metadata nodes: !{}. llvm-svn: 108259 --- lib/AsmParser/LLParser.cpp | 4 ++++ lib/Bitcode/Reader/BitcodeReader.cpp | 5 +++-- lib/VMCore/Metadata.cpp | 3 ++- test/Feature/metadata.ll | 3 ++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 67521814b0c..8c4d7348eb1 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -3983,6 +3983,10 @@ int LLParser::ParseInsertValue(Instruction *&Inst, PerFunctionState &PFS) { /// ::= 'null' | TypeAndValue bool LLParser::ParseMDNodeVector(SmallVectorImpl &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)) { diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 527ae49b714..b3f0776d29d 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -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++); diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index 1d3a0586930..3100d4ac7c9 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -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(N+1)+Op; } diff --git a/test/Feature/metadata.ll b/test/Feature/metadata.ll index 3e2cd3c4c0b..b34c947df4d 100644 --- a/test/Feature/metadata.ll +++ b/test/Feature/metadata.ll @@ -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 !{}