tighten up verifier checks which missed cases where

return instrs operands didn't match up with function results.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50182 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2008-04-23 20:33:41 +00:00
parent 67780f108c
commit 80b8f5dd6b

View File

@@ -592,22 +592,23 @@ void Verifier::visitTerminatorInst(TerminatorInst &I) {
void Verifier::visitReturnInst(ReturnInst &RI) { void Verifier::visitReturnInst(ReturnInst &RI) {
Function *F = RI.getParent()->getParent(); Function *F = RI.getParent()->getParent();
unsigned N = RI.getNumOperands(); unsigned N = RI.getNumOperands();
if (N == 0) if (F->getReturnType() == Type::VoidTy)
Assert2(F->getReturnType() == Type::VoidTy, Assert2(N == 0,
"Found return instr that returns void in Function of non-void " "Found return instr that returns void in Function of non-void "
"return type!", &RI, F->getReturnType()); "return type!", &RI, F->getReturnType());
else if (const StructType *STy = dyn_cast<StructType>(F->getReturnType())) { else if (const StructType *STy = dyn_cast<StructType>(F->getReturnType())) {
for (unsigned i = 0; i < N; i++) Assert2(STy->getNumElements() == N,
"Incorrect number of return values in ret instruction!",
&RI, F->getReturnType());
for (unsigned i = 0; i != N; ++i)
Assert2(STy->getElementType(i) == RI.getOperand(i)->getType(), Assert2(STy->getElementType(i) == RI.getOperand(i)->getType(),
"Function return type does not match operand " "Function return type does not match operand "
"type of return inst!", &RI, F->getReturnType()); "type of return inst!", &RI, F->getReturnType());
} } else {
else if (N == 1) Assert2(N == 1 && F->getReturnType() == RI.getOperand(0)->getType(),
Assert2(F->getReturnType() == RI.getOperand(0)->getType(),
"Function return type does not match operand " "Function return type does not match operand "
"type of return inst!", &RI, F->getReturnType()); "type of return inst!", &RI, F->getReturnType());
else }
Assert1(0, "Invalid return type!", &RI);
// Check to make sure that the return value has necessary properties for // Check to make sure that the return value has necessary properties for
// terminators... // terminators...