mirror of
https://github.com/cc65/cc65.git
synced 2025-01-11 11:30:13 +00:00
Fixed result type of certain operations, which was broken with the bit-field fix.
This commit is contained in:
parent
f3db74395d
commit
25a35d6b59
@ -155,7 +155,6 @@ void DoIncDecBitField (ExprDesc* Expr, long Val, unsigned KeepResult)
|
|||||||
unsigned Mask;
|
unsigned Mask;
|
||||||
unsigned ChunkFlags;
|
unsigned ChunkFlags;
|
||||||
const Type* ChunkType;
|
const Type* ChunkType;
|
||||||
const Type* ResType;
|
|
||||||
|
|
||||||
/* If the bit-field fits within one byte, do the following operations
|
/* If the bit-field fits within one byte, do the following operations
|
||||||
** with bytes.
|
** with bytes.
|
||||||
@ -190,11 +189,6 @@ void DoIncDecBitField (ExprDesc* Expr, long Val, unsigned KeepResult)
|
|||||||
/* Fetch the lhs into the primary register if needed */
|
/* Fetch the lhs into the primary register if needed */
|
||||||
LoadExpr (CF_NONE, Expr);
|
LoadExpr (CF_NONE, Expr);
|
||||||
|
|
||||||
if (KeepResult == OA_NEED_OLD) {
|
|
||||||
/* Save the original expression value */
|
|
||||||
g_save (Flags | CF_FORCECHAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Handle for add and sub */
|
/* Handle for add and sub */
|
||||||
if (Val > 0) {
|
if (Val > 0) {
|
||||||
g_inc (Flags | CF_CONST, Val);
|
g_inc (Flags | CF_CONST, Val);
|
||||||
@ -205,11 +199,6 @@ void DoIncDecBitField (ExprDesc* Expr, long Val, unsigned KeepResult)
|
|||||||
/* Apply the mask */
|
/* Apply the mask */
|
||||||
g_and (Flags | CF_CONST, Mask);
|
g_and (Flags | CF_CONST, Mask);
|
||||||
|
|
||||||
if (KeepResult == OA_NEED_NEW) {
|
|
||||||
/* Save the result value */
|
|
||||||
g_save (Flags | CF_FORCECHAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Do integral promotion without sign-extension if needed */
|
/* Do integral promotion without sign-extension if needed */
|
||||||
g_typecast (ChunkFlags | CF_UNSIGNED, Flags);
|
g_typecast (ChunkFlags | CF_UNSIGNED, Flags);
|
||||||
|
|
||||||
@ -229,6 +218,11 @@ void DoIncDecBitField (ExprDesc* Expr, long Val, unsigned KeepResult)
|
|||||||
/* Load the whole data chunk containing the bits to be changed */
|
/* Load the whole data chunk containing the bits to be changed */
|
||||||
LoadExpr (ChunkFlags, Expr);
|
LoadExpr (ChunkFlags, Expr);
|
||||||
|
|
||||||
|
if (KeepResult == OA_NEED_OLD) {
|
||||||
|
/* Save the original expression value */
|
||||||
|
g_save (ChunkFlags | CF_FORCECHAR);
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the bits that are not to be affected */
|
/* Get the bits that are not to be affected */
|
||||||
g_and (ChunkFlags | CF_CONST, ~(Mask << Expr->Type->A.B.Offs));
|
g_and (ChunkFlags | CF_CONST, ~(Mask << Expr->Type->A.B.Offs));
|
||||||
|
|
||||||
@ -238,39 +232,10 @@ void DoIncDecBitField (ExprDesc* Expr, long Val, unsigned KeepResult)
|
|||||||
/* Store the whole data chunk containing the changed bits back */
|
/* Store the whole data chunk containing the changed bits back */
|
||||||
Store (Expr, ChunkType);
|
Store (Expr, ChunkType);
|
||||||
|
|
||||||
/* Cache the expression result type */
|
if (KeepResult == OA_NEED_OLD) {
|
||||||
ResType = IntPromotion (Expr->Type);
|
/* Restore the original expression value */
|
||||||
|
g_restore (ChunkFlags | CF_FORCECHAR);
|
||||||
if (KeepResult != OA_NEED_NONE) {
|
|
||||||
/* Restore the expression result value */
|
|
||||||
g_restore (Flags | CF_FORCECHAR);
|
|
||||||
|
|
||||||
/* Promote if needed */
|
|
||||||
if (KeepResult != OA_NEED_OLD) {
|
|
||||||
/* Do unsigned promotion first */
|
|
||||||
g_typecast (TypeOf (ResType) | CF_UNSIGNED, Flags);
|
|
||||||
|
|
||||||
/* Then do sign-extension */
|
|
||||||
if (IsSignSigned (Expr->Type) &&
|
|
||||||
Expr->Type->A.B.Width < CHAR_BITS * SizeOf (ResType)) {
|
|
||||||
/* The way is:
|
|
||||||
** x = bits & bit_mask
|
|
||||||
** m = 1 << (bit_width - 1)
|
|
||||||
** r = (x ^ m) - m
|
|
||||||
** Since we have already masked bits with bit_mask, we may skip the
|
|
||||||
** first step.
|
|
||||||
*/
|
|
||||||
g_xor (Flags | CF_CONST, 1U << (Expr->Type->A.B.Width - 1U));
|
|
||||||
g_dec ((Flags & ~CF_FORCECHAR) | CF_CONST, 1U << (Expr->Type->A.B.Width - 1U));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* Do promotion with sign-extension */
|
|
||||||
g_typecast (TypeOf (ResType), Flags);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the expression result type */
|
|
||||||
Expr->Type = ResType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -285,10 +250,6 @@ static void OpAssignBitField (const GenDesc* Gen, ExprDesc* Expr, const char* Op
|
|||||||
unsigned Flags;
|
unsigned Flags;
|
||||||
unsigned ChunkFlags;
|
unsigned ChunkFlags;
|
||||||
const Type* ChunkType;
|
const Type* ChunkType;
|
||||||
const Type* ResType;
|
|
||||||
|
|
||||||
/* Cache the expression result type */
|
|
||||||
ResType = IntPromotion (Expr->Type);
|
|
||||||
|
|
||||||
ED_Init (&Expr2);
|
ED_Init (&Expr2);
|
||||||
Expr2.Flags |= Expr->Flags & E_MASK_KEEP_SUBEXPR;
|
Expr2.Flags |= Expr->Flags & E_MASK_KEEP_SUBEXPR;
|
||||||
@ -373,15 +334,6 @@ static void OpAssignBitField (const GenDesc* Gen, ExprDesc* Expr, const char* Op
|
|||||||
/* Store the whole data chunk containing the changed bits back */
|
/* Store the whole data chunk containing the changed bits back */
|
||||||
Store (Expr, ChunkType);
|
Store (Expr, ChunkType);
|
||||||
|
|
||||||
/* Load the expression result value */
|
|
||||||
if (IsSignSigned (Expr->Type)) {
|
|
||||||
unsigned SignExtensionMask = 1 << (Expr->Type->A.B.Width - 1);
|
|
||||||
Val = (Val^ SignExtensionMask) - SignExtensionMask;
|
|
||||||
}
|
|
||||||
ED_MakeConstAbs (Expr, Val, ResType);
|
|
||||||
LimitExprValue (Expr);
|
|
||||||
LoadExpr (CF_NONE, Expr);
|
|
||||||
|
|
||||||
/* Done */
|
/* Done */
|
||||||
goto Done;
|
goto Done;
|
||||||
|
|
||||||
@ -459,9 +411,6 @@ static void OpAssignBitField (const GenDesc* Gen, ExprDesc* Expr, const char* Op
|
|||||||
/* Apply the mask */
|
/* Apply the mask */
|
||||||
g_and (Flags | CF_CONST, Mask);
|
g_and (Flags | CF_CONST, Mask);
|
||||||
|
|
||||||
/* Save the expression result value */
|
|
||||||
g_save (Flags);
|
|
||||||
|
|
||||||
/* Do integral promotion without sign-extension if needed */
|
/* Do integral promotion without sign-extension if needed */
|
||||||
g_typecast (ChunkFlags | CF_UNSIGNED, Flags);
|
g_typecast (ChunkFlags | CF_UNSIGNED, Flags);
|
||||||
|
|
||||||
@ -490,31 +439,8 @@ static void OpAssignBitField (const GenDesc* Gen, ExprDesc* Expr, const char* Op
|
|||||||
/* Store the whole data chunk containing the changed bits back */
|
/* Store the whole data chunk containing the changed bits back */
|
||||||
Store (Expr, ChunkType);
|
Store (Expr, ChunkType);
|
||||||
|
|
||||||
/* Restore the expression result value */
|
|
||||||
g_restore (Flags);
|
|
||||||
|
|
||||||
/* Do unsigned promotion first */
|
|
||||||
g_typecast (TypeOf (ResType) | CF_UNSIGNED, Flags);
|
|
||||||
|
|
||||||
/* Then do sign-extension */
|
|
||||||
if (IsSignSigned (Expr->Type) &&
|
|
||||||
Expr->Type->A.B.Width < CHAR_BITS * SizeOf (ResType)) {
|
|
||||||
/* The way is:
|
|
||||||
** x = bits & bit_mask
|
|
||||||
** m = 1 << (bit_width - 1)
|
|
||||||
** r = (x ^ m) - m
|
|
||||||
** Since we have already masked bits with bit_mask, we may skip the
|
|
||||||
** first step.
|
|
||||||
*/
|
|
||||||
g_xor (Flags | CF_CONST, 1U << (Expr->Type->A.B.Width - 1U));
|
|
||||||
g_dec ((Flags & ~CF_FORCECHAR) | CF_CONST, 1U << (Expr->Type->A.B.Width - 1U));
|
|
||||||
}
|
|
||||||
|
|
||||||
Done:
|
Done:
|
||||||
|
|
||||||
/* Get the expression result type */
|
|
||||||
Expr->Type = ResType;
|
|
||||||
|
|
||||||
/* Value is in primary as an rvalue */
|
/* Value is in primary as an rvalue */
|
||||||
ED_FinalizeRValLoad (Expr);
|
ED_FinalizeRValLoad (Expr);
|
||||||
}
|
}
|
||||||
@ -643,11 +569,6 @@ static void OpAssignArithmetic (const GenDesc* Gen, ExprDesc* Expr, const char*
|
|||||||
/* Generate a store instruction */
|
/* Generate a store instruction */
|
||||||
Store (Expr, 0);
|
Store (Expr, 0);
|
||||||
|
|
||||||
/* Get the expression result type */
|
|
||||||
if (IsClassInt (Expr->Type)) {
|
|
||||||
Expr->Type = IntPromotion (Expr->Type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Value is in primary as an rvalue */
|
/* Value is in primary as an rvalue */
|
||||||
ED_FinalizeRValLoad (Expr);
|
ED_FinalizeRValLoad (Expr);
|
||||||
}
|
}
|
||||||
@ -824,11 +745,6 @@ void OpAddSubAssign (const GenDesc* Gen, ExprDesc *Expr, const char* Op)
|
|||||||
Internal ("Invalid location in Store(): 0x%04X", ED_GetLoc (Expr));
|
Internal ("Invalid location in Store(): 0x%04X", ED_GetLoc (Expr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the expression result type */
|
|
||||||
if (IsClassInt (Expr->Type)) {
|
|
||||||
Expr->Type = IntPromotion (Expr->Type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Expression is an rvalue in the primary now */
|
/* Expression is an rvalue in the primary now */
|
||||||
ED_FinalizeRValLoad (Expr);
|
ED_FinalizeRValLoad (Expr);
|
||||||
}
|
}
|
||||||
|
@ -1726,17 +1726,12 @@ static void PostInc (ExprDesc* Expr)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Fetch the value and use it (since it's the result of the expression) */
|
|
||||||
LoadExpr (CF_NONE, Expr);
|
|
||||||
|
|
||||||
/* Defer the increment until after the value of this expression is used */
|
/* Defer the increment until after the value of this expression is used */
|
||||||
DeferInc (Expr);
|
DeferInc (Expr);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Adjust the type of the expression */
|
/* Just return */
|
||||||
if (IsClassInt (Expr->Type)) {
|
return;
|
||||||
Expr->Type = IntPromotion (Expr->Type);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The result is always an expression, no reference */
|
/* The result is always an expression, no reference */
|
||||||
@ -1781,17 +1776,12 @@ static void PostDec (ExprDesc* Expr)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Fetch the value and save it (since it's the result of the expression) */
|
|
||||||
LoadExpr (CF_NONE, Expr);
|
|
||||||
|
|
||||||
/* Defer the decrement until after the value of this expression is used */
|
/* Defer the decrement until after the value of this expression is used */
|
||||||
DeferDec (Expr);
|
DeferDec (Expr);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Adjust the type of the expression */
|
/* Just return */
|
||||||
if (IsClassInt (Expr->Type)) {
|
return;
|
||||||
Expr->Type = IntPromotion (Expr->Type);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The result is always an expression, no reference */
|
/* The result is always an expression, no reference */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user