]> Cypherpunks repositories - gostls13.git/commitdiff
gc: return constant floats for parts of complex constants
authorAnthony Martin <ality@pbrane.org>
Wed, 5 Jan 2011 18:12:30 +0000 (13:12 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 5 Jan 2011 18:12:30 +0000 (13:12 -0500)
Fixes #1369.

R=rsc
CC=golang-dev
https://golang.org/cl/3731046

src/cmd/gc/go.h
src/cmd/gc/subr.c
src/cmd/gc/typecheck.c
test/fixedbugs/bug316.go [new file with mode: 0644]

index 4b48ad55eac8a9709477271aed7f16ceab245115..73ea5b9767468bf0267c4e05557a107055e020ef 100644 (file)
@@ -1106,6 +1106,7 @@ Node*     nod(int op, Node *nleft, Node *nright);
 Node*  nodbool(int b);
 void   nodconst(Node *n, Type *t, int64 v);
 Node*  nodintconst(int64 v);
+Node*  nodfltconst(Mpflt *v);
 Node*  nodnil(void);
 int    parserline(void);
 Sym*   pkglookup(char *name, Pkg *pkg);
index 9b6c79d8665be83f3b90c9e5ab97930e643fadfa..3c450109629de46d5f910aed5996d09957b6b32b 100644 (file)
@@ -592,6 +592,21 @@ nodintconst(int64 v)
        return c;
 }
 
+Node*
+nodfltconst(Mpflt* v)
+{
+       Node *c;
+
+       c = nod(OLITERAL, N, N);
+       c->addable = 1;
+       c->val.u.fval = mal(sizeof(*c->val.u.fval));
+       mpmovefltflt(c->val.u.fval, v);
+       c->val.ctype = CTFLT;
+       c->type = types[TIDEAL];
+       ullmancalc(c);
+       return c;
+}
+
 void
 nodconst(Node *n, Type *t, int64 v)
 {
index 4dd0d706bd1da6e639de8d188788c2c63e9fd719..ca114d47cdc637129e1b6bfcb9bcb3c883ed835e 100644 (file)
@@ -829,6 +829,12 @@ reswitch:
                case OIMAG:
                        if(!iscomplex[t->etype])
                                goto badcall1;
+                       if(isconst(l, CTCPLX)){
+                               if(n->op == OREAL)
+                                       n = nodfltconst(&l->val.u.cval->real);
+                               else
+                                       n = nodfltconst(&l->val.u.cval->imag);
+                       }
                        n->type = types[cplxsubtype(t->etype)];
                        goto ret;
                }
diff --git a/test/fixedbugs/bug316.go b/test/fixedbugs/bug316.go
new file mode 100644 (file)
index 0000000..bd4d99e
--- /dev/null
@@ -0,0 +1,17 @@
+// $G $D/$F.go || echo BUG: bug316
+
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 1369.
+
+package main
+
+const (
+       c = cmplx(1, 2)
+       r = real(c) // was: const initializer must be constant
+       i = imag(c) // was: const initializer must be constant
+)
+
+func main() {}