From 33a75e0a7315f5dc3a5cd1bf6db2b691e655da7b Mon Sep 17 00:00:00 2001 From: acqn Date: Sat, 15 Aug 2020 06:27:11 +0800 Subject: [PATCH] Optimized parameter list checking. Fixed function type comparison between ANSI and K&R styles. --- src/cc65/declare.c | 1 + src/cc65/funcdesc.h | 3 ++- src/cc65/function.c | 10 ++++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 218ba6017..8d3e0f458 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -1753,6 +1753,7 @@ static FuncDesc* ParseFuncDecl (void) /* It is allowed to use incomplete types in function prototypes, so we ** won't always get to know the parameter sizes here and may do that later. */ + F->Flags |= FD_INCOMPLETE_PARAM; /* Leave the lexical level remembering the symbol tables */ RememberFunctionLevel (F); diff --git a/src/cc65/funcdesc.h b/src/cc65/funcdesc.h index 1cfb2bd09..423e7621f 100644 --- a/src/cc65/funcdesc.h +++ b/src/cc65/funcdesc.h @@ -49,13 +49,14 @@ #define FD_EMPTY 0x0001U /* Function with empty param list */ #define FD_VOID_PARAM 0x0002U /* Function with a void param list */ #define FD_VARIADIC 0x0004U /* Function with variable param list */ +#define FD_INCOMPLETE_PARAM 0x0008U /* Function with param of unknown size */ #define FD_OLDSTYLE 0x0010U /* Old style (K&R) function */ #define FD_OLDSTYLE_INTRET 0x0020U /* K&R func has implicit int return */ #define FD_UNNAMED_PARAMS 0x0040U /* Function has unnamed params */ #define FD_CALL_WRAPPER 0x0080U /* This function is used as a wrapper */ /* Bits that must be ignored when comparing funcs */ -#define FD_IGNORE (FD_OLDSTYLE | FD_OLDSTYLE_INTRET | FD_UNNAMED_PARAMS | FD_CALL_WRAPPER) +#define FD_IGNORE (FD_INCOMPLETE_PARAM | FD_OLDSTYLE | FD_OLDSTYLE_INTRET | FD_UNNAMED_PARAMS | FD_CALL_WRAPPER) diff --git a/src/cc65/function.c b/src/cc65/function.c index 451efc54d..9d4f8c2f9 100644 --- a/src/cc65/function.c +++ b/src/cc65/function.c @@ -117,6 +117,11 @@ int F_CheckParamList (FuncDesc* D, int RequireAll) unsigned ParamSize = 0; unsigned IncompleteCount = 0; + /* Don't bother to check unnecessarily */ + if ((D->Flags & FD_INCOMPLETE_PARAM) == 0) { + return 1; + } + /* Assign offsets. If the function has a variable parameter list, ** there's one additional byte (the arg size). */ @@ -147,11 +152,12 @@ int F_CheckParamList (FuncDesc* D, int RequireAll) ++I; } - /* If all parameters have complete types, set the total size description - ** and return true. + /* If all parameters have complete types, set the total size description, + ** clear the FD_INCOMPLETE_PARAM flag and return true. */ if (IncompleteCount == 0) { D->ParamSize = ParamSize; + D->Flags &= ~FD_INCOMPLETE_PARAM; return 1; }