diff gen/tocall.cpp @ 530:d30c40f1128d

Make class invariants work.
author Christian Kamm <kamm incasoftware de>
date Thu, 21 Aug 2008 15:19:45 +0200
parents 642f6fa854e5
children fbb1a366cfbc
line wrap: on
line diff
--- a/gen/tocall.cpp	Wed Aug 20 19:03:28 2008 +0200
+++ b/gen/tocall.cpp	Thu Aug 21 15:19:45 2008 +0200
@@ -113,8 +113,11 @@
     int begin = tf->parameters->dim;
     Logger::println("num non vararg params = %d", begin);
 
+    // get n args in arguments list
+    size_t n_arguments = arguments ? arguments->dim : 0;
+
     // build struct with argument types (non variadic args)
-    for (int i=begin; i<arguments->dim; i++)
+    for (int i=begin; i<n_arguments; i++)
     {
         Expression* argexp = (Expression*)arguments->data[i];
         vtypes.push_back(DtoType(argexp->type));
@@ -127,7 +130,7 @@
     LLValue* mem = DtoAlloca(vtype,"_argptr_storage");
 
     // store arguments in the struct
-    for (int i=begin,k=0; i<arguments->dim; i++,k++)
+    for (int i=begin,k=0; i<n_arguments; i++,k++)
     {
         Expression* argexp = (Expression*)arguments->data[i];
         if (global.params.llvmAnnotate)
@@ -147,7 +150,7 @@
     Logger::cout() << "_arguments storage: " << *typeinfomem << '\n';
 
     std::vector<LLConstant*> vtypeinfos;
-    for (int i=begin,k=0; i<arguments->dim; i++,k++)
+    for (int i=begin,k=0; i<n_arguments; i++,k++)
     {
         Expression* argexp = (Expression*)arguments->data[i];
         vtypeinfos.push_back(DtoTypeInfoOf(argexp->type));
@@ -219,6 +222,9 @@
     const LLFunctionType* callableTy = DtoExtractFunctionType(callable->getType());
     assert(callableTy);
 
+    // get n arguments
+    size_t n_arguments = arguments ? arguments->dim : 0;
+
     // get llvm argument iterator, for types
     LLFunctionType::param_iterator argbegin = callableTy->param_begin();
     LLFunctionType::param_iterator argiter = argbegin;
@@ -280,8 +286,7 @@
     // variadic instrinsics need some custom casts
     if (va_intrinsic)
     {
-        size_t n = arguments->dim;
-        for (int i=0; i<n; i++)
+        for (int i=0; i<n_arguments; i++)
         {
             Expression* exp = (Expression*)arguments->data[i];
             DValue* expelem = exp->toElem(gIR);
@@ -302,7 +307,7 @@
     else
     {
         Logger::println("doing normal arguments");
-        for (int i=0; i<arguments->dim; i++) {
+        for (int i=0; i<n_arguments; i++) {
             int j = argiter-argbegin;
             Argument* fnarg = Argument::getNth(tf->parameters, i);
             DValue* argval = DtoArgument(fnarg, (Expression*)arguments->data[i]);