From: bernhardheld Date: Sun, 11 Apr 2004 21:42:02 +0000 (+0000) Subject: * src/SDCCast.c (decorateType): don't decorate/process parms twice, X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=22ac74a468a03e9989dc8b6365f8a49530e45a95;p=fw%2Fsdcc * src/SDCCast.c (decorateType): don't decorate/process parms twice, (processParms): fixed bug #927659: don't copy parms, this will clear decorated flag * support/regression/tests/bug-927659.c: added git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3284 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index d5edd6b6..73102d64 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,7 +4,11 @@ (geniCodeLogicAndOr): added in order to fix bug #905492, (ast2iCode): fixed bug #905492 * support/regression/tests/bug-905492.c: added - + * src/SDCCast.c (decorateType): don't decorate/process parms twice, + (processParms): fixed bug #927659: don't copy parms, this will clear + decorated flag + * support/regression/tests/bug-927659.c: added + 2004-03-29 Bernhard Held * src/SDCCast.c (addCast): don't cast float to char diff --git a/src/SDCCast.c b/src/SDCCast.c index a7cbd7c0..d32cace4 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -770,17 +770,14 @@ processParms (ast *func, } 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; - (*actParm)->decorated = 0; /* force typechecking */ - decorateType (*actParm, RESULT_TYPE_NONE); - } + { + /* cast required; change this op to a cast. */ + (*actParm)->decorated = 0; + *actParm = newNode (CAST, newType, *actParm); + (*actParm)->lineno = (*actParm)->right->lineno; + + decorateType (*actParm, RESULT_TYPE_NONE); + } return 0; } /* vararg */ @@ -4121,29 +4118,34 @@ decorateType (ast * tree, RESULT_TYPE resultType) goto errorTreeReturn; } - { - sym_link *functype; - parmNumber = 1; + /* if there are parms, make sure that + parms are decorate / process / reverse only once */ + if (!tree->right || + !tree->right->decorated) + { + sym_link *functype; + parmNumber = 1; - if (IS_CODEPTR(LTYPE(tree))) - functype = LTYPE (tree)->next; - else - functype = LTYPE (tree); + if (IS_CODEPTR(LTYPE(tree))) + functype = LTYPE (tree)->next; + else + functype = LTYPE (tree); - if (processParms (tree->left, FUNC_ARGS(functype), - &tree->right, &parmNumber, TRUE)) { - goto errorTreeReturn; - } - - if ((options.stackAuto || IFFUNC_ISREENT (functype)) && - !IFFUNC_ISBUILTIN(functype)) - { - reverseParms (tree->right); - } + if (processParms (tree->left, FUNC_ARGS(functype), + &tree->right, &parmNumber, TRUE)) + { + goto errorTreeReturn; + } + + if ((options.stackAuto || IFFUNC_ISREENT (functype)) && + !IFFUNC_ISBUILTIN(functype)) + { + reverseParms (tree->right); + } - TTYPE (tree) = functype->next; - TETYPE (tree) = getSpec (TTYPE (tree)); - } + TTYPE (tree) = functype->next; + TETYPE (tree) = getSpec (TTYPE (tree)); + } return tree; /*------------------------------------------------------------------*/ diff --git a/support/regression/tests/bug-927659.c b/support/regression/tests/bug-927659.c new file mode 100644 index 00000000..dde1e77d --- /dev/null +++ b/support/regression/tests/bug-927659.c @@ -0,0 +1,59 @@ +/* bug-927659.c + + double processing resp. reversing of params +*/ + +#include +#include +#include + +unsigned char +foo(unsigned char a, ...) REENTRANT +{ + va_list argptr; + unsigned char b; + + va_start (argptr, a); + b = va_arg (argptr, int); + va_end (argptr); + + return b; +} + +unsigned char +bar(unsigned char a, unsigned char b) REENTRANT +{ + return b / a; +} + +void +testReverse(void) +{ + ASSERT(foo (0, bar (1, 2)) == 2); +} + +/*************************************************************/ + +#ifndef PORT_HOST +void putchar (char c) +{ + c; +} +#endif + +void +testAddFunc(void) +{ +#ifndef SDCC_z80 + char buf[5]; + unsigned char count = 0; + + count += sprintf (buf, "%d", 5); + ASSERT(count == 1 && + buf[0] == '5' && + buf[1] == '\0'); +#else + ASSERT(1); +#endif +} +//#endif