]> Cypherpunks repositories - gostls13.git/commitdiff
width fixes.
authorRuss Cox <rsc@golang.org>
Tue, 11 Nov 2008 21:46:55 +0000 (13:46 -0800)
committerRuss Cox <rsc@golang.org>
Tue, 11 Nov 2008 21:46:55 +0000 (13:46 -0800)
* check for uncomputed struct offsets
* distinguish function structs from ordinary structs
* make sure function structs are not examined in isolation

R=ken
OCL=19005
CL=19005

src/cmd/6g/align.c
src/cmd/6g/gsubr.c
src/cmd/gc/dcl.c
src/cmd/gc/go.h

index 28516df387887002586d4091420987405aa106f6..163bd800cc5455ed109ac254501048ae8b8b6bd6 100644 (file)
@@ -154,6 +154,8 @@ dowidth(Type *t)
                break;
 
        case TSTRUCT:
+               if(t->funarg)
+                       fatal("dowidth fn struct %T", t);
                w = widstruct(t, 0, 1);
                offmod(t);
                break;
index e21e8838f8c9fc5ba790f2dbbf3902a0b06c8b85..e3e62e947ad7be401d04823d483257afdff6fcd6 100644 (file)
@@ -243,6 +243,8 @@ nodarg(Type *t, int fp)
        n = nod(ONAME, N, N);
        n->type = t->type;
        n->sym = t->sym;
+       if(t->width == BADWIDTH)
+               fatal("nodarg: offset not computed for %T", t);
        n->xoffset = t->width;
        n->addable = 1;
 
index effb957858d92e7e054c74cb2b374f54751608cf..ef1ddbc7173634331c9b0b9e304e332bbb36764f 100644 (file)
@@ -161,9 +161,9 @@ functype(Node *this, Node *in, Node *out)
 
        t = typ(TFUNC);
 
-       t->type = dostruct(this, TSTRUCT);
-       t->type->down = dostruct(out, TSTRUCT);
-       t->type->down->down = dostruct(in, TSTRUCT);
+       t->type = dostruct(this, TFUNC);
+       t->type->down = dostruct(out, TFUNC);
+       t->type->down->down = dostruct(in, TFUNC);
 
        t->thistuple = listcount(this);
        t->outtuple = listcount(out);
@@ -498,6 +498,7 @@ loop:
        f = typ(TFIELD);
        f->type = n->type;
        f->note = note;
+       f->width = BADWIDTH;
 
        if(n->left != N && n->left->op == ONAME) {
                f->nname = n->left;
@@ -517,15 +518,23 @@ Type*
 dostruct(Node *n, int et)
 {
        Type *t;
+       int funarg;
 
        /*
         * convert a parsed id/type list into
         * a type for struct/interface/arglist
         */
 
+       funarg = 0;
+       if(et == TFUNC) {
+               funarg = 1;
+               et = TSTRUCT;
+       }
        t = typ(et);
+       t->funarg = funarg;
        stotype(n, &t->type);
-       checkwidth(t);
+       if(!funarg)
+               checkwidth(t);
        return t;
 }
 
@@ -1130,6 +1139,11 @@ checkwidth(Type *t)
 {
        TypeList *l;
 
+       // function arg structs should not be checked
+       // outside of the enclosing function.
+       if(t->funarg)
+               fatal("checkwidth %T", t);
+
        if(!defercalc) {
                dowidth(t);
                return;
index acb311b4e73f6189894f98fdf1e30df351b0376a..c76adf6925b9e7ac713c7dd9dd265912d05ec671 100644 (file)
@@ -41,6 +41,8 @@ enum
        ASTRING,
        APTR,
        AINTER,
+       
+       BADWIDTH        = -1000000000
 };
 
 /*
@@ -126,6 +128,7 @@ struct      Type
        uchar   printed;
        uchar   embedded;       // TFIELD embedded type
        uchar   siggen;
+       uchar   funarg;
 
        // TFUNCT
        uchar   thistuple;