forked from OSchip/llvm-project
				
			reimplement insertvalue/extractvalue metadata handling to not blindly
accept invalid input. Actually add a testcase. llvm-svn: 92297
This commit is contained in:
		
							parent
							
								
									bafee45d2c
								
							
						
					
					
						commit
						28f1eebe3e
					
				| 
						 | 
					@ -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
 | 
					/// ParseIndexList
 | 
				
			||||||
///    ::=  (',' uint32)+
 | 
					///    ::=  (',' uint32)+
 | 
				
			||||||
bool LLParser::ParseIndexList(SmallVectorImpl<unsigned> &Indices) {
 | 
					///
 | 
				
			||||||
 | 
					bool LLParser::ParseIndexList(SmallVectorImpl<unsigned> &Indices,
 | 
				
			||||||
 | 
					                              bool &AteExtraComma) {
 | 
				
			||||||
 | 
					  AteExtraComma = false;
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  if (Lex.getKind() != lltok::comma)
 | 
					  if (Lex.getKind() != lltok::comma)
 | 
				
			||||||
    return TokError("expected ',' as start of index list");
 | 
					    return TokError("expected ',' as start of index list");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  while (EatIfPresent(lltok::comma)) {
 | 
					  while (EatIfPresent(lltok::comma)) {
 | 
				
			||||||
    // FIXME: TERRIBLE HACK.  Loses comma state.
 | 
					    if (Lex.getKind() == lltok::MetadataVar) {
 | 
				
			||||||
    if (Lex.getKind() == lltok::MetadataVar)
 | 
					      AteExtraComma = true;
 | 
				
			||||||
      break;
 | 
					      return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    unsigned Idx;
 | 
					    unsigned Idx;
 | 
				
			||||||
    if (ParseUInt32(Idx)) return true;
 | 
					    if (ParseUInt32(Idx)) return true;
 | 
				
			||||||
    Indices.push_back(Idx);
 | 
					    Indices.push_back(Idx);
 | 
				
			||||||
| 
						 | 
					@ -2803,6 +2814,7 @@ bool LLParser::ParseBasicBlock(PerFunctionState &PFS) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (ParseInstruction(Inst, BB, PFS)) return true;
 | 
					    if (ParseInstruction(Inst, BB, PFS)) return true;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    if (EatIfPresent(lltok::comma))
 | 
					    if (EatIfPresent(lltok::comma))
 | 
				
			||||||
      ParseOptionalCustomMetadata();
 | 
					      ParseOptionalCustomMetadata();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3765,11 +3777,14 @@ bool LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
 | 
				
			||||||
bool LLParser::ParseExtractValue(Instruction *&Inst, PerFunctionState &PFS) {
 | 
					bool LLParser::ParseExtractValue(Instruction *&Inst, PerFunctionState &PFS) {
 | 
				
			||||||
  Value *Val; LocTy Loc;
 | 
					  Value *Val; LocTy Loc;
 | 
				
			||||||
  SmallVector<unsigned, 4> Indices;
 | 
					  SmallVector<unsigned, 4> Indices;
 | 
				
			||||||
 | 
					  bool ParsedExtraComma;
 | 
				
			||||||
  if (ParseTypeAndValue(Val, Loc, PFS) ||
 | 
					  if (ParseTypeAndValue(Val, Loc, PFS) ||
 | 
				
			||||||
      ParseIndexList(Indices))
 | 
					      ParseIndexList(Indices, ParsedExtraComma))
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
  if (Lex.getKind() == lltok::MetadataVar)
 | 
					  if (ParsedExtraComma) {
 | 
				
			||||||
 | 
					    assert(Lex.getKind() == lltok::MetadataVar && "Should only happen for md");
 | 
				
			||||||
    if (ParseOptionalCustomMetadata()) return true;
 | 
					    if (ParseOptionalCustomMetadata()) return true;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isa<StructType>(Val->getType()) && !isa<ArrayType>(Val->getType()))
 | 
					  if (!isa<StructType>(Val->getType()) && !isa<ArrayType>(Val->getType()))
 | 
				
			||||||
    return Error(Loc, "extractvalue operand must be array or struct");
 | 
					    return Error(Loc, "extractvalue operand must be array or struct");
 | 
				
			||||||
| 
						 | 
					@ -3786,13 +3801,16 @@ bool LLParser::ParseExtractValue(Instruction *&Inst, PerFunctionState &PFS) {
 | 
				
			||||||
bool LLParser::ParseInsertValue(Instruction *&Inst, PerFunctionState &PFS) {
 | 
					bool LLParser::ParseInsertValue(Instruction *&Inst, PerFunctionState &PFS) {
 | 
				
			||||||
  Value *Val0, *Val1; LocTy Loc0, Loc1;
 | 
					  Value *Val0, *Val1; LocTy Loc0, Loc1;
 | 
				
			||||||
  SmallVector<unsigned, 4> Indices;
 | 
					  SmallVector<unsigned, 4> Indices;
 | 
				
			||||||
 | 
					  bool ParsedExtraComma;
 | 
				
			||||||
  if (ParseTypeAndValue(Val0, Loc0, PFS) ||
 | 
					  if (ParseTypeAndValue(Val0, Loc0, PFS) ||
 | 
				
			||||||
      ParseToken(lltok::comma, "expected comma after insertvalue operand") ||
 | 
					      ParseToken(lltok::comma, "expected comma after insertvalue operand") ||
 | 
				
			||||||
      ParseTypeAndValue(Val1, Loc1, PFS) ||
 | 
					      ParseTypeAndValue(Val1, Loc1, PFS) ||
 | 
				
			||||||
      ParseIndexList(Indices))
 | 
					      ParseIndexList(Indices, ParsedExtraComma))
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
  if (Lex.getKind() == lltok::MetadataVar)
 | 
					  if (ParsedExtraComma) {
 | 
				
			||||||
 | 
					    assert(Lex.getKind() == lltok::MetadataVar && "Should only happen for md");
 | 
				
			||||||
    if (ParseOptionalCustomMetadata()) return true;
 | 
					    if (ParseOptionalCustomMetadata()) return true;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  if (!isa<StructType>(Val0->getType()) && !isa<ArrayType>(Val0->getType()))
 | 
					  if (!isa<StructType>(Val0->getType()) && !isa<ArrayType>(Val0->getType()))
 | 
				
			||||||
    return Error(Loc0, "extractvalue operand must be array or struct");
 | 
					    return Error(Loc0, "extractvalue operand must be array or struct");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -173,7 +173,14 @@ namespace llvm {
 | 
				
			||||||
    bool ParseOptionalAlignment(unsigned &Alignment);
 | 
					    bool ParseOptionalAlignment(unsigned &Alignment);
 | 
				
			||||||
    bool ParseOptionalCustomMetadata();
 | 
					    bool ParseOptionalCustomMetadata();
 | 
				
			||||||
    bool ParseOptionalInfo(unsigned &Alignment);
 | 
					    bool ParseOptionalInfo(unsigned &Alignment);
 | 
				
			||||||
    bool ParseIndexList(SmallVectorImpl<unsigned> &Indices);
 | 
					    bool ParseIndexList(SmallVectorImpl<unsigned> &Indices,bool &AteExtraComma);
 | 
				
			||||||
 | 
					    bool ParseIndexList(SmallVectorImpl<unsigned> &Indices) {
 | 
				
			||||||
 | 
					      bool AteExtraComma;
 | 
				
			||||||
 | 
					      if (ParseIndexList(Indices, AteExtraComma)) return true;
 | 
				
			||||||
 | 
					      if (AteExtraComma)
 | 
				
			||||||
 | 
					        return TokError("expected index");
 | 
				
			||||||
 | 
					      return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Top-Level Entities
 | 
					    // Top-Level Entities
 | 
				
			||||||
    bool ParseTopLevelEntities();
 | 
					    bool ParseTopLevelEntities();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,11 +5,13 @@ define void @test() {
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  call void @llvm.dbg.func.start(metadata !"foo")
 | 
					  call void @llvm.dbg.func.start(metadata !"foo")
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					  extractvalue {{i32, i32}, i32} undef, 0, 1, !foo !0
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  ret void, !foo !0, !bar !1
 | 
					  ret void, !foo !0, !bar !1
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
!0 = metadata !{i32 662302, i32 26, metadata !1, null}
 | 
					!0 = metadata !{i32 662302, i32 26, metadata !1, null}
 | 
				
			||||||
!1 = metadata !{i32 4}
 | 
					!1 = metadata !{i32 4, metadata !"foo"}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
declare void @llvm.dbg.func.start(metadata) nounwind readnone
 | 
					declare void @llvm.dbg.func.start(metadata) nounwind readnone
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue