summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
authorOri Bernstein <orib@google.com>2012-08-02 18:25:56 -0400
committerOri Bernstein <orib@google.com>2012-08-02 18:25:56 -0400
commitc7606d65d33f37e853755930e5559c7c4aa4a554 (patch)
tree9ec97a4229e4024a666a1fa05720dd14f85f8991 /6
parenta61e4d3a951e7f1833de4ac8a9b16aa15439a35a (diff)
downloadmc-c7606d65d33f37e853755930e5559c7c4aa4a554.tar.gz
Don't put in a bogus offset when casting slices.
How did this EVER work?
Diffstat (limited to '6')
-rw-r--r--6/simp.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/6/simp.c b/6/simp.c
index bb84f94..cbdee1e 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -626,21 +626,27 @@ static Node *idxaddr(Simp *s, Node *n)
static Node *slicebase(Simp *s, Node *n, Node *off)
{
Node *t, *u, *v;
+ Type *ty;
int sz;
t = rval(s, n, NULL);
u = NULL;
- switch (exprtype(n)->type) {
+ ty = tybase(exprtype(n));
+ switch (ty->type) {
case Typtr: u = n; break;
case Tyarray: u = addr(t, base(exprtype(n))); break;
case Tyslice: u = load(addr(t, mktyptr(n->line, 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 */
- off = ptrsized(s, off);
- sz = tysize(n->expr.type->sub[0]);
- v = mul(off, disp(n->line, sz));
- return add(u, v);
+ if (off) {
+ off = ptrsized(s, off);
+ sz = tysize(n->expr.type->sub[0]);
+ v = mul(off, disp(n->line, sz));
+ return add(u, v);
+ } else {
+ return u;
+ }
}
static Node *slicelen(Simp *s, Node *sl)
@@ -713,7 +719,6 @@ static Node *simpslice(Simp *s, Node *n, Node *dst)
static Node *simpcast(Simp *s, Node *val, Type *to)
{
- Node *sz;
Node *r;
Type *t;
int issigned;
@@ -733,9 +738,7 @@ static Node *simpcast(Simp *s, Node *val, Type *to)
if (t->type == Typtr)
fatal(val->line, "Bad cast from %s to %s",
tystr(exprtype(val)), tystr(to));
- sz = mkintlit(val->line, Ptrsz);
- sz->expr.type = exprtype(val);
- r = slicebase(s, val, sz);
+ r = slicebase(s, val, NULL);
break;
case Tyint8: case Tyint16: case Tyint32: case Tyint64:
case Tyint: case Tylong: