From 899ee91ab8169609f83f2c34c14d9112df2bb085 Mon Sep 17 00:00:00 2001 From: kvigor Date: Fri, 26 Jan 2001 23:15:41 +0000 Subject: [PATCH] upcast parameters to varargs functions to int or generic pointers where appropriate git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@541 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCast.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- src/SDCCast.h | 3 +++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/SDCCast.c b/src/SDCCast.c index c109a873..c56f9c82 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -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); diff --git a/src/SDCCast.h b/src/SDCCast.h index 7af66517..617b944d 100644 --- a/src/SDCCast.h +++ b/src/SDCCast.h @@ -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 */ -- 2.39.5