Commit adaec0c4 authored by Ken Thompson's avatar Ken Thompson

vectors bug

R=r
OCL=15664
CL=15664
parent c14924bc
...@@ -667,21 +667,33 @@ ret: ...@@ -667,21 +667,33 @@ ret:
int32 int32
stkof(Node *n) stkof(Node *n)
{ {
Type *t;
Iter flist;
switch(n->op) { switch(n->op) {
// case OS2I:
// return 2*widthptr;
// case OI2I:
// return 1*widthptr;
case OINDREG: case OINDREG:
return n->xoffset; return n->xoffset;
case OCALLMETH:
case OCALLINTER:
case OCALL:
t = n->left->type;
if(isptr[t->etype])
t = t->type;
t = structfirst(&flist, getoutarg(t));
if(t != T)
return t->width;
break;
} }
// botch - probably failing to recognize address // botch - probably failing to recognize address
// arithmetic on the above. eg INDEX and DOT // arithmetic on the above. eg INDEX and DOT
return -1; return -1000;
} }
void void
sgen(Node *n, Node *ns, uint32 w) sgen(Node *n, Node *ns, int32 w)
{ {
Node nodl, nodr; Node nodl, nodr;
int32 c, q, odst, osrc; int32 c, q, odst, osrc;
...@@ -697,12 +709,11 @@ sgen(Node *n, Node *ns, uint32 w) ...@@ -697,12 +709,11 @@ sgen(Node *n, Node *ns, uint32 w)
} }
// offset on the stack // offset on the stack
odst = stkof(ns);
osrc = stkof(n); osrc = stkof(n);
if(osrc < 0) odst = stkof(ns);
odst = odst; //print("\nnsrc=%N\n", n);
if(odst < 0) //print("ndst=%N\n", ns);
osrc = odst; //print("osrc=%d odst=%d w=%d\n", osrc, odst, w);
nodreg(&nodl, types[tptr], D_DI); nodreg(&nodl, types[tptr], D_DI);
nodreg(&nodr, types[tptr], D_SI); nodreg(&nodr, types[tptr], D_SI);
...@@ -720,7 +731,7 @@ sgen(Node *n, Node *ns, uint32 w) ...@@ -720,7 +731,7 @@ sgen(Node *n, Node *ns, uint32 w)
// if we are copying forward on the stack and // if we are copying forward on the stack and
// the src and dst overlap, then reverse direction // the src and dst overlap, then reverse direction
if(odst > osrc && odst-osrc < w) { if(osrc < odst && odst < osrc+w) {
// reverse direction // reverse direction
gins(ASTD, N, N); // set direction flag gins(ASTD, N, N); // set direction flag
if(c > 0) { if(c > 0) {
......
...@@ -153,7 +153,7 @@ void agen(Node*, Node*); ...@@ -153,7 +153,7 @@ void agen(Node*, Node*);
void igen(Node*, Node*, Node*); void igen(Node*, Node*, Node*);
vlong fieldoffset(Type*, Node*); vlong fieldoffset(Type*, Node*);
void bgen(Node*, int, Prog*); void bgen(Node*, int, Prog*);
void sgen(Node*, Node*, uint32); void sgen(Node*, Node*, int32);
void gmove(Node*, Node*); void gmove(Node*, Node*);
Prog* gins(int, Node*, Node*); Prog* gins(int, Node*, Node*);
int samaddr(Node*, Node*); int samaddr(Node*, Node*);
......
...@@ -16,6 +16,7 @@ func printfloat(double); ...@@ -16,6 +16,7 @@ func printfloat(double);
func printint(int64); func printint(int64);
func printstring(string); func printstring(string);
func printpointer(*any); func printpointer(*any);
func printinter(any);
func catstring(string, string) string; func catstring(string, string) string;
func cmpstring(string, string) int32; func cmpstring(string, string) int32;
...@@ -24,8 +25,8 @@ func indexstring(string, int32) byte; ...@@ -24,8 +25,8 @@ func indexstring(string, int32) byte;
func intstring(int64) string; func intstring(int64) string;
func byteastring(*byte, int32) string; func byteastring(*byte, int32) string;
func ifaceT2I(sigi *byte, sigt *byte, elem any) (ret interface{}); func ifaceT2I(sigi *byte, sigt *byte, elem any) (ret any);
func ifaceI2T(sigt *byte, iface interface{}) (ret any); func ifaceI2T(sigt *byte, iface any) (ret any);
func ifaceI2I(sigi *byte, iface any) (ret any); func ifaceI2I(sigi *byte, iface any) (ret any);
func argc() int32; func argc() int32;
...@@ -90,6 +91,7 @@ export ...@@ -90,6 +91,7 @@ export
printint printint
printstring printstring
printpointer printpointer
printinter
// op string // op string
catstring catstring
......
This diff is collapsed.
...@@ -552,6 +552,7 @@ loop: ...@@ -552,6 +552,7 @@ loop:
// interface and structure // interface and structure
et = isandss(n->type, l); et = isandss(n->type, l);
if(et != Inone) { if(et != Inone) {
if(et == I2I) dump("conv", n);
indir(n, ifaceop(n->type, l, et)); indir(n, ifaceop(n->type, l, et));
goto ret; goto ret;
} }
...@@ -1626,14 +1627,19 @@ loop: ...@@ -1626,14 +1627,19 @@ loop:
default: default:
if(l->type == T) if(l->type == T)
goto out; goto out;
if(!isptr[l->type->etype]) { if(isinter(l->type)) {
badtype(n->op, l->type, T); on = syslook("printinter", 1);
l = listnext(&save); argtype(on, l->type); // any-1
goto loop; break;
} }
on = syslook("printpointer", 1); if(isptr[l->type->etype]) {
argtype(on, l->type->type); // any-1 on = syslook("printpointer", 1);
break; argtype(on, l->type->type); // any-1
break;
}
badtype(n->op, l->type, T);
l = listnext(&save);
goto loop;
case Wlitint: case Wlitint:
case Wtint: case Wtint:
...@@ -2490,7 +2496,7 @@ ifaceop(Type *tl, Node *n, int op) ...@@ -2490,7 +2496,7 @@ ifaceop(Type *tl, Node *n, int op)
fatal("ifaceop: unknown op %d\n", op); fatal("ifaceop: unknown op %d\n", op);
case I2T: case I2T:
// ifaceI2T(sigt *byte, iface interface{}) (ret any); // ifaceI2T(sigt *byte, iface any) (ret any);
a = n; // interface a = n; // interface
r = a; r = a;
...@@ -2503,12 +2509,13 @@ ifaceop(Type *tl, Node *n, int op) ...@@ -2503,12 +2509,13 @@ ifaceop(Type *tl, Node *n, int op)
r = list(a, r); r = list(a, r);
on = syslook("ifaceI2T", 1); on = syslook("ifaceI2T", 1);
argtype(on, tr);
argtype(on, tl); argtype(on, tl);
break; break;
case T2I: case T2I:
// ifaceT2I(sigi *byte, sigt *byte, elem any) (ret interface{}); // ifaceT2I(sigi *byte, sigt *byte, elem any) (ret any);
a = n; // elem a = n; // elem
r = a; r = a;
...@@ -2530,6 +2537,7 @@ ifaceop(Type *tl, Node *n, int op) ...@@ -2530,6 +2537,7 @@ ifaceop(Type *tl, Node *n, int op)
on = syslook("ifaceT2I", 1); on = syslook("ifaceT2I", 1);
argtype(on, tr); argtype(on, tr);
argtype(on, tl);
break; break;
...@@ -2538,16 +2546,17 @@ ifaceop(Type *tl, Node *n, int op) ...@@ -2538,16 +2546,17 @@ ifaceop(Type *tl, Node *n, int op)
a = n; // interface a = n; // interface
r = a; r = a;
s = signame(tr); // sigi
s = signame(tl); // sigi
if(s == S) if(s == S)
fatal("ifaceop: signame I2I"); fatal("ifaceop: signame I2I");
a = s->oname; a = s->oname;
a = nod(OADDR, a, N); a = nod(OADDR, a, N);
r = list(a, r); r = list(a, r);
on = syslook("ifaceI2I", 1); on = syslook("ifaceI2I", 1);
argtype(on, n->type);
argtype(on, tr); argtype(on, tr);
argtype(on, tl);
break; break;
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "runtime.h" #include "runtime.h"
static int32 debug = 0;
typedef struct Sigt Sigt; typedef struct Sigt Sigt;
typedef struct Sigi Sigi; typedef struct Sigi Sigi;
typedef struct Map Map; typedef struct Map Map;
...@@ -33,19 +35,79 @@ struct Map ...@@ -33,19 +35,79 @@ struct Map
}; };
static Map* hash[1009]; static Map* hash[1009];
static int32 debug = 0;
static void
printsigi(Sigi *si)
{
int32 i, n;
byte *name;
sys·printpointer(si);
prints("{");
n = si[0].offset;
for(i=1; i<n; i++) {
name = si[i].name;
if(name == nil) {
prints("<nil>");
break;
}
prints("[");
sys·printint(i);
prints("]\"");
prints((int8*)name);
prints("\"");
sys·printint(si[i].hash);
prints("/");
sys·printint(si[i].offset);
}
prints("}");
}
static void
printsigt(Sigt *st)
{
int32 i;
byte *name;
sys·printpointer(st);
prints("{");
for(i=0;; i++) {
name = st[i].name;
if(name == nil)
break;
prints("[");
sys·printint(i);
prints("]\"");
prints((int8*)name);
prints("\"");
sys·printint(st[i].hash);
prints("/");
sys·printpointer(st[i].fun);
}
prints("}");
}
static void
printiface(Map *im, void *it)
{
prints("(");
sys·printpointer(im);
prints(",");
sys·printpointer(it);
prints(")");
}
static Map* static Map*
hashmap(Sigi *si, Sigt *ss) hashmap(Sigi *si, Sigt *st)
{ {
int32 ns, ni; int32 nt, ni;
uint32 ihash, h; uint32 ihash, h;
byte *sname, *iname; byte *sname, *iname;
Map *m; Map *m;
h = ((uint32)(uint64)si + (uint32)(uint64)ss) % nelem(hash); h = ((uint32)(uint64)si + (uint32)(uint64)st) % nelem(hash);
for(m=hash[h]; m!=nil; m=m->link) { for(m=hash[h]; m!=nil; m=m->link) {
if(m->sigi == si && m->sigt == ss) { if(m->sigi == si && m->sigt == st) {
if(m->bad) { if(m->bad) {
throw("bad hashmap"); throw("bad hashmap");
m = nil; m = nil;
...@@ -58,10 +120,10 @@ hashmap(Sigi *si, Sigt *ss) ...@@ -58,10 +120,10 @@ hashmap(Sigi *si, Sigt *ss)
ni = si[0].offset; // first word has size ni = si[0].offset; // first word has size
m = mal(sizeof(*m) + ni*sizeof(m->fun[0])); m = mal(sizeof(*m) + ni*sizeof(m->fun[0]));
m->sigi = si; m->sigi = si;
m->sigt = ss; m->sigt = st;
ni = 1; // skip first word ni = 1; // skip first word
ns = 0; nt = 0;
loop1: loop1:
// pick up next name from // pick up next name from
...@@ -78,7 +140,7 @@ loop1: ...@@ -78,7 +140,7 @@ loop1:
loop2: loop2:
// pick up and comapre next name // pick up and comapre next name
// from structure signature // from structure signature
sname = ss[ns].name; sname = st[nt].name;
if(sname == nil) { if(sname == nil) {
prints((int8*)iname); prints((int8*)iname);
prints(": "); prints(": ");
...@@ -89,40 +151,18 @@ loop2: ...@@ -89,40 +151,18 @@ loop2:
return nil; return nil;
} }
if(ihash != ss[ns].hash || if(ihash != st[nt].hash ||
strcmp(sname, iname) != 0) { strcmp(sname, iname) != 0) {
ns++; nt++;
goto loop2; goto loop2;
} }
m->fun[si[ni].offset] = ss[ns].fun; m->fun[si[ni].offset] = st[nt].fun;
ni++; ni++;
goto loop1; goto loop1;
} }
static void // ifaceT2I(sigi *byte, sigt *byte, elem any) (ret any);
printsigi(Sigi *si)
{
sys·printpointer(si);
}
static void
printsigt(Sigt *st)
{
sys·printpointer(st);
}
static void
printiface(Map *im, void *it)
{
prints("(");
sys·printpointer(im);
prints(",");
sys·printpointer(it);
prints(")");
}
// ifaceT2I(sigi *byte, sigt *byte, elem any) (ret interface{});
void void
sys·ifaceT2I(Sigi *si, Sigt *st, void *elem, Map *retim, void *retit) sys·ifaceT2I(Sigi *si, Sigt *st, void *elem, Map *retim, void *retit)
{ {
...@@ -149,7 +189,7 @@ sys·ifaceT2I(Sigi *si, Sigt *st, void *elem, Map *retim, void *retit) ...@@ -149,7 +189,7 @@ sys·ifaceT2I(Sigi *si, Sigt *st, void *elem, Map *retim, void *retit)
FLUSH(&retim); FLUSH(&retim);
} }
// ifaceI2T(sigt *byte, iface interface{}) (ret any); // ifaceI2T(sigt *byte, iface any) (ret any);
void void
sys·ifaceI2T(Sigt *st, Map *im, void *it, void *ret) sys·ifaceI2T(Sigt *st, Map *im, void *it, void *ret)
{ {
...@@ -178,14 +218,14 @@ sys·ifaceI2T(Sigt *st, Map *im, void *it, void *ret) ...@@ -178,14 +218,14 @@ sys·ifaceI2T(Sigt *st, Map *im, void *it, void *ret)
FLUSH(&ret); FLUSH(&ret);
} }
// ifaceI2I(sigi *byte, iface interface{}) (ret interface{}); // ifaceI2I(sigi *byte, iface any) (ret any);
void void
sys·ifaceI2I(Sigi *si, Map *im, void *it, Map *retim, void *retit) sys·ifaceI2I(Sigi *si, Map *im, void *it, Map *retim, void *retit)
{ {
if(debug) { if(debug) {
prints("I2I sigi="); prints("I2I sigi=");
sys·printpointer(si); printsigi(si);
prints(" iface="); prints(" iface=");
printiface(im, it); printiface(im, it);
prints("\n"); prints("\n");
...@@ -209,3 +249,9 @@ sys·ifaceI2I(Sigi *si, Map *im, void *it, Map *retim, void *retit) ...@@ -209,3 +249,9 @@ sys·ifaceI2I(Sigi *si, Map *im, void *it, Map *retim, void *retit)
FLUSH(&retim); FLUSH(&retim);
} }
void
sys·printinter(Map *im, void *it)
{
printiface(im, it);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment