diff options
author | Chris Lattner <sabre@nondot.org> | 2009-12-30 05:14:00 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-12-30 05:14:00 +0000 |
commit | 628c13ad76fb4b7ce2f105c0e92644d1c39ee2f8 (patch) | |
tree | eed23e90144b620e1c0560e51488e567ca9d1f83 /lib/AsmParser/LLParser.cpp | |
parent | fa149ae923c32f80383d3585f7d5ea3bdae5ecf4 (diff) |
reimplement insertvalue/extractvalue metadata handling to not blindly
accept invalid input. Actually add a testcase.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92297 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AsmParser/LLParser.cpp')
-rw-r--r-- | lib/AsmParser/LLParser.cpp | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 1317b2cbd0..e8a98ea954 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -1124,16 +1124,27 @@ bool LLParser::ParseOptionalInfo(unsigned &Alignment) { } +/// ParseIndexList - This parses the index list for an insert/extractvalue +/// instruction. This sets AteExtraComma in the case where we eat an extra +/// comma at the end of the line and find that it is followed by metadata. +/// Clients that don't allow metadata can call the version of this function that +/// only takes one argument. +/// /// ParseIndexList /// ::= (',' uint32)+ -bool LLParser::ParseIndexList(SmallVectorImpl<unsigned> &Indices) { +/// +bool LLParser::ParseIndexList(SmallVectorImpl<unsigned> &Indices, + bool &AteExtraComma) { + AteExtraComma = false; + if (Lex.getKind() != lltok::comma) return TokError("expected ',' as start of index list"); while (EatIfPresent(lltok::comma)) { - // FIXME: TERRIBLE HACK. Loses comma state. - if (Lex.getKind() == lltok::MetadataVar) - break; + if (Lex.getKind() == lltok::MetadataVar) { + AteExtraComma = true; + return false; + } unsigned Idx; if (ParseUInt32(Idx)) return true; Indices.push_back(Idx); @@ -2803,6 +2814,7 @@ bool LLParser::ParseBasicBlock(PerFunctionState &PFS) { } if (ParseInstruction(Inst, BB, PFS)) return true; + if (EatIfPresent(lltok::comma)) ParseOptionalCustomMetadata(); @@ -3765,11 +3777,14 @@ bool LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) { bool LLParser::ParseExtractValue(Instruction *&Inst, PerFunctionState &PFS) { Value *Val; LocTy Loc; SmallVector<unsigned, 4> Indices; + bool ParsedExtraComma; if (ParseTypeAndValue(Val, Loc, PFS) || - ParseIndexList(Indices)) + ParseIndexList(Indices, ParsedExtraComma)) return true; - if (Lex.getKind() == lltok::MetadataVar) + if (ParsedExtraComma) { + assert(Lex.getKind() == lltok::MetadataVar && "Should only happen for md"); if (ParseOptionalCustomMetadata()) return true; + } if (!isa<StructType>(Val->getType()) && !isa<ArrayType>(Val->getType())) return Error(Loc, "extractvalue operand must be array or struct"); @@ -3786,14 +3801,17 @@ bool LLParser::ParseExtractValue(Instruction *&Inst, PerFunctionState &PFS) { bool LLParser::ParseInsertValue(Instruction *&Inst, PerFunctionState &PFS) { Value *Val0, *Val1; LocTy Loc0, Loc1; SmallVector<unsigned, 4> Indices; + bool ParsedExtraComma; if (ParseTypeAndValue(Val0, Loc0, PFS) || ParseToken(lltok::comma, "expected comma after insertvalue operand") || ParseTypeAndValue(Val1, Loc1, PFS) || - ParseIndexList(Indices)) + ParseIndexList(Indices, ParsedExtraComma)) return true; - if (Lex.getKind() == lltok::MetadataVar) + if (ParsedExtraComma) { + assert(Lex.getKind() == lltok::MetadataVar && "Should only happen for md"); if (ParseOptionalCustomMetadata()) return true; - + } + if (!isa<StructType>(Val0->getType()) && !isa<ArrayType>(Val0->getType())) return Error(Loc0, "extractvalue operand must be array or struct"); |