mirror of
https://github.com/golang/go
synced 2024-11-22 00:54:43 -07:00
gc: return constant floats for parts of complex constants
Fixes #1369. R=rsc CC=golang-dev https://golang.org/cl/3731046
This commit is contained in:
parent
c0332fc93f
commit
94df1a067c
@ -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;
|
||||
}
|
||||
|
17
test/fixedbugs/bug316.go
Normal file
17
test/fixedbugs/bug316.go
Normal file
@ -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() {}
|
Loading…
Reference in New Issue
Block a user