From: uz Date: Mon, 31 Aug 2009 15:11:32 +0000 (+0000) Subject: Improved code for bit fields. X-Git-Tag: V2.13.0rc1~159 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7983009e0655547bf85fd47430c6fbcc2dbdda40;p=cc65 Improved code for bit fields. git-svn-id: svn://svn.cc65.org/cc65/trunk@4097 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/loadexpr.c b/src/cc65/loadexpr.c index 8e7f83b76..fd09a4d7f 100644 --- a/src/cc65/loadexpr.c +++ b/src/cc65/loadexpr.c @@ -95,8 +95,16 @@ void LoadExpr (unsigned Flags, struct ExprDesc* Expr) { if (ED_IsLVal (Expr)) { - /* Dereferenced lvalue */ - Flags |= TypeOf (Expr->Type); + /* Dereferenced lvalue. If this is a bit field its type is unsigned. + * But if the field is completely contained in the lower byte, we will + * throw away the high byte anyway and may therefore load just the + * low byte. + */ + if (ED_IsBitField (Expr) && Expr->BitOffs + Expr->BitWidth <= CHAR_BITS) { + Flags |= CF_CHAR | CF_UNSIGNED; + } else { + Flags |= TypeOf (Expr->Type); + } if (ED_NeedsTest (Expr)) { Flags |= CF_TEST; }