ref: 4c23b2a4324da13e2f6027a4f53107a46568373b
parent: 2bf74b8f25a89c8a49e96e5e44ffd72f495e4930
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Jan 27 09:16:08 EST 2016
Literal zero slices should have the base be null.
--- a/6/simp.c
+++ b/6/simp.c
@@ -757,8 +757,8 @@
ty = tybase(exprtype(n));
switch (ty->type) {
case Typtr: u = n; break;
- case Tyarray: u = addr(s, n, base(exprtype(n))); break;
case Tyslice: u = load(addr(s, n, mktyptr(n->loc, base(exprtype(n))))); break;
+ case Tyarray: u = addr(s, n, base(exprtype(n))); break;
default: die("Unslicable type %s", tystr(n->expr.type));
}
/* safe: all types we allow here have a sub[0] that we want to grab */
@@ -941,7 +941,7 @@
static Node *simpslice(Simp *s, Node *n, Node *dst)
{
Node *t;
- Node *start, *end;
+ Node *start, *end, *arg;
Node *seq, *base, *sz, *len, *max;
Node *stbase, *stlen;
@@ -949,9 +949,16 @@
t = dst;
else
t = temp(s, n);
- seq = rval(s, n->expr.args[0], NULL);
- /* *(&slice) = (void*)base + off*sz */
- base = slicebase(s, seq, n->expr.args[1]);
+ arg = n->expr.args[0];
+ if (exprop(arg) == Oarr && arg->expr.nargs == 0) {
+ seq = arg;
+ base = mkintlit(n->loc, 0);
+ base->expr.type = tyintptr;
+ } else {
+ /* *(&slice) = (void*)base + off*sz */
+ seq = rval(s, arg, NULL);
+ base = slicebase(s, seq, n->expr.args[1]);
+ }
start = ptrsized(s, rval(s, n->expr.args[1], NULL));
end = ptrsized(s, rval(s, n->expr.args[2], NULL));
len = sub(end, start);