[llvm-commits] [llvm] r50182 - /llvm/trunk/lib/VMCore/Verifier.cpp

Chris Lattner sabre at nondot.org
Wed Apr 23 13:33:42 PDT 2008


Author: lattner
Date: Wed Apr 23 15:33:41 2008
New Revision: 50182

URL: http://llvm.org/viewvc/llvm-project?rev=50182&view=rev
Log:
tighten up verifier checks which missed cases where
return instrs operands didn't match up with function results.

Modified:
    llvm/trunk/lib/VMCore/Verifier.cpp

Modified: llvm/trunk/lib/VMCore/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Verifier.cpp?rev=50182&r1=50181&r2=50182&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Verifier.cpp (original)
+++ llvm/trunk/lib/VMCore/Verifier.cpp Wed Apr 23 15:33:41 2008
@@ -592,22 +592,23 @@
 void Verifier::visitReturnInst(ReturnInst &RI) {
   Function *F = RI.getParent()->getParent();
   unsigned N = RI.getNumOperands();
-  if (N == 0) 
-    Assert2(F->getReturnType() == Type::VoidTy,
+  if (F->getReturnType() == Type::VoidTy) 
+    Assert2(N == 0,
             "Found return instr that returns void in Function of non-void "
             "return type!", &RI, 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(),
               "Function return type does not match operand "
               "type of return inst!", &RI, F->getReturnType());
-  } 
-  else if (N == 1) 
-    Assert2(F->getReturnType() == RI.getOperand(0)->getType(),
+  } else {
+    Assert2(N == 1 && F->getReturnType() == RI.getOperand(0)->getType(),
             "Function return type does not match operand "
             "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
   // terminators...





More information about the llvm-commits mailing list