Commit 94df1a06 authored by Anthony Martin's avatar Anthony Martin Committed by Russ Cox

gc: return constant floats for parts of complex constants

Fixes #1369.

R=rsc
CC=golang-dev
https://golang.org/cl/3731046
parent c0332fc9
......@@ -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);
......
......@@ -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)
{
......
......@@ -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;
}
......
// $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() {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment