1
0
mirror of https://github.com/golang/go synced 2024-11-19 15:14:45 -07:00

gc: make size of struct{} and [0]byte 0 bytes

Fixes #1949.

R=iant, rsc
CC=golang-dev
https://golang.org/cl/4634124
This commit is contained in:
Robert Hencke 2011-07-12 11:12:06 -07:00 committed by Russ Cox
parent 86e7323bdf
commit 67edf9cb87
2 changed files with 9 additions and 20 deletions

View File

@ -225,20 +225,16 @@ dowidth(Type *t)
uint64 cap; uint64 cap;
dowidth(t->type); dowidth(t->type);
if(t->type->width == 0) if(t->type->width != 0) {
fatal("no width for type %T", t->type); if(tptr == TPTR32)
if(tptr == TPTR32) cap = ((uint32)-1) / t->type->width;
cap = ((uint32)-1) / t->type->width; else
else cap = ((uint64)-1) / t->type->width;
cap = ((uint64)-1) / t->type->width; if(t->bound > cap)
if(t->bound > cap) yyerror("type %lT larger than address space", t);
yyerror("type %lT larger than address space", t); }
w = t->bound * t->type->width; w = t->bound * t->type->width;
t->align = t->type->align; t->align = t->type->align;
if(w == 0) {
w = 1;
t->align = 1;
}
} }
else if(t->bound == -1) { else if(t->bound == -1) {
w = sizeof_Array; w = sizeof_Array;
@ -255,10 +251,6 @@ dowidth(Type *t)
if(t->funarg) if(t->funarg)
fatal("dowidth fn struct %T", t); fatal("dowidth fn struct %T", t);
w = widstruct(t, 0, 1); w = widstruct(t, 0, 1);
if(w == 0) {
w = 1;
t->align = 1;
}
break; break;
case TFUNC: case TFUNC:
@ -286,9 +278,6 @@ dowidth(Type *t)
break; break;
} }
// catch all for error cases; avoid divide by zero later
if(w == 0)
w = 1;
t->width = w; t->width = w;
if(t->align == 0) { if(t->align == 0) {
if(w > 8 || (w&(w-1)) != 0) if(w > 8 || (w&(w-1)) != 0)

View File

@ -189,7 +189,7 @@ compactframe(Prog* ptxt)
continue; continue;
w = n->type->width; w = n->type->width;
if((w >= MAXWIDTH) || (w < 1)) if((w >= MAXWIDTH) || (w < 0))
fatal("bad width"); fatal("bad width");
stksize += w; stksize += w;
stksize = rnd(stksize, n->type->align); stksize = rnd(stksize, n->type->align);