more function pointer parameter issues
[fw/sdcc] / src / SDCCicode.c
index 0caa5b2f9643a03d7bfa94523173ded256709600..7dca929a28cb09708a605048325f32af70359385 100644 (file)
@@ -136,9 +136,17 @@ void checkConstantRange(sym_link *ltype, value *val, char *msg, int pedantic) {
   max = pow ((double)2.0, (double)bitsForType(ltype));
 
   if (SPEC_LONG(val->type)) {
-    v=SPEC_CVAL(val->type).v_long;
+    if (SPEC_USIGN(val->type)) {
+      v=SPEC_CVAL(val->type).v_ulong;
+    } else {
+      v=SPEC_CVAL(val->type).v_long;
+    }
   } else {
-    v=SPEC_CVAL(val->type).v_int;
+    if (SPEC_USIGN(val->type)) {
+      v=SPEC_CVAL(val->type).v_uint;
+    } else {
+      v=SPEC_CVAL(val->type).v_int;
+    }
   }
 
 
@@ -541,7 +549,7 @@ newiCodeCondition (operand * condition,
 {
   iCode *ic;
 
-  if (IS_VOID(OP_SYMBOL(condition)->type)) {
+  if (IS_VOID(operandType(condition))) {
     werror(E_VOID_VALUE_USED);
   }
 
@@ -1258,7 +1266,6 @@ operandFromSymbol (symbol * sym)
      register equivalent for a local symbol */
   if (sym->level && sym->etype && SPEC_OCLS (sym->etype) &&
       (IN_FARSPACE (SPEC_OCLS (sym->etype)) &&
-      /* (!TARGET_IS_DS390)) && */
       (!(options.model == MODEL_FLAT24)) ) &&
       options.stackAuto == 0)
     ok = 0;
@@ -1268,7 +1275,7 @@ operandFromSymbol (symbol * sym)
       !sym->_isparm &&         /* not a parameter  */
       sym->level &&            /* is a local variable */
       !sym->addrtaken &&       /* whose address has not been taken */
-      !sym->reqv &&            /* does not already have a register euivalence */
+      !sym->reqv &&            /* does not already have a reg equivalence */
       !IS_VOLATILE (sym->etype) &&     /* not declared as volatile */
       !IS_STATIC (sym->etype) &&       /* and not declared static  */
       !sym->islbl &&           /* not a label */
@@ -1284,6 +1291,7 @@ operandFromSymbol (symbol * sym)
       OP_SYMBOL (sym->reqv)->key = sym->key;
       OP_SYMBOL (sym->reqv)->isreqv = 1;
       OP_SYMBOL (sym->reqv)->islocal = 1;
+      OP_SYMBOL (sym->reqv)->onStack = sym->onStack;
       SPIL_LOC (sym->reqv) = sym;
     }
 
@@ -1322,8 +1330,6 @@ operandFromSymbol (symbol * sym)
   else
     IC_RESULT (ic)->isaddr = (!IS_AGGREGATE (sym->type));
 
-  IC_RESULT (ic)->operand.symOperand->args = sym->args;
-
   ADDTOCHAIN (ic);
 
   return IC_RESULT (ic);
@@ -1564,10 +1570,6 @@ geniCodeRValue (operand * op, bool force)
 
 /*     ic->supportRtn = ((IS_GENPTR(type) | op->isGptr) & op->isaddr); */
 
-  /* if the right is a symbol */
-  if (op->type == SYMBOL)
-    IC_RESULT (ic)->operand.symOperand->args =
-      op->operand.symOperand->args;
   ADDTOCHAIN (ic);
 
   return IC_RESULT (ic);
@@ -1656,13 +1658,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit)
     }
   }
   if (errors) {
-    /* fprintf (stderr, "%s%s %d: ", op->operand.symOperand->name,
-       implicit?"(implicit)":"", errors); */
-    fprintf (stderr, "from type '");
-    printTypeChain (optype, stderr);
-    fprintf (stderr, "' to type '");
-    printTypeChain (type, stderr);
-    fprintf (stderr, "'\n");
+    printFromToType (optype, type);
   }
 
   /* if they are the same size create an assignment */
@@ -2618,7 +2614,7 @@ geniCodeAssign (operand * left, operand * right, int nosupdate)
 
   /* first check the type for pointer assignement */
   if (left->isaddr && IS_PTR (ltype) && IS_ITEMP (left) &&
-      compareType (ltype, rtype) < 0)
+      compareType (ltype, rtype) <= 0)
     {
       if (compareType (ltype->next, rtype) < 0)
        right = geniCodeCast (ltype->next, right, TRUE);
@@ -2693,21 +2689,27 @@ geniCodeSEParms (ast * parms,int lvl)
 /*-----------------------------------------------------------------*/
 /* geniCodeParms - generates parameters                            */
 /*-----------------------------------------------------------------*/
-static void 
-geniCodeParms (ast * parms, int *stack, sym_link * fetype, symbol * func,int lvl)
+value *
+geniCodeParms (ast * parms, value *argVals, int *stack, 
+              sym_link * fetype, symbol * func,int lvl)
 {
   iCode *ic;
   operand *pval;
 
   if (!parms)
-    return;
+    return argVals;
+
+  if (argVals==NULL) {
+    // first argument
+    argVals=FUNC_ARGS(func->type);
+  }
 
   /* if this is a param node then do the left & right */
   if (parms->type == EX_OP && parms->opval.op == PARAM)
     {
-      geniCodeParms (parms->left, stack, fetype, func,lvl);
-      geniCodeParms (parms->right, stack, fetype, func,lvl);
-      return;
+      argVals=geniCodeParms (parms->left, argVals, stack, fetype, func,lvl);
+      argVals=geniCodeParms (parms->right, argVals, stack, fetype, func,lvl);
+      return argVals;
     }
 
   /* get the parameter value */
@@ -2730,8 +2732,7 @@ geniCodeParms (ast * parms, int *stack, sym_link * fetype, symbol * func,int lvl
     }
 
   /* if register parm then make it a send */
-  if (((parms->argSym && IS_REGPARM (parms->argSym->etype)) ||
-       IS_REGPARM (parms->etype)) && !func->hasVargs)
+  if (IS_REGPARM (parms->etype) && !IFFUNC_HASVARARGS(func->type))
     {
       ic = newiCode (SEND, pval, NULL);
       ADDTOCHAIN (ic);
@@ -2739,11 +2740,11 @@ geniCodeParms (ast * parms, int *stack, sym_link * fetype, symbol * func,int lvl
   else
     {
       /* now decide whether to push or assign */
-      if (!(options.stackAuto || IS_RENT (fetype)))
+      if (!(options.stackAuto || IFFUNC_ISREENT (func->type)))
        {
 
          /* assign */
-         operand *top = operandFromSymbol (parms->argSym);
+         operand *top = operandFromSymbol (argVals->sym);
          geniCodeAssign (top, pval, 1);
        }
       else
@@ -2758,6 +2759,8 @@ geniCodeParms (ast * parms, int *stack, sym_link * fetype, symbol * func,int lvl
        }
     }
 
+  argVals=argVals->next;
+  return argVals;
 }
 
 /*-----------------------------------------------------------------*/
@@ -2783,7 +2786,7 @@ geniCodeCall (operand * left, ast * parms,int lvl)
   geniCodeSEParms (parms,lvl);
 
   /* first the parameters */
-  geniCodeParms (parms, &stack, getSpec (operandType (left)), OP_SYMBOL (left),lvl);
+  geniCodeParms (parms, NULL, &stack, getSpec (operandType (left)), OP_SYMBOL (left),lvl);
 
   /* now call : if symbol then pcall */
   if (IS_OP_POINTER (left) || IS_ITEMP(left))
@@ -2791,7 +2794,7 @@ geniCodeCall (operand * left, ast * parms,int lvl)
   else
     ic = newiCode (CALL, left, NULL);
 
-  IC_ARGS (ic) = left->operand.symOperand->args;
+  IC_ARGS (ic) = FUNC_ARGS(left->operand.symOperand->type);
   type = copyLinkChain (operandType (left)->next);
   etype = getSpec (type);
   SPEC_EXTR (etype) = 0;
@@ -2947,14 +2950,14 @@ geniCodeIfx (ast * tree,int lvl)
          if (tree->trueLabel)
            geniCodeGoto (tree->trueLabel);
          else
-           assert (1);
+           assert (0);
        }
       else
        {
          if (tree->falseLabel)
            geniCodeGoto (tree->falseLabel);
          else
-           assert (1);
+           assert (0);
        }
       goto exit;
     }