1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-15 17:30:06 +00:00

Merge pull request #1439 from acqn/CConvFix

[cc65] Issue #1438 fix
This commit is contained in:
Oliver Schmidt 2021-03-27 01:33:07 +01:00 committed by GitHub
commit 1bd04e8462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 25 deletions

View File

@ -493,17 +493,14 @@ fncls_t GetFuncInfo (const char* Name, unsigned int* Use, unsigned int* Chg)
** registers.
*/
*Use = REG_EAXY;
} else if ((D->ParamCount > 0 ||
(D->Flags & FD_EMPTY) != 0) &&
(AutoCDecl ?
IsQualFastcall (E->Type) :
!IsQualCDecl (E->Type))) {
} else if ((D->ParamCount > 0 || (D->Flags & FD_EMPTY) != 0) &&
IsFastcallFunc (E->Type)) {
/* Will use registers depending on the last param. If the last
** param has incomplete type, or if the function has not been
** prototyped yet, just assume __EAX__.
*/
if (D->LastParam != 0) {
switch (SizeOf(D->LastParam->Type)) {
switch (SizeOf (D->LastParam->Type)) {
case 1u:
*Use = REG_A;
break;

View File

@ -1085,11 +1085,26 @@ int HasUnknownSize (const Type* T)
int IsVariadicFunc (const Type* T)
/* Return true if this is a function type or pointer to function type with
** variable parameter list
** variable parameter list.
** Check fails if the type is not a function or a pointer to function.
*/
{
FuncDesc* F = GetFuncDesc (T);
return (F->Flags & FD_VARIADIC) != 0;
return (GetFuncDesc (T)->Flags & FD_VARIADIC) != 0;
}
int IsFastcallFunc (const Type* T)
/* Return true if this is a function type or pointer to function type by
** __fastcall__ calling convention.
** Check fails if the type is not a function or a pointer to function.
*/
{
if (UnqualifiedType (T->C) == T_PTR) {
/* Pointer to function */
++T;
}
return !IsVariadicFunc (T) && (AutoCDecl ? IsQualFastcall (T) : !IsQualCDecl (T));
}

View File

@ -825,7 +825,14 @@ INLINE int IsQualCConv (const Type* T)
int IsVariadicFunc (const Type* T) attribute ((const));
/* Return true if this is a function type or pointer to function type with
** variable parameter list
** variable parameter list.
** Check fails if the type is not a function or a pointer to function.
*/
int IsFastcallFunc (const Type* T) attribute ((const));
/* Return true if this is a function type or pointer to function type by
** __fastcall__ calling convention.
** Check fails if the type is not a function or a pointer to function.
*/
FuncDesc* GetFuncDesc (const Type* T) attribute ((const));

View File

@ -835,7 +835,7 @@ static unsigned FunctionParamList (FuncDesc* Func, int IsFastcall, ExprDesc* ED)
/* Append last deferred inc/dec before the function is called.
** The last parameter needs to be preserved if it is passed in AX/EAX Regs.
*/
DoDeferred (IsFastcall ? SQP_KEEP_EAX : SQP_KEEP_NONE, &Expr);
DoDeferred (IsFastcall && PushedCount > 0 ? SQP_KEEP_EAX : SQP_KEEP_NONE, &Expr);
/* Check if we had enough arguments */
if (PushedCount < Func->ParamCount) {
@ -863,7 +863,7 @@ static void FunctionCall (ExprDesc* Expr)
unsigned ParamSize; /* Number of parameter bytes */
CodeMark Mark;
int PtrOffs = 0; /* Offset of function pointer on stack */
int IsFastcall = 0; /* True if it's a fast-call function */
int IsFastcall = 0; /* True if we are fast-calling the function */
int PtrOnStack = 0; /* True if a pointer copy is on stack */
Type* ReturnType;
@ -882,11 +882,8 @@ static void FunctionCall (ExprDesc* Expr)
** parameter count is zero. Handle K & R functions as though there are
** parameters.
*/
IsFastcall = (Func->Flags & FD_VARIADIC) == 0 &&
(Func->ParamCount > 0 || (Func->Flags & FD_EMPTY)) &&
(AutoCDecl ?
IsQualFastcall (Expr->Type + 1) :
!IsQualCDecl (Expr->Type + 1));
IsFastcall = (Func->ParamCount > 0 || (Func->Flags & FD_EMPTY) != 0) &&
IsFastcallFunc (Expr->Type + 1);
/* Things may be difficult, depending on where the function pointer
** resides. If the function pointer is an expression of some sort
@ -931,10 +928,8 @@ static void FunctionCall (ExprDesc* Expr)
}
/* If we didn't inline the function, get fastcall info */
IsFastcall = (Func->Flags & FD_VARIADIC) == 0 &&
(AutoCDecl ?
IsQualFastcall (Expr->Type) :
!IsQualCDecl (Expr->Type));
IsFastcall = (Func->ParamCount > 0 || (Func->Flags & FD_EMPTY) != 0) &&
IsFastcallFunc (Expr->Type);
}
/* Parse the parameter list */

View File

@ -558,10 +558,7 @@ void NewFunc (SymEntry* Func, FuncDesc* D)
PushLiteralPool (Func);
/* If this is a fastcall function, push the last parameter onto the stack */
if ((D->Flags & FD_VARIADIC) == 0 && D->ParamCount > 0 &&
(AutoCDecl ?
IsQualFastcall (Func->Type) :
!IsQualCDecl (Func->Type))) {
if (D->ParamCount > 0 && IsFastcallFunc (Func->Type)) {
unsigned Flags;
/* Generate the push */