From f5ca779b9b0049504ddf2ffb7bb41b4495438aae Mon Sep 17 00:00:00 2001 From: uz Date: Mon, 7 Sep 2009 14:22:27 +0000 Subject: [PATCH 1/1] A constant right side does not necessarily mean that no code is generated for the right side. The expression may have had side effects. This error is also found in several other places. git-svn-id: svn://svn.cc65.org/cc65/trunk@4129 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/assignment.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cc65/assignment.c b/src/cc65/assignment.c index eed097272..0cdf2772d 100644 --- a/src/cc65/assignment.c +++ b/src/cc65/assignment.c @@ -163,6 +163,8 @@ void Assignment (ExprDesc* Expr) CodeMark AndPos; CodeMark PushPos; + CodeMark RhsPos; + CodeMark RhsEndPos; unsigned Mask; unsigned Flags; @@ -194,15 +196,20 @@ void Assignment (ExprDesc* Expr) g_push (Flags, 0); /* Read the expression on the right side of the '=' */ + GetCodePos (&RhsPos); hie1 (&Expr2); + GetCodePos (&RhsEndPos); /* Do type conversion if necessary. Beware: Do not use char type * here! */ TypeConversion (&Expr2, ltype); - /* Special treatment if the value is constant */ - if (ED_IsConstAbsInt (&Expr2)) { + /* Special treatment if the value is constant. */ + /* Beware: Expr2 may contain side effects, so there must not be + * code generated for Expr2. + */ + if (ED_IsConstAbsInt (&Expr2) && CodeRangeIsEmpty (&RhsPos, &RhsEndPos)) { /* Get the value and apply the mask */ unsigned Val = (unsigned) (Expr2.IVal & Mask); -- 2.39.5