]> git.sur5r.net Git - cc65/blobdiff - src/cc65/assignment.c
A constant right side does not necessarily mean that no code is generated for
[cc65] / src / cc65 / assignment.c
index eed097272b4602deaa747b30ef15da9bbc7893bd..0cdf2772d1d7bb17064dc59f2f60381132459b26 100644 (file)
@@ -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);