From: bernhardheld Date: Fri, 27 Jan 2006 21:38:09 +0000 (+0000) Subject: * src/SDCC.y: fixed bug #716242, exchanged pointer and function declarator in the... X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=a8b6b80ff9fcad4aba5bb339e95db62f75f9eb61;p=fw%2Fsdcc * src/SDCC.y: fixed bug #716242, exchanged pointer and function declarator in the symbol chain * src/SDCCsymt.h, * src/SDCCsymt.c (processFuncPtrArgs): added, removes "(void)" parameter list for function pointers * src/SDCCast.c (decorateType): added call of processFuncPtrArgs() * support/regression/tests/bug-716242.c: added git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4024 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 61b509a7..48183fe7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-01-27 Bernhard Held + + * src/SDCC.y: fixed bug #716242, exchanged pointer and function + declarator in the symbol chain + * src/SDCCsymt.h, + * src/SDCCsymt.c (processFuncPtrArgs): added, removes "(void)" + parameter list for function pointers + * src/SDCCast.c (decorateType): added call of processFuncPtrArgs() + * support/regression/tests/bug-716242.c: added + 2006-01-20 Bernhard Held * src/SDCCicode.c (geniCodeAdd, geniCodeArray): use char for array diff --git a/src/SDCC.y b/src/SDCC.y index a81e243e..a5a0f329 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -1373,12 +1373,17 @@ abstract_declarator2 FUNC_HASVARARGS(p) = IS_VARG($4); FUNC_ARGS(p) = reverseVal($4); - + /* nest level was incremented to take care of the parms */ NestLevel-- ; currBlockno--; - p->next = $1; - $$ = p; + if (!$1) { + /* ((void (code *) (void)) 0) () */ + $1=newLink(DECLARATOR); + DCL_TYPE($1)=CPOINTER; + $$ = $1; + } + $1->next=p; // remove the symbol args (if any) cleanUpLevel(SymbolTab,NestLevel+1); diff --git a/src/SDCCast.c b/src/SDCCast.c index dcddefdb..86fad20a 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -4348,7 +4348,10 @@ decorateType (ast * tree, RESULT_TYPE resultType) parmNumber = 1; if (IS_FUNCPTR (LTYPE (tree))) - functype = LTYPE (tree)->next; + { + functype = LTYPE (tree)->next; + processFuncPtrArgs (functype); + } else functype = LTYPE (tree); diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 5cb19d06..0c0c00cc 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -2568,6 +2568,22 @@ void cdbStructBlock (int block) } } +/*-----------------------------------------------------------------*/ +/* processFuncPtrArgs - does some processing with args of func ptrs*/ +/*-----------------------------------------------------------------*/ +void +processFuncPtrArgs (sym_link * funcType) +{ + value *val = FUNC_ARGS(funcType); + + /* if it is void then remove parameters */ + if (val && IS_VOID (val->type)) + { + FUNC_ARGS(funcType) = NULL; + return; + } +} + /*-----------------------------------------------------------------*/ /* processFuncArgs - does some processing with function args */ /*-----------------------------------------------------------------*/ diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index 3699759a..dedf6e85 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -591,6 +591,7 @@ void addSymChain (symbol **); sym_link *structElemType (sym_link *, value *); symbol *getStructElement (structdef *, symbol *); sym_link *computeType (sym_link *, sym_link *, RESULT_TYPE, int); +void processFuncPtrArgs (sym_link *); void processFuncArgs (symbol *); int isSymbolEqual (symbol *, symbol *); int powof2 (TYPE_UDWORD); diff --git a/support/regression/tests/bug-716242.c b/support/regression/tests/bug-716242.c new file mode 100644 index 00000000..95f32682 --- /dev/null +++ b/support/regression/tests/bug-716242.c @@ -0,0 +1,82 @@ +/* bug-716242.c + + syntax tests about function pointers at compile time + */ +#include + +#if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80) || defined(SDCC_hc08) +# define code +#endif + +void *p; +int ret; + +int mul2 (int i) +{ + return 2 * i; +} + +void g (int (*h) (int)) +{ + ret = h (2); +} + +void f1() +{ + p = (void *) mul2; + g ((int (*) (int)) p); +} + +/****************************/ + +void g (int (*h) (int)); + +void f2() +{ + int (*fp) (int) = p; + + g (fp); +} + +/****************************/ + +void g (int (*h) (int)); + +void f3() +{ + int (*fp) (int) = (int (*) (int)) p; + + g (fp); +} + +/****************************/ + +void f4() +{ + ((void (code *) (void)) p) (); +} + +/****************************/ + +void f5() +{ + int (*fp) (int) = mul2; + + fp(1); +} + +/****************************/ + +void f6() +{ + ((void (code *) (void)) 0) (); +} + +/****************************/ + +static void +testFuncPtr(void) +{ + f1(); + ASSERT(ret == 4); +}