fixed bug #436360 part 2, a better type check for function parameters
[fw/sdcc] / src / SDCCicode.c
index 93892f78bb13b75c1058bb56bc2320c7fdf291d3..2c99d04a33c50ccb4e8e99a3beda3cc0ba881e45 100644 (file)
@@ -474,6 +474,10 @@ newiCodeCondition (operand * condition,
 {
   iCode *ic;
 
+  if (IS_VOID(OP_SYMBOL(condition)->type)) {
+    werror(E_VOID_VALUE_USED);
+  }
+
   ic = newiCode (IFX, NULL, NULL);
   IC_COND (ic) = condition;
   IC_TRUE (ic) = trueLabel;
@@ -2103,7 +2107,7 @@ geniCodePostDec (operand * op)
   /* if this is not an address we have trouble */
   if (!op->isaddr)
     {
-      werror (E_LVALUE_REQUIRED, "++");
+      werror (E_LVALUE_REQUIRED, "--");
       return op;
     }
 
@@ -2147,7 +2151,7 @@ geniCodePreDec (operand * op)
 
   if (!op->isaddr)
     {
-      werror (E_LVALUE_REQUIRED, "++");
+      werror (E_LVALUE_REQUIRED, "--");
       return op;
     }
 
@@ -2396,7 +2400,7 @@ geniCodeLogic (operand * left, operand * right, int op)
 
   /* left is integral type and right is literal then
      check if the literal value is within bounds */
-  if (IS_INTEGRAL (ltype) && IS_LITERAL (rtype))
+  if (IS_INTEGRAL (ltype) && IS_VALOP (right) && IS_LITERAL (rtype))
     {
       int nbits = bitsForType (ltype);
       long v = (long) operandLitValue (right);
@@ -2661,6 +2665,12 @@ geniCodeCall (operand * left, ast * parms,int lvl)
   sym_link *type, *etype;
   int stack = 0;
 
+  if (!IS_FUNC(OP_SYMBOL(left)->type) && 
+      !IS_CODEPTR(OP_SYMBOL(left)->type)) {
+    werror (E_FUNCTION_EXPECTED);
+    return NULL;
+  }
+
   /* take care of parameters with side-effecting
      function calls in them, this is required to take care
      of overlaying function parameters */
@@ -3025,8 +3035,16 @@ geniCodeArrayInit (ast * tree, operand *array)
 {
   iCode *ic;
 
-  ic = newiCode (ARRAYINIT, array, NULL);
-  IC_ARRAYILIST (ic) = tree->values.constlist;
+  if (!getenv("TRY_THE_NEW_INITIALIZER")) {
+    ic = newiCode (ARRAYINIT, array, NULL);
+    IC_ARRAYILIST (ic) = tree->values.constlist;
+  } else {
+    operand *left=newOperand(), *right=newOperand();
+    left->type=right->type=SYMBOL;
+    OP_SYMBOL(left)=AST_SYMBOL(tree->left);
+    OP_SYMBOL(right)=AST_SYMBOL(tree->right);
+    ic = newiCode (ARRAYINIT, left, right);
+  }
   ADDTOCHAIN (ic);
 }