]> Cypherpunks repositories - gostls13.git/commitdiff
portability bug
authorKen Thompson <ken@golang.org>
Fri, 19 Dec 2008 22:04:25 +0000 (14:04 -0800)
committerKen Thompson <ken@golang.org>
Fri, 19 Dec 2008 22:04:25 +0000 (14:04 -0800)
cant assign to closed array

R=r
OCL=21634
CL=21634

src/cmd/6g/align.c
src/cmd/6g/cgen.c
src/cmd/6g/gg.h
src/cmd/6g/gsubr.c
src/cmd/gc/go.h
src/cmd/gc/walk.c

index 392ad3d0c45631b0e122bd0428e602c70ffd3d97..2a930523b4212d26f221044f1b7e31815892ace8 100644 (file)
@@ -151,7 +151,7 @@ dowidth(Type *t)
                if(t->type == T)
                        break;
                dowidth(t->type);
-               w = sizeof(Array);
+               w = sizeof_Array;
                if(t->bound >= 0)
                        w = t->bound * t->type->width;
                break;
@@ -259,5 +259,10 @@ belexinit(int lextype)
 
        symstringo = lookup(".stringo");        // strings
 
+       Array_array = rnd(0, types[tptr]->width);
+       Array_nel = rnd(Array_array+types[tptr]->width, types[TUINT32]->width);
+       Array_cap = rnd(Array_nel+types[TUINT32]->width, types[TUINT32]->width);
+       sizeof_Array = rnd(Array_cap+types[TUINT32]->width, maxround);
+
        listinit();
 }
index bb5cb246128e91383dbdfa7601248721b1542e0f..c0a665c072e4fc7a4469e4290789fd68436d87e2 100644 (file)
@@ -189,14 +189,14 @@ cgen(Node *n, Node *res)
                        // convert dynamic array to static array
                        n2 = n1;
                        n2.op = OINDREG;
-                       n2.xoffset = offsetof(Array,array);
+                       n2.xoffset = Array_array;
                        n2.type = types[tptr];
                        gins(AMOVQ, &n2, &n1);
                }
                if(isptrdarray(n->type) && isptrsarray(nl->type)) {
                        // conver static array to dynamic array
                        // it is assumed that the dope is just before the array
-                       nodconst(&n2, types[tptr], sizeof(Array));
+                       nodconst(&n2, types[tptr], sizeof_Array);
                        gins(ASUBQ, &n2, &n1);
                }
                gmove(&n1, res);
@@ -247,7 +247,7 @@ cgen(Node *n, Node *res)
                        cgen(nl, &n1);
                        n1.op = OINDREG;
                        n1.type = types[TUINT32];
-                       n1.xoffset = offsetof(Array,nel);
+                       n1.xoffset = Array_nel;
                        gmove(&n1, res);
                        regfree(&n1);
                        break;
@@ -257,7 +257,7 @@ cgen(Node *n, Node *res)
                        agen(nl, &n1);
                        n1.op = OINDREG;
                        n1.type = types[TUINT32];
-                       n1.xoffset = offsetof(Array,nel);
+                       n1.xoffset = Array_nel;
                        gmove(&n1, res);
                        regfree(&n1);
                        break;
@@ -271,7 +271,7 @@ cgen(Node *n, Node *res)
                        cgen(nl, &n1);
                        n1.op = OINDREG;
                        n1.type = types[TUINT32];
-                       n1.xoffset = offsetof(Array,cap);
+                       n1.xoffset = Array_cap;
                        gmove(&n1, res);
                        regfree(&n1);
                        break;
@@ -281,7 +281,7 @@ cgen(Node *n, Node *res)
                        agen(nl, &n1);
                        n1.op = OINDREG;
                        n1.type = types[TUINT32];
-                       n1.xoffset = offsetof(Array,cap);
+                       n1.xoffset = Array_cap;
                        gmove(&n1, res);
                        regfree(&n1);
                        break;
@@ -491,7 +491,7 @@ agen(Node *n, Node *res)
                                        n1 = n3;
                                        n1.op = OINDREG;
                                        n1.type = types[tptr];
-                                       n1.xoffset = offsetof(Array, nel);
+                                       n1.xoffset = Array_nel;
                                        nodconst(&n2, types[TUINT64], v);
                                        gins(optoas(OCMP, types[TUINT32]), &n1, &n2);
                                        p1 = gbranch(optoas(OGT, types[TUINT32]), T);
@@ -502,7 +502,7 @@ agen(Node *n, Node *res)
                                n1 = n3;
                                n1.op = OINDREG;
                                n1.type = types[tptr];
-                               n1.xoffset = offsetof(Array, array);
+                               n1.xoffset = Array_array;
                                gmove(&n1, &n3);
                        } else
                        if(!debug['B']) {
@@ -540,7 +540,7 @@ agen(Node *n, Node *res)
                                n1 = n3;
                                n1.op = OINDREG;
                                n1.type = types[tptr];
-                               n1.xoffset = offsetof(Array, nel);
+                               n1.xoffset = Array_nel;
                        } else {
                                nodconst(&n1, types[TUINT64], nl->type->bound);
                                if(isptrsarray(nl->type))
@@ -556,7 +556,7 @@ agen(Node *n, Node *res)
                        n1 = n3;
                        n1.op = OINDREG;
                        n1.type = types[tptr];
-                       n1.xoffset = offsetof(Array, array);
+                       n1.xoffset = Array_array;
                        gmove(&n1, &n3);
                }
 
@@ -756,7 +756,7 @@ bgen(Node *n, int true, Prog *to)
                        agen(nl, &n1);
                        n2 = n1;
                        n2.op = OINDREG;
-                       n2.xoffset = offsetof(Array,array);
+                       n2.xoffset = Array_array;
                        nodconst(&tmp, types[tptr], 0);
                        gins(optoas(OCMP, types[tptr]), &n2, &tmp);
                        patch(gbranch(a, types[tptr]), to);
index 80a548f8aa64dc7e4103f44c1d8531875bc60980..8d44d67d4a2ef174f9c2b8ce684db460e3325a10 100644 (file)
@@ -119,6 +119,22 @@ EXTERN     Node*   newproc;
 EXTERN Node*   throwindex;
 EXTERN Node*   throwreturn;
 
+/*
+ * note this is the runtime representation
+ * of the compilers arrays.
+ *
+ * typedef     struct
+ * {                           // must not move anything
+ *     uchar   array[8];       // pointer to data
+ *     uchar   nel[4];         // number of elements
+ *     uchar   cap[4];         // allocated number of elements
+ * } Array;
+ */
+EXTERN int     Array_array;    // runtime offsetof(Array,array)
+EXTERN int     Array_nel;      // runtime offsetof(Array,nel)
+EXTERN int     Array_cap;      // runtime offsetof(Array,cap)
+EXTERN int     sizeof_Array;   // runtime sizeof(Array)
+
 /*
  * gen.c
  */
index daaf7132129ebe75c3fb9e5ea29a62805682e417..e19e85d5fe0d7402f71776cba7bb5565683988aa 100644 (file)
@@ -1965,7 +1965,7 @@ oindex:
                        n2 = *reg;
                        n2.op = OINDREG;
                        n2.type = types[tptr];
-                       n2.xoffset = offsetof(Array, nel);
+                       n2.xoffset = Array_nel;
                } else {
                        nodconst(&n2, types[TUINT64], l->type->bound);
                        if(o & OPtrto)
@@ -1981,7 +1981,7 @@ oindex:
                n2 = *reg;
                n2.op = OINDREG;
                n2.type = types[tptr];
-               n2.xoffset = offsetof(Array, array);
+               n2.xoffset = Array_array;
                gmove(&n2, reg);
        }
 
@@ -2011,7 +2011,7 @@ oindex_const:
                        n1 = *reg;
                        n1.op = OINDREG;
                        n1.type = types[tptr];
-                       n1.xoffset = offsetof(Array, nel);
+                       n1.xoffset = Array_nel;
                        nodconst(&n2, types[TUINT64], v);
                        gins(optoas(OCMP, types[TUINT32]), &n1, &n2);
                        p1 = gbranch(optoas(OGT, types[TUINT32]), T);
@@ -2022,7 +2022,7 @@ oindex_const:
                n1 = *reg;
                n1.op = OINDREG;
                n1.type = types[tptr];
-               n1.xoffset = offsetof(Array, array);
+               n1.xoffset = Array_array;
                gmove(&n1, reg);
 
        } else
index 6cd2eab5a67c8e4c5dd957cc5a2ab8d37176a887..c0faddd478c7aa006559a413638f7699612fdaf8 100644 (file)
@@ -61,20 +61,6 @@ struct       String
        char    s[3];   // variable
 };
 
-/*
- * note this is the runtime representation
- * of the compilers arrays. it is probably
- * insafe to use it this way, but it puts
- * all the changes in one place.
- */
-typedef        struct  Array   Array;
-struct Array
-{                              // must not move anything
-       uchar   array[8];       // pointer to data
-       uchar   nel[4];         // number of elements
-       uchar   cap[4];         // allocated number of elements
-};
-
 /*
  * note this is the runtime representation
  * of hashmap iterator. it is probably
index 35d062524c310ebee790041890132a919b66ef8b..be0dd255051ede12e52eee89e84a29310429377b 100644 (file)
@@ -1873,6 +1873,8 @@ ascompat(Type *t1, Type *t2)
 //     if(eqtype(t2, nilptr, 0))
 //             return 1;
 
+       if(issarray(t1))
+               return 0;
        if(isnilinter(t1))
                return 1;
        if(isinter(t1)) {