1
0
mirror of https://github.com/golang/go synced 2024-11-20 08:04:42 -07:00

cmd/gc: prepare for 64-bit ints

This CL makes the compiler understand that the type of
the len or cap of a map, slice, or string is 'int', not 'int32'.
It does not change the meaning of int, but it should make
the eventual change of the meaning of int in 6g a bit smoother.

Update #2188.

R=ken, dave, remyoudompheng
CC=golang-dev
https://golang.org/cl/6542059
This commit is contained in:
Russ Cox 2012-09-24 14:59:44 -04:00
parent 0bf46d0cf3
commit 650160e36a
16 changed files with 81 additions and 78 deletions

View File

@ -27,6 +27,7 @@ void
betypeinit(void) betypeinit(void)
{ {
widthptr = 4; widthptr = 4;
widthint = 4;
zprog.link = P; zprog.link = P;
zprog.as = AGOK; zprog.as = AGOK;

View File

@ -309,7 +309,7 @@ cgen(Node *n, Node *res)
case OLEN: case OLEN:
if(istype(nl->type, TMAP) || istype(nl->type, TCHAN)) { if(istype(nl->type, TMAP) || istype(nl->type, TCHAN)) {
// map and chan have len in the first 32-bit word. // map and chan have len in the first int-sized word.
// a zero pointer means zero length // a zero pointer means zero length
regalloc(&n1, types[tptr], res); regalloc(&n1, types[tptr], res);
cgen(nl, &n1); cgen(nl, &n1);
@ -320,7 +320,7 @@ cgen(Node *n, Node *res)
n2 = n1; n2 = n1;
n2.op = OINDREG; n2.op = OINDREG;
n2.type = types[TINT32]; n2.type = types[simtype[TINT]];
gmove(&n2, &n1); gmove(&n2, &n1);
patch(p1, pc); patch(p1, pc);
@ -333,7 +333,7 @@ cgen(Node *n, Node *res)
// both slice and string have len one pointer into the struct. // both slice and string have len one pointer into the struct.
// a zero pointer means zero length // a zero pointer means zero length
igen(nl, &n1, res); igen(nl, &n1, res);
n1.type = types[TUINT32]; n1.type = types[simtype[TUINT]];
n1.xoffset += Array_nel; n1.xoffset += Array_nel;
gmove(&n1, res); gmove(&n1, res);
regfree(&n1); regfree(&n1);
@ -344,7 +344,7 @@ cgen(Node *n, Node *res)
case OCAP: case OCAP:
if(istype(nl->type, TCHAN)) { if(istype(nl->type, TCHAN)) {
// chan has cap in the second 32-bit word. // chan has cap in the second int-sized word.
// a zero pointer means zero length // a zero pointer means zero length
regalloc(&n1, types[tptr], res); regalloc(&n1, types[tptr], res);
cgen(nl, &n1); cgen(nl, &n1);
@ -355,8 +355,8 @@ cgen(Node *n, Node *res)
n2 = n1; n2 = n1;
n2.op = OINDREG; n2.op = OINDREG;
n2.xoffset = 4; n2.xoffset = widthint;
n2.type = types[TINT32]; n2.type = types[simtype[TINT]];
gmove(&n2, &n1); gmove(&n2, &n1);
patch(p1, pc); patch(p1, pc);
@ -367,7 +367,7 @@ cgen(Node *n, Node *res)
} }
if(isslice(nl->type)) { if(isslice(nl->type)) {
igen(nl, &n1, res); igen(nl, &n1, res);
n1.type = types[TUINT32]; n1.type = types[simtype[TUINT]];
n1.xoffset += Array_cap; n1.xoffset += Array_cap;
gmove(&n1, res); gmove(&n1, res);
regfree(&n1); regfree(&n1);
@ -596,7 +596,7 @@ agen(Node *n, Node *res)
nlen.type = types[tptr]; nlen.type = types[tptr];
nlen.xoffset += Array_array; nlen.xoffset += Array_array;
gmove(&nlen, &n3); gmove(&nlen, &n3);
nlen.type = types[TUINT32]; nlen.type = types[simtype[TUINT]];
nlen.xoffset += Array_nel-Array_array; nlen.xoffset += Array_nel-Array_array;
} }
} }
@ -621,7 +621,7 @@ agen(Node *n, Node *res)
nlen.type = types[tptr]; nlen.type = types[tptr];
nlen.xoffset += Array_array; nlen.xoffset += Array_array;
gmove(&nlen, &n3); gmove(&nlen, &n3);
nlen.type = types[TUINT32]; nlen.type = types[simtype[TUINT]];
nlen.xoffset += Array_nel-Array_array; nlen.xoffset += Array_nel-Array_array;
} }
} }
@ -656,9 +656,9 @@ agen(Node *n, Node *res)
v = mpgetfix(nr->val.u.xval); v = mpgetfix(nr->val.u.xval);
if(isslice(nl->type) || nl->type->etype == TSTRING) { if(isslice(nl->type) || nl->type->etype == TSTRING) {
if(!debug['B'] && !n->bounded) { if(!debug['B'] && !n->bounded) {
nodconst(&n2, types[TUINT32], v); nodconst(&n2, types[simtype[TUINT]], v);
gins(optoas(OCMP, types[TUINT32]), &nlen, &n2); gins(optoas(OCMP, types[simtype[TUINT]]), &nlen, &n2);
p1 = gbranch(optoas(OGT, types[TUINT32]), T, +1); p1 = gbranch(optoas(OGT, types[simtype[TUINT]]), T, +1);
ginscall(panicindex, -1); ginscall(panicindex, -1);
patch(p1, pc); patch(p1, pc);
} }
@ -683,7 +683,7 @@ agen(Node *n, Node *res)
if(!debug['B'] && !n->bounded) { if(!debug['B'] && !n->bounded) {
// check bounds // check bounds
t = types[TUINT32]; t = types[simtype[TUINT]];
if(is64(nr->type)) if(is64(nr->type))
t = types[TUINT64]; t = types[TUINT64];
if(isconst(nl, CTSTR)) { if(isconst(nl, CTSTR)) {
@ -1350,7 +1350,7 @@ componentgen(Node *nr, Node *nl)
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
nodl.xoffset += Array_nel-Array_array; nodl.xoffset += Array_nel-Array_array;
nodl.type = types[TUINT32]; nodl.type = types[simtype[TUINT]];
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_nel-Array_array; nodr.xoffset += Array_nel-Array_array;
@ -1360,7 +1360,7 @@ componentgen(Node *nr, Node *nl)
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
nodl.xoffset += Array_cap-Array_nel; nodl.xoffset += Array_cap-Array_nel;
nodl.type = types[TUINT32]; nodl.type = types[simtype[TUINT]];
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_cap-Array_nel; nodr.xoffset += Array_cap-Array_nel;
@ -1383,7 +1383,7 @@ componentgen(Node *nr, Node *nl)
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
nodl.xoffset += Array_nel-Array_array; nodl.xoffset += Array_nel-Array_array;
nodl.type = types[TUINT32]; nodl.type = types[simtype[TUINT]];
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_nel-Array_array; nodr.xoffset += Array_nel-Array_array;

View File

@ -27,6 +27,7 @@ void
betypeinit(void) betypeinit(void)
{ {
widthptr = 8; widthptr = 8;
widthint = 4;
zprog.link = P; zprog.link = P;
zprog.as = AGOK; zprog.as = AGOK;

View File

@ -21,7 +21,7 @@ struct Addr
Sym* gotype; Sym* gotype;
Sym* sym; Sym* sym;
Node* node; Node* node;
int width; int64 width;
uchar type; uchar type;
uchar index; uchar index;
uchar etype; uchar etype;

View File

@ -312,8 +312,8 @@ datastring(char *s, int len, Addr *a)
a->type = D_EXTERN; a->type = D_EXTERN;
a->sym = sym; a->sym = sym;
a->node = sym->def; a->node = sym->def;
a->offset = widthptr+4; // skip header a->offset = widthptr+widthint; // skip header
a->etype = TINT32; a->etype = simtype[TINT];
} }
/* /*
@ -386,10 +386,10 @@ gdatastring(Node *nam, Strlit *sval)
p->to.type = D_ADDR; p->to.type = D_ADDR;
//print("%P\n", p); //print("%P\n", p);
nodconst(&nod1, types[TINT32], sval->len); nodconst(&nod1, types[TINT], sval->len);
p = gins(ADATA, nam, &nod1); p = gins(ADATA, nam, &nod1);
p->from.scale = types[TINT32]->width; p->from.scale = widthint;
p->from.offset += types[tptr]->width; p->from.offset += widthptr;
} }
int int
@ -408,7 +408,7 @@ dstringptr(Sym *s, int off, char *str)
datastring(str, strlen(str)+1, &p->to); datastring(str, strlen(str)+1, &p->to);
p->to.index = p->to.type; p->to.index = p->to.type;
p->to.type = D_ADDR; p->to.type = D_ADDR;
p->to.etype = TINT32; p->to.etype = simtype[TINT];
off += widthptr; off += widthptr;
return off; return off;
@ -432,7 +432,7 @@ dgostrlitptr(Sym *s, int off, Strlit *lit)
datagostring(lit, &p->to); datagostring(lit, &p->to);
p->to.index = p->to.type; p->to.index = p->to.type;
p->to.type = D_ADDR; p->to.type = D_ADDR;
p->to.etype = TINT32; p->to.etype = simtype[TINT];
off += widthptr; off += widthptr;
return off; return off;

View File

@ -1247,9 +1247,9 @@ naddr(Node *n, Addr *a, int canemitcode)
naddr(n->left, a, canemitcode); naddr(n->left, a, canemitcode);
if(a->type == D_CONST && a->offset == 0) if(a->type == D_CONST && a->offset == 0)
break; // len(nil) break; // len(nil)
a->etype = TUINT32; a->etype = simtype[TUINT];
a->offset += Array_nel; a->offset += Array_nel;
a->width = 4; a->width = widthint;
if(a->offset >= unmappedzero && a->offset-Array_nel < unmappedzero) if(a->offset >= unmappedzero && a->offset-Array_nel < unmappedzero)
checkoffset(a, canemitcode); checkoffset(a, canemitcode);
break; break;
@ -1259,9 +1259,9 @@ naddr(Node *n, Addr *a, int canemitcode)
naddr(n->left, a, canemitcode); naddr(n->left, a, canemitcode);
if(a->type == D_CONST && a->offset == 0) if(a->type == D_CONST && a->offset == 0)
break; // cap(nil) break; // cap(nil)
a->etype = TUINT32; a->etype = simtype[TUINT];
a->offset += Array_cap; a->offset += Array_cap;
a->width = 4; a->width = widthint;
if(a->offset >= unmappedzero && a->offset-Array_cap < unmappedzero) if(a->offset >= unmappedzero && a->offset-Array_cap < unmappedzero)
checkoffset(a, canemitcode); checkoffset(a, canemitcode);
break; break;
@ -2086,12 +2086,12 @@ oindex:
if(!debug['B'] && !n->bounded) { if(!debug['B'] && !n->bounded) {
// check bounds // check bounds
n4.op = OXXX; n4.op = OXXX;
t = types[TUINT32]; t = types[simtype[TUINT]];
if(o & ODynam) { if(o & ODynam) {
if(o & OAddable) { if(o & OAddable) {
n2 = *l; n2 = *l;
n2.xoffset += Array_nel; n2.xoffset += Array_nel;
n2.type = types[TUINT32]; n2.type = types[simtype[TUINT]];
if(is64(r->type)) { if(is64(r->type)) {
t = types[TUINT64]; t = types[TUINT64];
regalloc(&n4, t, N); regalloc(&n4, t, N);
@ -2102,7 +2102,7 @@ oindex:
n2 = *reg; n2 = *reg;
n2.xoffset = Array_nel; n2.xoffset = Array_nel;
n2.op = OINDREG; n2.op = OINDREG;
n2.type = types[TUINT32]; n2.type = types[simtype[TUINT]];
if(is64(r->type)) { if(is64(r->type)) {
t = types[TUINT64]; t = types[TUINT64];
regalloc(&n4, t, N); regalloc(&n4, t, N);
@ -2180,8 +2180,8 @@ oindex_const:
n1.type = types[tptr]; n1.type = types[tptr];
n1.xoffset = Array_nel; n1.xoffset = Array_nel;
nodconst(&n2, types[TUINT64], v); nodconst(&n2, types[TUINT64], v);
gins(optoas(OCMP, types[TUINT32]), &n1, &n2); gins(optoas(OCMP, types[simtype[TUINT]]), &n1, &n2);
p1 = gbranch(optoas(OGT, types[TUINT32]), T, +1); p1 = gbranch(optoas(OGT, types[simtype[TUINT]]), T, +1);
ginscall(panicindex, -1); ginscall(panicindex, -1);
patch(p1, pc); patch(p1, pc);
} }
@ -2223,9 +2223,9 @@ oindex_const_sudo:
if(!debug['B'] && !n->bounded) { if(!debug['B'] && !n->bounded) {
a->offset += Array_nel; a->offset += Array_nel;
nodconst(&n2, types[TUINT64], v); nodconst(&n2, types[TUINT64], v);
p1 = gins(optoas(OCMP, types[TUINT32]), N, &n2); p1 = gins(optoas(OCMP, types[simtype[TUINT]]), N, &n2);
p1->from = *a; p1->from = *a;
p1 = gbranch(optoas(OGT, types[TUINT32]), T, +1); p1 = gbranch(optoas(OGT, types[simtype[TUINT]]), T, +1);
ginscall(panicindex, -1); ginscall(panicindex, -1);
patch(p1, pc); patch(p1, pc);
a->offset -= Array_nel; a->offset -= Array_nel;

View File

@ -945,7 +945,8 @@ Bits
mkvar(Reg *r, Adr *a) mkvar(Reg *r, Adr *a)
{ {
Var *v; Var *v;
int i, t, n, et, z, w, flag; int i, t, n, et, z, flag;
int64 w;
uint32 regu; uint32 regu;
int32 o; int32 o;
Bits bit; Bits bit;
@ -998,7 +999,7 @@ mkvar(Reg *r, Adr *a)
o = a->offset; o = a->offset;
w = a->width; w = a->width;
if(w < 0) if(w < 0)
fatal("bad width %d for %D", w, a); fatal("bad width %lld for %D", w, a);
flag = 0; flag = 0;
for(i=0; i<nvar; i++) { for(i=0; i<nvar; i++) {

View File

@ -27,6 +27,7 @@ void
betypeinit(void) betypeinit(void)
{ {
widthptr = 4; widthptr = 4;
widthint = 4;
zprog.link = P; zprog.link = P;
zprog.as = AGOK; zprog.as = AGOK;

View File

@ -615,12 +615,12 @@ typeinit(void)
} }
Array_array = rnd(0, widthptr); Array_array = rnd(0, widthptr);
Array_nel = rnd(Array_array+widthptr, types[TUINT32]->width); Array_nel = rnd(Array_array+widthptr, widthint);
Array_cap = rnd(Array_nel+types[TUINT32]->width, types[TUINT32]->width); Array_cap = rnd(Array_nel+widthint, widthint);
sizeof_Array = rnd(Array_cap+types[TUINT32]->width, widthptr); sizeof_Array = rnd(Array_cap+widthint, widthptr);
// string is same as slice wo the cap // string is same as slice wo the cap
sizeof_String = rnd(Array_nel+types[TUINT32]->width, widthptr); sizeof_String = rnd(Array_nel+widthint, widthptr);
dowidth(types[TSTRING]); dowidth(types[TSTRING]);
dowidth(idealstring); dowidth(idealstring);

View File

@ -763,7 +763,7 @@ cgen_eface(Node *n, Node *res)
* generate: * generate:
* res = s[lo, hi]; * res = s[lo, hi];
* n->left is s * n->left is s
* n->list is (cap(s)-lo(TUINT32), hi-lo(TUINT32)[, lo*width(TUINTPTR)]) * n->list is (cap(s)-lo(TUINT), hi-lo(TUINT)[, lo*width(TUINTPTR)])
* caller (cgen) guarantees res is an addable ONAME. * caller (cgen) guarantees res is an addable ONAME.
*/ */
void void
@ -780,14 +780,14 @@ cgen_slice(Node *n, Node *res)
// dst.len = hi [ - lo ] // dst.len = hi [ - lo ]
dst = *res; dst = *res;
dst.xoffset += Array_nel; dst.xoffset += Array_nel;
dst.type = types[TUINT32]; dst.type = types[simtype[TUINT]];
cgen(len, &dst); cgen(len, &dst);
if(n->op != OSLICESTR) { if(n->op != OSLICESTR) {
// dst.cap = cap [ - lo ] // dst.cap = cap [ - lo ]
dst = *res; dst = *res;
dst.xoffset += Array_cap; dst.xoffset += Array_cap;
dst.type = types[TUINT32]; dst.type = types[simtype[TUINT]];
cgen(cap, &dst); cgen(cap, &dst);
} }

View File

@ -905,6 +905,7 @@ EXTERN int hasdefer; // flag that curfn has defer statetment
EXTERN Node* curfn; EXTERN Node* curfn;
EXTERN int widthptr; EXTERN int widthptr;
EXTERN int widthint;
EXTERN Node* typesw; EXTERN Node* typesw;
EXTERN Node* nblank; EXTERN Node* nblank;

View File

@ -302,8 +302,8 @@ stringsym(char *s, int len)
off = 0; off = 0;
// string header // string header
off = dsymptr(sym, off, sym, widthptr+4); off = dsymptr(sym, off, sym, widthptr+widthint);
off = duint32(sym, off, len); off = duintxx(sym, off, len, widthint);
// string data // string data
for(n=0; n<len; n+=m) { for(n=0; n<len; n+=m) {

View File

@ -378,9 +378,9 @@ dextratype(Sym *sym, int off, Type *t, int ptroff)
} }
// slice header // slice header
ot = dsymptr(s, ot, s, ot + widthptr + 2*4); ot = dsymptr(s, ot, s, ot + widthptr + 2*widthint);
ot = duint32(s, ot, n); ot = duintxx(s, ot, n, widthint);
ot = duint32(s, ot, n); ot = duintxx(s, ot, n, widthint);
// methods // methods
for(a=m; a; a=a->link) { for(a=m; a; a=a->link) {
@ -780,13 +780,13 @@ ok:
// two slice headers: in and out. // two slice headers: in and out.
ot = rnd(ot, widthptr); ot = rnd(ot, widthptr);
ot = dsymptr(s, ot, s, ot+2*(widthptr+2*4)); ot = dsymptr(s, ot, s, ot+2*(widthptr+2*widthint));
n = t->thistuple + t->intuple; n = t->thistuple + t->intuple;
ot = duint32(s, ot, n); ot = duintxx(s, ot, n, widthint);
ot = duint32(s, ot, n); ot = duintxx(s, ot, n, widthint);
ot = dsymptr(s, ot, s, ot+1*(widthptr+2*4)+n*widthptr); ot = dsymptr(s, ot, s, ot+1*(widthptr+2*widthint)+n*widthptr);
ot = duint32(s, ot, t->outtuple); ot = duintxx(s, ot, t->outtuple, widthint);
ot = duint32(s, ot, t->outtuple); ot = duintxx(s, ot, t->outtuple, widthint);
// slice data // slice data
for(t1=getthisx(t)->type; t1; t1=t1->down, n++) for(t1=getthisx(t)->type; t1; t1=t1->down, n++)
@ -808,9 +808,9 @@ ok:
// ../../pkg/runtime/type.go:/InterfaceType // ../../pkg/runtime/type.go:/InterfaceType
ot = dcommontype(s, ot, t); ot = dcommontype(s, ot, t);
xt = ot - 2*widthptr; xt = ot - 2*widthptr;
ot = dsymptr(s, ot, s, ot+widthptr+2*4); ot = dsymptr(s, ot, s, ot+widthptr+2*widthint);
ot = duint32(s, ot, n); ot = duintxx(s, ot, n, widthint);
ot = duint32(s, ot, n); ot = duintxx(s, ot, n, widthint);
for(a=m; a; a=a->link) { for(a=m; a; a=a->link) {
// ../../pkg/runtime/type.go:/imethod // ../../pkg/runtime/type.go:/imethod
ot = dgostringptr(s, ot, a->name); ot = dgostringptr(s, ot, a->name);
@ -853,9 +853,9 @@ ok:
} }
ot = dcommontype(s, ot, t); ot = dcommontype(s, ot, t);
xt = ot - 2*widthptr; xt = ot - 2*widthptr;
ot = dsymptr(s, ot, s, ot+widthptr+2*4); ot = dsymptr(s, ot, s, ot+widthptr+2*widthint);
ot = duint32(s, ot, n); ot = duintxx(s, ot, n, widthint);
ot = duint32(s, ot, n); ot = duintxx(s, ot, n, widthint);
for(t1=t->type; t1!=T; t1=t1->down) { for(t1=t->type; t1!=T; t1=t1->down) {
// ../../pkg/runtime/type.go:/structField // ../../pkg/runtime/type.go:/structField
if(t1->sym && !t1->embedded) { if(t1->sym && !t1->embedded) {

View File

@ -46,8 +46,6 @@ func appendstr(typ *byte, x []byte, y string) []byte
func cmpstring(string, string) int func cmpstring(string, string) int
func eqstring(string, string) bool func eqstring(string, string) bool
func slicestring(string, int, int) string
func slicestring1(string, int) string
func intstring(int64) string func intstring(int64) string
func slicebytetostring([]byte) string func slicebytetostring([]byte) string
func slicerunetostring([]rune) string func slicerunetostring([]rune) string
@ -55,7 +53,7 @@ func stringtoslicebyte(string) []byte
func stringtoslicerune(string) []rune func stringtoslicerune(string) []rune
func stringiter(string, int) int func stringiter(string, int) int
func stringiter2(string, int) (retk int, retv rune) func stringiter2(string, int) (retk int, retv rune)
func copy(to any, fr any, wid uint32) int func copy(to any, fr any, wid uintptr) int
func slicestringcopy(to any, fr any) int func slicestringcopy(to any, fr any) int
// interface conversions // interface conversions
@ -109,7 +107,7 @@ func selectnbsend(chanType *byte, hchan chan<- any, elem any) bool
func selectnbrecv(chanType *byte, elem *any, hchan <-chan any) bool func selectnbrecv(chanType *byte, elem *any, hchan <-chan any) bool
func selectnbrecv2(chanType *byte, elem *any, received *bool, hchan <-chan any) bool func selectnbrecv2(chanType *byte, elem *any, received *bool, hchan <-chan any) bool
func newselect(size int) (sel *byte) func newselect(size int32) (sel *byte)
func selectsend(sel *byte, hchan chan<- any, elem *any) (selected bool) func selectsend(sel *byte, hchan chan<- any, elem *any) (selected bool)
func selectrecv(sel *byte, hchan <-chan any, elem *any) (selected bool) func selectrecv(sel *byte, hchan <-chan any, elem *any) (selected bool)
func selectrecv2(sel *byte, hchan <-chan any, elem *any, received *bool) (selected bool) func selectrecv2(sel *byte, hchan <-chan any, elem *any, received *bool) (selected bool)

View File

@ -300,9 +300,9 @@ staticcopy(Node *l, Node *r, NodeList **out)
n1.xoffset = l->xoffset + Array_array; n1.xoffset = l->xoffset + Array_array;
gdata(&n1, nod(OADDR, a, N), widthptr); gdata(&n1, nod(OADDR, a, N), widthptr);
n1.xoffset = l->xoffset + Array_nel; n1.xoffset = l->xoffset + Array_nel;
gdata(&n1, r->right, 4); gdata(&n1, r->right, widthint);
n1.xoffset = l->xoffset + Array_cap; n1.xoffset = l->xoffset + Array_cap;
gdata(&n1, r->right, 4); gdata(&n1, r->right, widthint);
return 1; return 1;
} }
// fall through // fall through
@ -403,9 +403,9 @@ staticassign(Node *l, Node *r, NodeList **out)
n1.xoffset = l->xoffset + Array_array; n1.xoffset = l->xoffset + Array_array;
gdata(&n1, nod(OADDR, a, N), widthptr); gdata(&n1, nod(OADDR, a, N), widthptr);
n1.xoffset = l->xoffset + Array_nel; n1.xoffset = l->xoffset + Array_nel;
gdata(&n1, r->right, 4); gdata(&n1, r->right, widthint);
n1.xoffset = l->xoffset + Array_cap; n1.xoffset = l->xoffset + Array_cap;
gdata(&n1, r->right, 4); gdata(&n1, r->right, widthint);
// Fall through to init underlying array. // Fall through to init underlying array.
l = a; l = a;
} }
@ -1232,11 +1232,11 @@ slice:
gdata(&nam, nl, types[tptr]->width); gdata(&nam, nl, types[tptr]->width);
nam.xoffset += Array_nel-Array_array; nam.xoffset += Array_nel-Array_array;
nodconst(&nod1, types[TINT32], nr->type->bound); nodconst(&nod1, types[TINT], nr->type->bound);
gdata(&nam, &nod1, types[TINT32]->width); gdata(&nam, &nod1, widthint);
nam.xoffset += Array_cap-Array_nel; nam.xoffset += Array_cap-Array_nel;
gdata(&nam, &nod1, types[TINT32]->width); gdata(&nam, &nod1, widthint);
goto yes; goto yes;

View File

@ -2496,7 +2496,7 @@ sliceany(Node* n, NodeList **init)
chk1 = N; chk1 = N;
chk2 = N; chk2 = N;
bt = types[TUINT32]; bt = types[simtype[TUINT]];
if(hb != N && hb->type->width > 4) if(hb != N && hb->type->width > 4)
bt = types[TUINT64]; bt = types[TUINT64];
if(lb != N && lb->type->width > 4) if(lb != N && lb->type->width > 4)
@ -2546,18 +2546,18 @@ sliceany(Node* n, NodeList **init)
n->right = N; n->right = N;
n->list = nil; n->list = nil;
if(lb == N) if(lb == N)
bound = conv(bound, types[TUINT32]); bound = conv(bound, types[simtype[TUINT]]);
else else
bound = nod(OSUB, conv(bound, types[TUINT32]), conv(lb, types[TUINT32])); bound = nod(OSUB, conv(bound, types[simtype[TUINT]]), conv(lb, types[simtype[TUINT]]));
typecheck(&bound, Erv); typecheck(&bound, Erv);
walkexpr(&bound, init); walkexpr(&bound, init);
n->list = list(n->list, bound); n->list = list(n->list, bound);
// len = hi [ - lo] // len = hi [ - lo]
if(lb == N) if(lb == N)
hb = conv(hb, types[TUINT32]); hb = conv(hb, types[simtype[TUINT]]);
else else
hb = nod(OSUB, conv(hb, types[TUINT32]), conv(lb, types[TUINT32])); hb = nod(OSUB, conv(hb, types[simtype[TUINT]]), conv(lb, types[simtype[TUINT]]));
typecheck(&hb, Erv); typecheck(&hb, Erv);
walkexpr(&hb, init); walkexpr(&hb, init);
n->list = list(n->list, hb); n->list = list(n->list, hb);