From 3e252cb4fbe0bc24530c21d473bd33f6e2f976da Mon Sep 17 00:00:00 2001 From: epetrich Date: Wed, 4 Feb 2004 06:26:03 +0000 Subject: [PATCH] * src/SDCCicode.c (geniCodeParms), * src/SDCCast.c (decorateType, processParms): support for ANSI-style function pointers, fixed function pointer bugs #861242 and #861896 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3168 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 6 ++++++ src/SDCCast.c | 36 +++++++++++++++++++++++++++++------- src/SDCCicode.c | 13 ++++++++++++- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 25c1c335..e8850ed9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-02-04 Erik Petrich + + * src/SDCCicode.c (geniCodeParms), + * src/SDCCast.c (decorateType, processParms): support for ANSI-style + function pointers, fixed function pointer bugs #861242 and #861896 + 2004-01-31 Frieder Ferlemann * device/include/c8051f000.h, diff --git a/src/SDCCast.c b/src/SDCCast.c index 559e82d5..8bf776ba 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -652,6 +652,7 @@ processParms (ast *func, bool rightmost) { RESULT_TYPE resultType; + sym_link *functype; /* if none of them exist */ if (!defParm && !actParm) @@ -667,10 +668,15 @@ processParms (ast *func, checkTypeSanity(defParm->etype, defParm->name); } + if (IS_CODEPTR (func->ftype)) + functype = func->ftype->next; + else + functype = func->ftype; + /* if the function is being called via a pointer & */ /* it has not been defined a reentrant then we cannot */ /* have parameters */ - if (func->type != EX_VALUE && !IFFUNC_ISREENT (func->ftype) && !options.stackAuto) + if (func->type != EX_VALUE && !IFFUNC_ISREENT (functype) && !options.stackAuto) { werror (W_NONRENT_ARGS); return 1; @@ -678,10 +684,8 @@ 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(func->ftype)) + if (!defParm && actParm && !IFFUNC_HASVARARGS(functype)) { - /* if (func->type==EX_VALUE && func->opval.val->sym->undefined) */ - /* return 1; *//* Already gave them an undefined function error */ werror (E_TOO_MANY_PARMS); return 1; } @@ -729,7 +733,7 @@ processParms (ast *func, } /* If this is a varargs function... */ - if (!defParm && actParm && IFFUNC_HASVARARGS(func->ftype)) + if (!defParm && actParm && IFFUNC_HASVARARGS(functype)) { ast *newType = NULL; sym_link *ftype; @@ -780,7 +784,7 @@ processParms (ast *func, /* if defined parameters ended but actual has not & */ /* reentrant */ if (!defParm && actParm && - (options.stackAuto || IFFUNC_ISREENT (func->ftype))) + (options.stackAuto || IFFUNC_ISREENT (functype))) return 0; resolveSymbols (actParm); @@ -4027,10 +4031,28 @@ decorateType (ast * tree, RESULT_TYPE resultType) /* function call */ /*----------------------------*/ case CALL: + + /* undo any explicit pointer derefernce; PCALL will handle it instead */ + if (IS_FUNC (LTYPE (tree)) && tree->left->type == EX_OP) + { + if (tree->left->opval.op == '*' && !tree->left->right) + tree->left = tree->left->left; + } + + /* require a function or pointer to function */ + if (!IS_FUNC (LTYPE (tree)) + && !(IS_CODEPTR (LTYPE (tree)) && IS_FUNC (LTYPE (tree)->next))) + { + werrorfl (tree->filename, tree->lineno, E_FUNCTION_EXPECTED); + goto errorTreeReturn; + } + parmNumber = 1; if (processParms (tree->left, - FUNC_ARGS(tree->left->ftype), + IS_CODEPTR(LTYPE(tree)) ? + FUNC_ARGS(tree->left->ftype->next) + : FUNC_ARGS(tree->left->ftype), tree->right, &parmNumber, TRUE)) { goto errorTreeReturn; } diff --git a/src/SDCCicode.c b/src/SDCCicode.c index d9ee9aa4..100c4fec 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -1932,6 +1932,14 @@ geniCodeCast (sym_link * type, operand * op, bool implicit) } /* if they are the same size create an assignment */ + + /* This seems very dangerous to me, since there are several */ + /* optimizations (for example, gcse) that don't notice the */ + /* cast hidden in this assignement and may simplify an */ + /* iCode to use the original (uncasted) operand. */ + /* Unfortunately, other things break when this cast is */ + /* made explicit. Need to fix this someday. */ + /* -- EEP, 2004/01/21 */ if (getSize (type) == getSize (optype) && !IS_BITFIELD (type) && !IS_FLOAT (type) && @@ -3040,7 +3048,10 @@ geniCodeParms (ast * parms, value *argVals, int *stack, if (argVals==NULL) { // first argument - argVals=FUNC_ARGS(func->type); + if (IS_CODEPTR(func->type)) + argVals = FUNC_ARGS (func->type->next); + else + argVals = FUNC_ARGS (func->type); } /* if this is a param node then do the left & right */ -- 2.30.2