shithub: mc

Download patch

ref: d4652ead0e6be99b889228f76caa4bb1c3ba62d8
parent: cb4e2d4b69b663b99271bd4b29efceb873603f53
author: Ori Bernstein <[email protected]>
date: Mon Jun 11 10:29:09 EDT 2012

Make the CFG correct.

    Explitly insert out jumps where we expect fallthroughs.

--- a/opt/df.c
+++ b/opt/df.c
@@ -63,6 +63,12 @@
     for (i = 0; i < nn; i++) {
         switch (nl[i]->type) {
             case Nlbl:
+                /* if the current block assumes fall-through, insert an explicit
+                 * jump */
+                if (i > 0 && nl[i - 1]->type == Nexpr) {
+                    if (exprop(nl[i - 1]) != Ocjmp && exprop(nl[i - 1]) != Ojmp)
+                        addnode(cfg, bb, mkexpr(-1, Ojmp, mklbl(-1, nl[i]->lbl.name), NULL));
+                }
                 if (bb->nnl)
                     bb = mkbb(cfg);
                 label(cfg, nl[i], bb);
@@ -130,9 +136,10 @@
         fprintf(fd, "In:  ");
         sep = "";
         for (i = 0; i < bsmax(bb->in); i++) {
-             if (bshas(bb->in, i))
-                fprintf(fd, "%d%s", i, sep);
-             sep = ",";
+            if (bshas(bb->in, i)) {
+                fprintf(fd, "%s%d", sep, i);
+                sep = ",";
+            }
         }
         fprintf(fd, "\n");
 
@@ -141,7 +148,7 @@
         sep = "";
         for (i = 0; i < bsmax(bb->out); i++) {
              if (bshas(bb->out, i)) {
-                fprintf(fd, "%d%s", i, sep);
+                fprintf(fd, "%s%d", sep, i);
                 sep = ",";
              }
         }