From adda28f5c5ce8de5a7a778723361b36545dcf92e Mon Sep 17 00:00:00 2001 From: Jesse Rosenstock Date: Sun, 2 Aug 2020 09:03:21 +0200 Subject: [PATCH] LoadExpr: Set CF_FORCECHAR if test is required If we are testing, we do not need to load the high byte(s). --- src/cc65/loadexpr.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/cc65/loadexpr.c b/src/cc65/loadexpr.c index 15be997df..1a6e43779 100644 --- a/src/cc65/loadexpr.c +++ b/src/cc65/loadexpr.c @@ -127,12 +127,19 @@ void LoadExpr (unsigned Flags, struct ExprDesc* Expr) Flags |= TypeOf (Expr->Type); } - /* Setting CF_TEST will cause the load to perform optimizations and not actually load all - ** bits of the bit-field, instead just computing the condition codes. Therefore, if - ** adjustment is required, we do not set CF_TEST here, but handle it below. - */ - if (ED_NeedsTest (Expr) && !AdjustBitField) { - Flags |= CF_TEST; + if (ED_NeedsTest (Expr)) { + /* If we're only testing, we do not need to promote char to int. + ** CF_FORCECHAR does nothing if the type is not CF_CHAR. + */ + Flags |= CF_FORCECHAR; + + /* Setting CF_TEST will cause the load to perform optimizations and not actually load + ** all bits of the bit-field, instead just computing the condition codes. Therefore, + ** if adjustment is required, we do not set CF_TEST here, but handle it below. + */ + if (!AdjustBitField) { + Flags |= CF_TEST; + } } /* Load the content of Expr */ @@ -206,7 +213,6 @@ void LoadExpr (unsigned Flags, struct ExprDesc* Expr) if (AdjustBitField) { /* If the field was loaded as a char, force the shift/mask ops to be char ops. ** If it is a char, the load has already put 0 in the upper byte, so that can remain. - ** CF_FORCECHAR does nothing if the type is not CF_CHAR. */ unsigned F = Flags | CF_FORCECHAR | CF_CONST;