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