+2003-08-16 Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
+ Fixed bug #748310 (pointer to function type mishandled when the
+ function name is omitted). Also fixed a SIGSEGV when a function
+ attribute (reentrant, etc) is used on a non-function or on a
+ function but misplaced before the parameter list.
+
+ * src/SDCC.y (abstract_declarator, abstract_declaractor2): fixed
+ bug #748310
+ * src/SDCC.y (declarator2_function_attributes): avoided SIGSEGV
+ * support/Util/SDCCerr.h,
+ * support/Util/SDCCerr.c: Added func attr misuse error msg
+
2003-08-13 Bernhard Held <bernhard@bernhardheld.de>
Fixed bug #787649 by anonymous
declarator2_function_attributes
: declarator2 { $$ = $1 ; }
| declarator2 function_attribute {
- // copy the functionAttributes (not the args and hasVargs !!)
- sym_link *funcType=$1->etype;
- struct value *args=FUNC_ARGS(funcType);
- unsigned hasVargs=FUNC_HASVARARGS(funcType);
-
- memcpy (&funcType->funcAttrs, &$2->funcAttrs,
- sizeof($2->funcAttrs));
-
- FUNC_ARGS(funcType)=args;
- FUNC_HASVARARGS(funcType)=hasVargs;
-
- // just to be sure
- memset (&$2->funcAttrs, 0,
- sizeof($2->funcAttrs));
-
- addDecl ($1,0,$2);
+ if ((! $1) || (! IS_FUNC($1->etype)))
+ {
+ // function_attribute is only allowed if declarator2 was
+ // an actual function
+ werror(E_FUNC_ATTR);
+ $$=$1;
+ }
+ else
+ {
+ // copy the functionAttributes (not the args and hasVargs !!)
+ sym_link *funcType=$1->etype;
+ struct value *args=FUNC_ARGS(funcType);
+ unsigned hasVargs=FUNC_HASVARARGS(funcType);
+
+ memcpy (&funcType->funcAttrs, &$2->funcAttrs,
+ sizeof($2->funcAttrs));
+
+ FUNC_ARGS(funcType)=args;
+ FUNC_HASVARARGS(funcType)=hasVargs;
+
+ // just to be sure
+ memset (&$2->funcAttrs, 0,
+ sizeof($2->funcAttrs));
+
+ addDecl ($1,0,$2);
+ }
}
;
abstract_declarator
: pointer { $$ = reverseLink($1); }
| abstract_declarator2
- | pointer abstract_declarator2 { $1 = reverseLink($1); $1->next = $2 ; $$ = $1;}
+ | pointer abstract_declarator2 { $1 = reverseLink($1); $1->next = $2 ; $$ = $1;
+ if (IS_PTR($1) && IS_FUNC($2))
+ DCL_TYPE($1) = CPOINTER;
+ }
;
abstract_declarator2
}
$1->next=p;
}
- | abstract_declarator2 '(' parameter_type_list ')' {
- if (!IS_VOID($3->etype)) {
- // this is nonsense, so let's just burp something
- werror(E_TOO_FEW_PARMS);
- } else {
- // $1 must be a pointer to a function
+ | abstract_declarator2 '(' { NestLevel++ ; currBlockno++; } parameter_type_list ')' {
sym_link *p=newLink(DECLARATOR);
DCL_TYPE(p) = FUNCTION;
- if (!$1) {
- // ((void (code *) (void)) 0) ()
- $1=newLink(DECLARATOR);
- DCL_TYPE($1)=CPOINTER;
- $$ = $1;
- }
- $1->next=p;
- }
+
+ 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;
+
+ // remove the symbol args (if any)
+ cleanUpLevel(SymbolTab,NestLevel+1);
}
;