upcast parameters to varargs functions to int or generic pointers where appropriate
authorkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 26 Jan 2001 23:15:41 +0000 (23:15 +0000)
committerkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 26 Jan 2001 23:15:41 +0000 (23:15 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@541 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCast.c
src/SDCCast.h

index c109a873569fb55390593c7c3b0c16bc6746d54f..c56f9c822ce329295fef979e8b7284a395e9ba4c 100644 (file)
@@ -588,10 +588,50 @@ int processParms (ast *func, value *defParm,
        return 1;
     }
         
+    /* If this is a varagrs function... */ 
+    if (!defParm && actParm && func->hasVargs )
+    {
+        ast *newType = NULL;
+        
+       if (IS_CAST_OP(actParm) 
+        || (IS_AST_LIT_VALUE(actParm) && actParm->values.literalFromCast))
+       {
+          /* Parameter was explicitly typecast; don't touch it. */
+          return 0;
+       }    
+        
+        /* If it's a small integer, upcast to int. */
+       if (IS_INTEGRAL(actParm->ftype)
+         && getSize(actParm->ftype) < INTSIZE)
+        {
+           newType = newAst_LINK(INTTYPE);
+        }
+        
+        if (IS_PTR(actParm->ftype) && !IS_GENPTR(actParm->ftype))
+        {
+            newType = newAst_LINK(copyLinkChain(actParm->ftype));
+            DCL_TYPE(newType->opval.lnk) = GPOINTER;
+        }
+        
+        if (newType)
+        {
+           /* cast required; change this op to a cast. */
+            ast *parmCopy = resolveSymbols(copyAst(actParm));
+           
+           actParm->type = EX_OP;
+           actParm->opval.op = CAST;
+           actParm->left = newType;
+           actParm->right= parmCopy;
+           decorateType(actParm);           
+        }
+        
+        return 0;
+    }        
+        
     /* if defined parameters ended but actual has not & */
-    /* has a variable argument list or statckAuto       */
+    /* stackAuto                                               */
     if (! defParm && actParm && 
-       (func->hasVargs || options.stackAuto || IS_RENT(fetype)))
+       (options.stackAuto || IS_RENT(fetype)))
        return 0;
     
     resolveSymbols(actParm);
@@ -2360,6 +2400,7 @@ ast *decorateType (ast *tree)
            tree->left = NULL;
            tree->right = NULL;
            TTYPE(tree) = tree->opval.val->type;            
+           tree->values.literalFromCast = 1;
        }
        else {
            TTYPE(tree) = LTYPE(tree);
index 7af66517130c6d3e620c60dcdd5204345fe38e1f..617b944d689288c2c30ada0d30746b9898b636f3 100644 (file)
@@ -79,6 +79,9 @@ typedef  struct   ast {
            symbol   *continueLabel;  /* conditional check   */
            symbol   *condLabel;      /* conditional label   */
        } forVals ;
+       unsigned literalFromCast;     /* true if this is an EX_VALUE of LITERAL 
+                                      * type resulting from a typecast.
+                                      */
     } values ;
     
     int   lineno         ;  /* source file line number     */