]> git.sur5r.net Git - cc65/blobdiff - src/cc65/coptstop.c
The check for illegal storage classes on globals was wrong
[cc65] / src / cc65 / coptstop.c
index c632fd5fe42d6d3b7dc9042e95d8d90cd5897dd0..5a512cb206c202348dae6d746da32fce0e384dda 100644 (file)
@@ -208,8 +208,12 @@ static void CheckDirectOp (StackOpData* D)
         if (E->AM == AM65_IMM || E->AM == AM65_ZP || E->AM == AM65_ABS) {
             /* These insns are all ok and replaceable */
             D->Flags |= OP_DIRECT;
-        } else if (E->AM == AM65_ZP_INDY && RegValIsKnown (E->RI->In.RegY)) {
-            /* Load indirect with known offset is also ok */
+        } else if (E->AM == AM65_ZP_INDY && RegValIsKnown (E->RI->In.RegY) &&
+                   strcmp (E->Arg, D->ZPLo) != 0 && strcmp (E->Arg, D->ZPHi) != 0) {
+            /* Load indirect with known offset is also ok, provided that
+             * the zeropage location used is not the same as the one we're
+             * using for the temp storage.
+             */
             D->Flags |= (OP_DIRECT | OP_RELOAD_Y);
         }
     }
@@ -707,8 +711,16 @@ unsigned OptStackOps (CodeSeg* S)
        /* Handling depends if we're inside a sequence or not */
        if (InSeq) {
 
-                   if (((E->Use & REG_SP) != 0 &&
-                (E->AM != AM65_ZP_INDY || RegValIsUnknown (E->RI->In.RegY)))) {
+            /* If we are using the stack, and we don't have "indirect Y"
+             * addressing mode, or the value of Y is unknown, or less than
+             * two, we cannot cope with this piece of code. Having an unknown
+             * value of Y means that we cannot correct the stack offset, while
+             * having an offset less than two means that the code works with
+             * the value on stack which is to be removed.
+             */
+                   if ((E->Use & REG_SP) != 0 &&
+               (E->AM != AM65_ZP_INDY || RegValIsUnknown (E->RI->In.RegY) ||
+                 E->RI->In.RegY < 2)) {
 
                /* All this stuff is not allowed in a sequence */
                InSeq = 0;