]> Cypherpunks repositories - gostls13.git/commitdiff
bug104
authorKen Thompson <ken@golang.org>
Fri, 12 Dec 2008 21:10:36 +0000 (13:10 -0800)
committerKen Thompson <ken@golang.org>
Fri, 12 Dec 2008 21:10:36 +0000 (13:10 -0800)
R=r
OCL=21082
CL=21082

src/cmd/gc/const.c
src/cmd/gc/go.h
src/cmd/gc/walk.c

index a61ebe5ee153b53aeb228020d6137d50ccc5e57b..d8e38300d4c54aa57bbb563e748f4381b2c56149 100644 (file)
@@ -34,7 +34,7 @@ truncfltlit(Mpflt *fv, Type *t)
 }
 
 void
-convlit(Node *n, Type *t)
+convlit1(Node *n, Type *t, int conv)
 {
        int et, wt;
 
@@ -92,21 +92,6 @@ convlit(Node *n, Type *t)
                        defaultlit(n);
                        return;
                }
-               if(isptrto(t, TSTRING)) {
-                       Rune rune;
-                       int l;
-                       String *s;
-
-                       rune = mpgetfix(n->val.u.xval);
-                       l = runelen(rune);
-                       s = mal(sizeof(*s)+l);
-                       s->len = l;
-                       runetochar((char*)(s->s), &rune);
-
-                       n->val.u.sval = s;
-                       n->val.ctype = CTSTR;
-                       break;
-               }
                if(isint[et]) {
                        // int to int
                        if(mpcmpfixfix(n->val.u.xval, minintval[et]) < 0)
@@ -132,6 +117,25 @@ convlit(Node *n, Type *t)
                        truncfltlit(fv, t);
                        break;
                }
+               if(!conv)
+                       goto bad1;
+
+               // only done as string(CONST)
+               if(isptrto(t, TSTRING)) {
+                       Rune rune;
+                       int l;
+                       String *s;
+
+                       rune = mpgetfix(n->val.u.xval);
+                       l = runelen(rune);
+                       s = mal(sizeof(*s)+l);
+                       s->len = l;
+                       runetochar((char*)(s->s), &rune);
+
+                       n->val.u.sval = s;
+                       n->val.ctype = CTSTR;
+                       break;
+               }
                goto bad1;
 
        case Wlitfloat:
@@ -186,6 +190,12 @@ bad3:
        return;
 }
 
+void
+convlit(Node *n, Type *t)
+{
+       convlit1(n, t, 0);
+}
+
 void
 evconst(Node *n)
 {
index 8ab5c24dae393ae284e441b2d8cb5ff7debc684f..81371f41d4b4e48f5ea85e13658f6fa95171f17b 100644 (file)
@@ -822,6 +822,7 @@ Node*       old2new(Node*, Type*);
 /*
  *     const.c
  */
+void   convlit1(Node*, Type*, int);
 void   convlit(Node*, Type*);
 void   evconst(Node*);
 int    cmpslit(Node *l, Node *r);
index c0b78d69df1ad2ffc3c18213f0133b76acb10aa9..7c17794a5d240cb95822c46af359ac58ceaf7c2c 100644 (file)
@@ -560,7 +560,7 @@ loop:
                        goto ret;
 
                if(!iscomposite(t))
-                       convlit(l, t);
+                       convlit1(l, t, 1);
 
                // nil conversion
                if(eqtype(t, l->type, 0)) {