summaryrefslogtreecommitdiff
path: root/src/cmd/gc/align.c
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-08-03 17:26:15 +0200
committerOndřej Surý <ondrej@sury.org>2011-08-03 17:31:49 +0200
commitb757d264230d65f988e08158e096a09497d39eb4 (patch)
treee20ec608a2ec8ebf603fa7aa060eb9723c4780b9 /src/cmd/gc/align.c
parent5976088995f5c0d0bcada7d491fda4b6245e54e0 (diff)
downloadgolang-b757d264230d65f988e08158e096a09497d39eb4.tar.gz
Imported Upstream version 2011.07.29
Diffstat (limited to 'src/cmd/gc/align.c')
-rw-r--r--src/cmd/gc/align.c46
1 files changed, 20 insertions, 26 deletions
diff --git a/src/cmd/gc/align.c b/src/cmd/gc/align.c
index 7fcac4833..14c1c4a8d 100644
--- a/src/cmd/gc/align.c
+++ b/src/cmd/gc/align.c
@@ -30,14 +30,18 @@ offmod(Type *t)
o = 0;
for(f=t->type; f!=T; f=f->down) {
if(f->etype != TFIELD)
- fatal("widstruct: not TFIELD: %lT", f);
+ fatal("offmod: not TFIELD: %lT", f);
f->width = o;
o += widthptr;
+ if(o >= MAXWIDTH) {
+ yyerror("interface too large");
+ o = widthptr;
+ }
}
}
-static uint32
-widstruct(Type *t, uint32 o, int flag)
+static vlong
+widstruct(Type *errtype, Type *t, vlong o, int flag)
{
Type *f;
int32 w, maxalign;
@@ -69,6 +73,10 @@ widstruct(Type *t, uint32 o, int flag)
f->nname->xoffset = o;
}
o += w;
+ if(o >= MAXWIDTH) {
+ yyerror("type %lT too large", errtype);
+ o = 8; // small but nonzero
+ }
}
// final width is rounded
if(flag)
@@ -225,20 +233,13 @@ dowidth(Type *t)
uint64 cap;
dowidth(t->type);
- if(t->type->width == 0)
- fatal("no width for type %T", t->type);
- if(tptr == TPTR32)
- cap = ((uint32)-1) / t->type->width;
- else
- cap = ((uint64)-1) / t->type->width;
- if(t->bound > cap)
- yyerror("type %lT larger than address space", t);
+ if(t->type->width != 0) {
+ cap = (MAXWIDTH-1) / t->type->width;
+ if(t->bound > cap)
+ yyerror("type %lT larger than address space", t);
+ }
w = t->bound * t->type->width;
t->align = t->type->align;
- if(w == 0) {
- w = 1;
- t->align = 1;
- }
}
else if(t->bound == -1) {
w = sizeof_Array;
@@ -254,11 +255,7 @@ dowidth(Type *t)
case TSTRUCT:
if(t->funarg)
fatal("dowidth fn struct %T", t);
- w = widstruct(t, 0, 1);
- if(w == 0) {
- w = 1;
- t->align = 1;
- }
+ w = widstruct(t, t, 0, 1);
break;
case TFUNC:
@@ -276,9 +273,9 @@ dowidth(Type *t)
// function is 3 cated structures;
// compute their widths as side-effect.
t1 = t->type;
- w = widstruct(*getthis(t1), 0, 0);
- w = widstruct(*getinarg(t1), w, widthptr);
- w = widstruct(*getoutarg(t1), w, widthptr);
+ w = widstruct(t->type, *getthis(t1), 0, 0);
+ w = widstruct(t->type, *getinarg(t1), w, widthptr);
+ w = widstruct(t->type, *getoutarg(t1), w, widthptr);
t1->argwid = w;
if(w%widthptr)
warn("bad type %T %d\n", t1, w);
@@ -286,9 +283,6 @@ dowidth(Type *t)
break;
}
- // catch all for error cases; avoid divide by zero later
- if(w == 0)
- w = 1;
t->width = w;
if(t->align == 0) {
if(w > 8 || (w&(w-1)) != 0)