1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 07:29:33 +00:00

Merge pull request #1840 from acqn/FnParamFix

[cc65] Fixed function parameters declared as function types rather than function pointers
This commit is contained in:
Bob Andrews 2022-08-26 23:19:55 +02:00 committed by GitHub
commit d2628d5949
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 4 deletions

View File

@ -1133,10 +1133,6 @@ static void Primary (ExprDesc* E)
/* Enum or some other numeric constant */
E->Flags = E_LOC_NONE | E_RTYPE_RVAL;
E->IVal = Sym->V.ConstVal;
} else if ((Sym->Flags & SC_FUNC) == SC_FUNC) {
/* Function */
E->Flags = E_LOC_GLOBAL | E_RTYPE_LVAL;
E->Name = (uintptr_t) Sym->Name;
} else if ((Sym->Flags & SC_AUTO) == SC_AUTO) {
/* Local variable. If this is a parameter for a variadic
** function, we have to add some address calculations, and the
@ -1151,6 +1147,10 @@ static void Primary (ExprDesc* E)
E->Flags = E_LOC_STACK | E_RTYPE_LVAL;
E->IVal = Sym->V.Offs;
}
} else if ((Sym->Flags & SC_FUNC) == SC_FUNC) {
/* Function */
E->Flags = E_LOC_GLOBAL | E_RTYPE_LVAL;
E->Name = (uintptr_t) Sym->Name;
} else if ((Sym->Flags & SC_REGISTER) == SC_REGISTER) {
/* Register variable, zero page based */
E->Flags = E_LOC_REGISTER | E_RTYPE_LVAL;

35
test/val/bug1838.c Normal file
View File

@ -0,0 +1,35 @@
/* Bug 1838 - function parameters declared as function types rather than function pointers */
#include <stdio.h>
static int failures = 0;
typedef int fn_t(int);
int main(void)
{
void foo(fn_t*);
fn_t bar;
foo(bar);
return 0;
}
void foo(int func(int))
{
int n = func(42);
if (n != 12) {
printf("n = %d, expected: 12\n", n);
++failures;
}
}
int bar(int a)
{
if (a != 42) {
printf("a = %d, expected: 42\n", a);
++failures;
}
return 12;
}