From 2004a3562e7ee5bfc7b62ec0c843cea8d5f01aaf Mon Sep 17 00:00:00 2001 From: borutr Date: Sun, 24 Feb 2008 20:59:03 +0000 Subject: [PATCH] * src/SDCCast.c, src/SDCCast.h: fixed bug #1874922: explicit typecast is ineffective for unsigned char parameter git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5044 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 9 +++++++-- src/SDCCast.c | 23 +++++++++++++++-------- src/SDCCast.h | 1 + 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index c6ed9cd4..23c54095 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-02-24 Borut Razem + + * src/SDCCast.c, src/SDCCast.h: fixed bug #1874922: explicit typecast + is ineffective for unsigned char parameter + 2008-02-24 Maarten Brock * src/SDCCast.c (expandInlineFuncs): fixed bug 1875869 @@ -8,12 +13,12 @@ 2008-02-22 Philipp Klaus Krause * src/z80/gen.c (genMult): Rewrote 8-bit multiplication by constant, - implements #1898231 + implements #1898231 2008-02-22 Philipp Klaus Krause * device/lib/z80/mul.s: Rewrote __muluchar_rrx_s, to improve 8-bit mult., - implements #1896290 + implements #1896290 2008-02-22 Maarten Brock diff --git a/src/SDCCast.c b/src/SDCCast.c index 2fd83186..24c3eb1c 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -227,6 +227,7 @@ copyAst (ast * src) dest->level = src->level; dest->funcName = src->funcName; dest->reversed = src->reversed; + dest->actualArgument = src->actualArgument; if (src->ftype) dest->etype = getSpec (dest->ftype = copyLinkChain (src->ftype)); @@ -837,6 +838,9 @@ processParms (ast *func, } } + /* mark the actual parameter */ + (*actParm)->actualArgument = 1; + /* decorate parameter */ resultType = defParm ? getResultTypeFromType (defParm->type) : RESULT_TYPE_NONE; @@ -854,8 +858,11 @@ processParms (ast *func, ast *newType = NULL; sym_link *ftype; + int isCast = IS_CAST_OP (*actParm); + int isAstLitValue = (IS_AST_LIT_VALUE (*actParm)); + if (IS_CAST_OP (*actParm) - || (IS_AST_LIT_VALUE (*actParm) && (*actParm)->values.literalFromCast)) + || (IS_AST_LIT_VALUE (*actParm) && (*actParm)->values.literalFromCast)) { /* Parameter was explicitly typecast; don't touch it. */ return 0; @@ -3834,9 +3841,11 @@ decorateType (ast * tree, RESULT_TYPE resultType) changePointer(LTYPE(tree)); checkTypeSanity(LETYPE(tree), "(cast)"); - /* if 'from' and 'to' are the same remove the superfluous cast, */ - /* this helps other optimizations */ - if (compareTypeExact (LTYPE(tree), RTYPE(tree), -1) == 1) + + /* if not an actual argument and + * if 'from' and 'to' are the same remove the superfluous cast, + * this helps other optimizations */ + if (!tree->actualArgument && compareTypeExact (LTYPE(tree), RTYPE(tree), -1) == 1) { return tree->right; } @@ -4153,9 +4162,7 @@ decorateType (ast * tree, RESULT_TYPE resultType) if (!options.lessPedantic) werrorfl (tree->filename, tree->lineno, W_COMP_RANGE, ccr_result == CCR_ALWAYS_TRUE ? "true" : "false"); - return decorateType (newAst_VALUE (constCharVal ( - (unsigned char)(ccr_result == CCR_ALWAYS_TRUE ? 1 : 0))), - resultType); + return decorateType (newAst_VALUE (constCharVal ((unsigned char)(ccr_result == CCR_ALWAYS_TRUE))), resultType); case CCR_OK: default: break; @@ -6306,7 +6313,7 @@ expandInlineFuncs (ast * tree, ast * block) ast * assigntree; symbol * parm; ast * passedarg = inlineFindParm (tree->right, argIndex); - + if (!passedarg) { werror(E_TOO_FEW_PARMS); diff --git a/src/SDCCast.h b/src/SDCCast.h index 3b8ec6e1..3bf42291 100644 --- a/src/SDCCast.h +++ b/src/SDCCast.h @@ -50,6 +50,7 @@ typedef struct ast unsigned lvalue:1; unsigned initMode:1; unsigned reversed:1; + unsigned actualArgument:1; /* actual function argument */ int level; /* level for expr */ int block; /* block number */ int seqPoint; /* sequence point */ -- 2.30.2