From: bernhardheld Date: Mon, 22 Mar 2004 20:29:18 +0000 (+0000) Subject: * src/SDCCast.c (processParms): fixed bug #920866; decorateType() can return an optim... X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=aaa16aad6fcd7bfcfd2c2070bcfe59bf0da07244;p=fw%2Fsdcc * src/SDCCast.c (processParms): fixed bug #920866; decorateType() can return an optimized tree; actually replace actParm with the new tree * src/SDCCast.h: added some parantheses to remove side effects * support/regression/tests/bug-920866.c git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3274 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 85845494..d7868d5d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-03-22 Bernhard Held + + * src/SDCCast.c (processParms): fixed bug #920866; decorateType() can + return an optimized tree; actually replace actParm with the new tree + * src/SDCCast.h: added some parantheses to remove side effects + * support/regression/tests/bug-920866.c + 2004-03-21 Scott Dattalo * src/pic/gen.c, src/pic/gen.h, src/pic/genarith.c, src/pic/pcode.c: Bit operands were not being handled properly in the pic14 port. @@ -96,7 +103,7 @@ reported by Adam Wozniak in Sdcc-user list 2004-03-10 Bernhard Held - + * src/SDCCast.c (decorateType): fixed with bug and promotion in arithmetic optimizations, added debug output diff --git a/src/SDCCast.c b/src/SDCCast.c index 5d7bdffc..b56020d2 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -649,7 +649,7 @@ reverseParms (ast * ptree) static int processParms (ast *func, value *defParm, - ast *actParm, + ast **actParm, int *parmNumber, /* unused, although updated */ bool rightmost) { @@ -657,7 +657,7 @@ processParms (ast *func, sym_link *functype; /* if none of them exist */ - if (!defParm && !actParm) + if (!defParm && !*actParm) return 0; if (defParm) @@ -687,27 +687,27 @@ processParms (ast *func, /* if defined parameters ended but actual parameters */ /* exist and this is not defined as a variable arg */ - if (!defParm && actParm && !IFFUNC_HASVARARGS(functype)) + if (!defParm && *actParm && !IFFUNC_HASVARARGS(functype)) { werror (E_TOO_MANY_PARMS); return 1; } /* if defined parameters present but no actual parameters */ - if (defParm && !actParm) + if (defParm && !*actParm) { werror (E_TOO_FEW_PARMS); return 1; } /* if this is a PARAM node then match left & right */ - if (actParm->type == EX_OP && actParm->opval.op == PARAM) + if ((*actParm)->type == EX_OP && (*actParm)->opval.op == PARAM) { - actParm->decorated = 1; + (*actParm)->decorated = 1; return (processParms (func, defParm, - actParm->left, parmNumber, FALSE) || + &(*actParm)->left, parmNumber, FALSE) || processParms (func, defParm ? defParm->next : NULL, - actParm->right, parmNumber, rightmost)); + &(*actParm)->right, parmNumber, rightmost)); } else if (defParm) /* not vararg */ { @@ -727,28 +727,28 @@ processParms (ast *func, /* decorate parameter */ resultType = defParm ? getResultTypeFromType (defParm->etype) : RESULT_TYPE_NONE; - actParm = decorateType (actParm, resultType); + *actParm = decorateType (*actParm, resultType); - if (IS_VOID(actParm->ftype)) + if (IS_VOID((*actParm)->ftype)) { werror (E_VOID_VALUE_USED); return 1; } /* If this is a varargs function... */ - if (!defParm && actParm && IFFUNC_HASVARARGS(functype)) + if (!defParm && *actParm && IFFUNC_HASVARARGS(functype)) { ast *newType = NULL; sym_link *ftype; - if (IS_CAST_OP (actParm) - || (IS_AST_LIT_VALUE (actParm) && actParm->values.literalFromCast)) + if (IS_CAST_OP (*actParm) + || (IS_AST_LIT_VALUE (*actParm) && (*actParm)->values.literalFromCast)) { /* Parameter was explicitly typecast; don't touch it. */ return 0; } - ftype = actParm->ftype; + ftype = (*actParm)->ftype; /* If it's a char, upcast to int. */ if (IS_INTEGRAL (ftype) @@ -772,55 +772,55 @@ processParms (ast *func, if (newType) { /* cast required; change this op to a cast. */ - ast *parmCopy = resolveSymbols (copyAst (actParm)); + 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); + (*actParm)->type = EX_OP; + (*actParm)->opval.op = CAST; + (*actParm)->left = newType; + (*actParm)->right = parmCopy; + (*actParm)->decorated = 0; /* force typechecking */ + decorateType (*actParm, RESULT_TYPE_NONE); } return 0; } /* vararg */ /* if defined parameters ended but actual has not & */ /* reentrant */ - if (!defParm && actParm && + if (!defParm && *actParm && (options.stackAuto || IFFUNC_ISREENT (functype))) return 0; - resolveSymbols (actParm); + resolveSymbols (*actParm); /* the parameter type must be at least castable */ - if (compareType (defParm->type, actParm->ftype) == 0) + if (compareType (defParm->type, (*actParm)->ftype) == 0) { werror (E_INCOMPAT_TYPES); - printFromToType (actParm->ftype, defParm->type); + printFromToType ((*actParm)->ftype, defParm->type); return 1; } /* if the parameter is castable then add the cast */ - if (compareType (defParm->type, actParm->ftype) < 0) + if (compareType (defParm->type, (*actParm)->ftype) < 0) { ast *pTree; resultType = getResultTypeFromType (defParm->etype); - pTree = resolveSymbols (copyAst (actParm)); + pTree = resolveSymbols (copyAst (*actParm)); /* now change the current one to a cast */ - actParm->type = EX_OP; - actParm->opval.op = CAST; - actParm->left = newAst_LINK (defParm->type); - actParm->right = pTree; - actParm->decorated = 0; /* force typechecking */ - decorateType (actParm, resultType); + (*actParm)->type = EX_OP; + (*actParm)->opval.op = CAST; + (*actParm)->left = newAst_LINK (defParm->type); + (*actParm)->right = pTree; + (*actParm)->decorated = 0; /* force typechecking */ + decorateType (*actParm, resultType); } /* make a copy and change the regparm type to the defined parm */ - actParm->etype = getSpec (actParm->ftype = copyLinkChain (actParm->ftype)); - SPEC_REGPARM (actParm->etype) = SPEC_REGPARM (defParm->etype); - SPEC_ARGREG (actParm->etype) = SPEC_ARGREG (defParm->etype); + (*actParm)->etype = getSpec ((*actParm)->ftype = copyLinkChain ((*actParm)->ftype)); + SPEC_REGPARM ((*actParm)->etype) = SPEC_REGPARM (defParm->etype); + SPEC_ARGREG ((*actParm)->etype) = SPEC_ARGREG (defParm->etype); (*parmNumber)++; return 0; } @@ -4128,7 +4128,7 @@ decorateType (ast * tree, RESULT_TYPE resultType) functype = LTYPE (tree); if (processParms (tree->left, FUNC_ARGS(functype), - tree->right, &parmNumber, TRUE)) { + &tree->right, &parmNumber, TRUE)) { goto errorTreeReturn; } diff --git a/src/SDCCast.h b/src/SDCCast.h index d46ad5f1..8cc1a4e1 100644 --- a/src/SDCCast.h +++ b/src/SDCCast.h @@ -111,7 +111,7 @@ ast; /* easy access macros */ -#define IS_AST_OP(x) (x && x->type == EX_OP) +#define IS_AST_OP(x) ((x) && (x)->type == EX_OP) #define IS_CALLOP(x) (IS_AST_OP(x) && x->opval.op == CALL) #define IS_BITOR(x) (IS_AST_OP(x) && x->opval.op == '|') #define IS_BITAND(x) (IS_AST_OP(x) && x->opval.op == '&' && \ @@ -119,7 +119,7 @@ ast; #define IS_FOR_STMT(x) (IS_AST_OP(x) && x->opval.op == FOR) #define IS_LEFT_OP(x) (IS_AST_OP(x) && x->opval.op == LEFT_OP) #define IS_RIGHT_OP(x) (IS_AST_OP(x) && x->opval.op == RIGHT_OP) -#define IS_AST_VALUE(x) (x && x->type == EX_VALUE && x->opval.val) +#define IS_AST_VALUE(x) ((x) && (x)->type == EX_VALUE && (x)->opval.val) #define IS_AST_LINK(x) (x->type == EX_LINK) #define IS_AST_NOT_OPER(x) (x && IS_AST_OP(x) && x->opval.op == '!') #define IS_ARRAY_OP(x) (IS_AST_OP(x) && x->opval.op == '[') @@ -130,14 +130,14 @@ ast; x->opval.op == GE_OP || \ x->opval.op == EQ_OP || \ x->opval.op == NE_OP )) -#define IS_CAST_OP(x) (IS_AST_OP(x) && x->opval.op == CAST) +#define IS_CAST_OP(x) (IS_AST_OP(x) && (x)->opval.op == CAST) #define IS_TERNARY_OP(x) (IS_AST_OP(x) && x->opval.op == '?') #define IS_COLON_OP(x) (IS_AST_OP(x) && x->opval.op == ':') #define IS_ADDRESS_OF_OP(x) (IS_AST_OP(x) && \ x->opval.op == '&' && \ x->right == NULL ) #define IS_AST_LIT_VALUE(x) (IS_AST_VALUE(x) && \ - IS_LITERAL(x->opval.val->etype)) + IS_LITERAL((x)->opval.val->etype)) #define IS_AST_SYM_VALUE(x) (IS_AST_VALUE(x) && x->opval.val->sym) #define AST_LIT_VALUE(x) (floatFromVal(x->opval.val)) #define AST_SYMBOL(x) (x->opval.val->sym) diff --git a/support/regression/tests/bug-920866.c b/support/regression/tests/bug-920866.c new file mode 100644 index 00000000..3b15a726 --- /dev/null +++ b/support/regression/tests/bug-920866.c @@ -0,0 +1,15 @@ +/* replace optimized parameter tree returned by decorateType */ + +#include + +char +foo(char c) +{ + return c; +} + +void +testReplaceParameterTree(void) +{ + ASSERT(foo (0 ? 1 : 2) == 2); +}