[llvm-commits] CVS: llvm/lib/VMCore/Instructions.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue May 2 17:48:34 PDT 2006



Changes in directory llvm/lib/VMCore:

Instructions.cpp updated: 1.35 -> 1.36
---
Log message:

Add assertions that verify that the actual arguments to a call or invoke match
the prototype of the called function.


---
Diffs of the changes:  (+22 -4)

 Instructions.cpp |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)


Index: llvm/lib/VMCore/Instructions.cpp
diff -u llvm/lib/VMCore/Instructions.cpp:1.35 llvm/lib/VMCore/Instructions.cpp:1.36
--- llvm/lib/VMCore/Instructions.cpp:1.35	Fri Apr 14 17:20:32 2006
+++ llvm/lib/VMCore/Instructions.cpp	Tue May  2 19:48:22 2006
@@ -197,9 +197,13 @@
 
   assert((Params.size() == FTy->getNumParams() ||
           (FTy->isVarArg() && Params.size() > FTy->getNumParams())) &&
-         "Calling a function with bad signature");
-  for (unsigned i = 0, e = Params.size(); i != e; ++i)
+         "Calling a function with bad signature!");
+  for (unsigned i = 0, e = Params.size(); i != e; ++i) {
+    assert((i >= FTy->getNumParams() || 
+            FTy->getParamType(i) == Params[i]->getType()) &&
+           "Calling a function with a bad signature!");
     OL[i+1].init(Params[i], this);
+  }
 }
 
 void CallInst::init(Value *Func, Value *Actual1, Value *Actual2) {
@@ -213,8 +217,14 @@
     cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
 
   assert((FTy->getNumParams() == 2 ||
-          (FTy->isVarArg() && FTy->getNumParams() == 0)) &&
+          (FTy->isVarArg() && FTy->getNumParams() < 2)) &&
          "Calling a function with bad signature");
+  assert((0 >= FTy->getNumParams() || 
+          FTy->getParamType(0) == Actual1->getType()) &&
+         "Calling a function with a bad signature!");
+  assert((1 >= FTy->getNumParams() || 
+          FTy->getParamType(1) == Actual2->getType()) &&
+         "Calling a function with a bad signature!");
 }
 
 void CallInst::init(Value *Func, Value *Actual) {
@@ -229,6 +239,9 @@
   assert((FTy->getNumParams() == 1 ||
           (FTy->isVarArg() && FTy->getNumParams() == 0)) &&
          "Calling a function with bad signature");
+  assert((0 == FTy->getNumParams() || 
+          FTy->getParamType(0) == Actual->getType()) &&
+         "Calling a function with a bad signature!");
 }
 
 void CallInst::init(Value *Func) {
@@ -339,8 +352,13 @@
          (FTy->isVarArg() && Params.size() > FTy->getNumParams()) &&
          "Calling a function with bad signature");
 
-  for (unsigned i = 0, e = Params.size(); i != e; i++)
+  for (unsigned i = 0, e = Params.size(); i != e; i++) {
+    assert((i >= FTy->getNumParams() || 
+            FTy->getParamType(i) == Params[i]->getType()) &&
+           "Invoking a function with a bad signature!");
+    
     OL[i+3].init(Params[i], this);
+  }
 }
 
 InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal,






More information about the llvm-commits mailing list