summaryrefslogtreecommitdiff
path: root/opt
diff options
context:
space:
mode:
authorOri Bernstein <orib@google.com>2012-07-20 18:18:22 -0400
committerOri Bernstein <orib@google.com>2012-07-20 18:18:22 -0400
commite62508a51069116eeb35fee1e774794604dae8eb (patch)
tree13931809f3c00bf3d8b7b73037940fec80d8929e /opt
parentd555aa6e04f4459fd6bc5f8e1fb07f80cdc29b50 (diff)
downloadmc-e62508a51069116eeb35fee1e774794604dae8eb.tar.gz
Don't die if we call fold() on NULL.
Making it safe to call fold(NULL) is easier than adding checks wrapping all call sites.
Diffstat (limited to 'opt')
-rw-r--r--opt/fold.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/opt/fold.c b/opt/fold.c
index 0dc5dea..feabef4 100644
--- a/opt/fold.c
+++ b/opt/fold.c
@@ -50,6 +50,8 @@ Node *fold(Node *n)
vlong a, b;
size_t i;
+ if (!n)
+ return NULL;
assert(n->type == Nexpr);
r = NULL;
args = n->expr.args;
@@ -112,6 +114,12 @@ Node *fold(Node *n)
if (islit(args[0], &a))
r = val(n->line, -a);
break;
+ case Ocast:
+ /* FIXME: we currentl assume that the bits of the
+ * val are close enough. */
+ r = args[0];
+ r->expr.type = exprtype(n);
+ break;
default:
break;
}