shithub: mc

Download patch

ref: bf903ecaf5d7a182e7796acd727b54128c4ba20f
parent: 2ba584cf7da0ce23828e187cf22fcbe02d65f7cc
author: Ori Bernstein <[email protected]>
date: Wed Jul 25 19:32:21 EDT 2012

Get the rvals for the subexpressions of casts.

    We weren't actually evaluating the rhs. This is bad.

--- a/8/simp.c
+++ b/8/simp.c
@@ -686,11 +686,11 @@
                 case Tyuint8: case Tyuint16: case Tyuint32: case Tyuint64:
                 case Tyint: case Tyuint: case Tylong: case Tyulong:
                     args[0]->expr.type = n->expr.type;
-                    r = args[0];
+                    r = rval(s, args[0], NULL);
                     break;
                 case Typtr:
                     args[0]->expr.type = n->expr.type;
-                    r = args[0];
+                    r = rval(s, args[0], NULL);
                     break;
                 default:
                     fatal(n->line, "Bad cast from %s to %s",
--- a/opt/fold.c
+++ b/opt/fold.c
@@ -53,13 +53,13 @@
 
     if (!n)
         return NULL;
-    assert(n->type == Nexpr);
+    if (n->type != Nexpr)
+        return n;
+
     r = NULL;
     args = n->expr.args;
-    if (exprop(n) != Ovar && exprop(n) != Ocjmp &&
-        exprop(n) != Ojmp && exprop(n) != Olit)
-        for (i = 0; i < n->expr.nargs; i++)
-            args[i] = fold(args[i]);
+    for (i = 0; i < n->expr.nargs; i++)
+        args[i] = fold(args[i]);
     switch (exprop(n)) {
         case Ovar:
             /* FIXME: chase small consts */