diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index b69a44dd0..6d9afa403 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -1007,6 +1007,25 @@ const Type* PtrConversion (const Type* T) +const Type* StdConversion (const Type* T) +/* If the type is a function, convert it to pointer to function. If the +** expression is an array, convert it to pointer to first element. If the +** type is an integer, do integeral promotion. Otherwise return T. +*/ +{ + if (IsTypeFunc (T)) { + return AddressOf (T); + } else if (IsTypeArray (T)) { + return AddressOf (GetElementType (T)); + } else if (IsClassInt (T)) { + return IntPromotion (T); + } else { + return T; + } +} + + + const Type* IntPromotion (const Type* T) /* Apply the integer promotions to T and return the result. The returned type ** string may be T if there is no need to change it. diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index c60023944..e8ba7b6c0 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -368,6 +368,12 @@ const Type* PtrConversion (const Type* T); ** return T. */ +const Type* StdConversion (const Type* T); +/* If the type is a function, convert it to pointer to function. If the +** expression is an array, convert it to pointer to first element. If the +** type is an integer, do integeral promotion. Otherwise return T. +*/ + const Type* IntPromotion (const Type* T); /* Apply the integer promotions to T and return the result. The returned type ** string may be T if there is no need to change it. diff --git a/src/cc65/expr.c b/src/cc65/expr.c index dc45b108d..dc2374190 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -765,9 +765,10 @@ static unsigned FunctionArgList (FuncDesc* Func, int IsFastcall, ExprDesc* ED) } else { /* No prototype available. Convert array to "pointer to first - ** element", and function to "pointer to function". + ** element", function to "pointer to function" and do integral + ** promotion if necessary. */ - Expr.Type = PtrConversion (Expr.Type); + TypeConversion (&Expr, StdConversion (Expr.Type)); } @@ -3062,7 +3063,7 @@ static void parseadd (ExprDesc* Expr, int DoArrayRef) Error ("Invalid operands for binary operator '+'"); } else { /* Array and function types must be converted to pointer types */ - Expr->Type = PtrConversion (Expr->Type); + Expr->Type = StdConversion (Expr->Type); } } @@ -3341,7 +3342,7 @@ static void parsesub (ExprDesc* Expr) } /* Result type is either a pointer or an integer */ - Expr->Type = PtrConversion (Expr->Type); + Expr->Type = StdConversion (Expr->Type); /* Condition code not set */ ED_MarkAsUntested (Expr);