]> Cypherpunks repositories - gostls13.git/commitdiff
gc: make size of struct{} and [0]byte 0 bytes
authorRobert Hencke <robert.hencke@gmail.com>
Tue, 12 Jul 2011 18:12:06 +0000 (11:12 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 12 Jul 2011 18:12:06 +0000 (11:12 -0700)
Fixes #1949.

R=iant, rsc
CC=golang-dev
https://golang.org/cl/4634124

src/cmd/gc/align.c
src/cmd/gc/pgen.c

index 7fcac483393f5e1fec1dec84590e0a38d4d82f9f..6bb93ef1791c4e8364dc68cd30acc38ae8d8a437 100644 (file)
@@ -225,20 +225,16 @@ 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) {
+                               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);
+                       }
                        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;
@@ -255,10 +251,6 @@ dowidth(Type *t)
                if(t->funarg)
                        fatal("dowidth fn struct %T", t);
                w = widstruct(t, 0, 1);
-               if(w == 0) {
-                       w = 1;
-                       t->align = 1;
-               }
                break;
 
        case TFUNC:
@@ -286,9 +278,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)
index 552e405d8be966fbc13ba11e07148d86c0bf3cb1..ad5ad27583798042b8ab0a87648436cb6ca5dbbd 100644 (file)
@@ -189,7 +189,7 @@ compactframe(Prog* ptxt)
                        continue;
 
                w = n->type->width;
-               if((w >= MAXWIDTH) || (w < 1))
+               if((w >= MAXWIDTH) || (w < 0))
                        fatal("bad width");
                stksize += w;
                stksize = rnd(stksize, n->type->align);