1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-22 12:30:41 +00:00

Fixed a type conversion bug

git-svn-id: svn://svn.cc65.org/cc65/trunk@2419 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2003-08-27 19:40:40 +00:00
parent fe37c38972
commit 7989e202a6

View File

@ -474,7 +474,7 @@ static unsigned FunctionParamList (FuncDesc* Func)
* The function returns the size of the parameters pushed. * The function returns the size of the parameters pushed.
*/ */
{ {
ExprDesc lval; ExprDesc Expr;
/* Initialize variables */ /* Initialize variables */
SymEntry* Param = 0; /* Keep gcc silent */ SymEntry* Param = 0; /* Keep gcc silent */
@ -520,8 +520,8 @@ static unsigned FunctionParamList (FuncDesc* Func)
/* Parse the actual parameter list */ /* Parse the actual parameter list */
while (CurTok.Tok != TOK_RPAREN) { while (CurTok.Tok != TOK_RPAREN) {
unsigned CFlags;
unsigned Flags; unsigned Flags;
int k;
/* Count arguments */ /* Count arguments */
++ParamCount; ++ParamCount;
@ -556,43 +556,29 @@ static unsigned FunctionParamList (FuncDesc* Func)
Ellipsis = 1; Ellipsis = 1;
} }
/* Do some optimization: If we have a constant value to push, /* Evaluate the parameter expression */
* use a special function that may optimize. k = hie1 (InitExprDesc (&Expr));
*/
CFlags = CF_NONE;
if (!Ellipsis && CheckedSizeOf (Param->Type) == 1) {
CFlags = CF_FORCECHAR;
}
Flags = CF_NONE;
if (evalexpr (CFlags, hie1, &lval) == 0) {
/* A constant value */
Flags |= CF_CONST;
}
/* If we don't have an argument spec, accept anything, otherwise /* If we don't have an argument spec, accept anything, otherwise
* convert the actual argument to the type needed. * convert the actual argument to the type needed.
*/ */
Flags = CF_NONE;
if (!Ellipsis) { if (!Ellipsis) {
/* Convert the argument to the parameter type if needed */ /* Convert the argument to the parameter type if needed */
TypeConversion (&lval, 0, Param->Type); k = TypeConversion (&Expr, k, Param->Type);
/* If we have a prototype, chars may be pushed as chars */ /* If we have a prototype, chars may be pushed as chars */
Flags |= CF_FORCECHAR; Flags |= CF_FORCECHAR;
} }
/* Load the value into the primary if it is not already there */
exprhs (Flags, k, &Expr);
/* Use the type of the argument for the push */ /* Use the type of the argument for the push */
Flags |= TypeOf (lval.Type); Flags |= TypeOf (Expr.Type);
/* If this is a fastcall function, don't push the last argument */ /* If this is a fastcall function, don't push the last argument */
if (ParamCount == Func->ParamCount && (Func->Flags & FD_FASTCALL) != 0) { if (ParamCount != Func->ParamCount || (Func->Flags & FD_FASTCALL) == 0) {
/* Just load the argument into the primary. This is only needed if
* we have a constant argument, otherwise the value is already in
* the primary.
*/
if (Flags & CF_CONST) {
exprhs (CF_FORCECHAR, 0, &lval);
}
} else {
unsigned ArgSize = sizeofarg (Flags); unsigned ArgSize = sizeofarg (Flags);
if (FrameSize > 0) { if (FrameSize > 0) {
/* We have the space already allocated, store in the frame. /* We have the space already allocated, store in the frame.
@ -608,10 +594,10 @@ static unsigned FunctionParamList (FuncDesc* Func)
} }
FrameOffs -= ArgSize; FrameOffs -= ArgSize;
/* Store */ /* Store */
g_putlocal (Flags | CF_NOKEEP, FrameOffs, lval.ConstVal); g_putlocal (Flags | CF_NOKEEP, FrameOffs, Expr.ConstVal);
} else { } else {
/* Push the argument */ /* Push the argument */
g_push (Flags, lval.ConstVal); g_push (Flags, Expr.ConstVal);
} }
/* Calculate total parameter size */ /* Calculate total parameter size */