summaryrefslogtreecommitdiff
path: root/src/cmd/gc
diff options
context:
space:
mode:
authorKen Thompson <ken@golang.org>2010-03-09 13:39:45 -0800
committerKen Thompson <ken@golang.org>2010-03-09 13:39:45 -0800
commite6c5d112eced3e278e12dee69dc8d41618761fed (patch)
tree91478d57085967c0ffe235b2fe7f79ce50d328ae /src/cmd/gc
parentb129670ca135bd6be7b4afcadeb0bcec0675789e (diff)
downloadgolang-e6c5d112eced3e278e12dee69dc8d41618761fed.tar.gz
fix bugs compiling things like
c = cmplx(imag(c), real(c)) without a temporary R=rsc CC=golang-dev http://codereview.appspot.com/360043
Diffstat (limited to 'src/cmd/gc')
-rw-r--r--src/cmd/gc/cplx.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/cmd/gc/cplx.c b/src/cmd/gc/cplx.c
index 23f339914..7538a432a 100644
--- a/src/cmd/gc/cplx.c
+++ b/src/cmd/gc/cplx.c
@@ -123,7 +123,7 @@ complexgen(Node *n, Node *res)
{
Node *nl, *nr;
Node tnl, tnr;
- Node n1, n2;
+ Node n1, n2, tmp;
int tl, tr;
if(debug['g']) {
@@ -135,8 +135,10 @@ complexgen(Node *n, Node *res)
switch(n->op) {
case OCMPLX:
subnode(&n1, &n2, res);
- cgen(n->left, &n1);
+ tempname(&tmp, n1.type);
+ cgen(n->left, &tmp);
cgen(n->right, &n2);
+ cgen(&tmp, &n1);
return;
case OREAL:
@@ -428,19 +430,21 @@ complexadd(int op, Node *nl, Node *nr, Node *res)
}
// build and execute tree
-// real(res) = real(nl)*real(nr) - imag(nl)*imag(nr)
+// tmp = real(nl)*real(nr) - imag(nl)*imag(nr)
// imag(res) = real(nl)*imag(nr) + imag(nl)*real(nr)
+// real(res) = tmp
void
complexmul(Node *nl, Node *nr, Node *res)
{
Node n1, n2, n3, n4, n5, n6;
- Node rm1, rm2, ra;
+ Node rm1, rm2, ra, tmp;
subnode(&n1, &n2, nl);
subnode(&n3, &n4, nr);
subnode(&n5, &n6, res);
+ tempname(&tmp, n5.type);
- // real part
+ // real part -> tmp
memset(&rm1, 0, sizeof(ra));
rm1.op = OMUL;
rm1.left = &n1;
@@ -458,7 +462,7 @@ complexmul(Node *nl, Node *nr, Node *res)
ra.left = &rm1;
ra.right = &rm2;
ra.type = rm1.type;
- cgen(&ra, &n5);
+ cgen(&ra, &tmp);
// imag part
memset(&rm1, 0, sizeof(ra));
@@ -479,4 +483,7 @@ complexmul(Node *nl, Node *nr, Node *res)
ra.right = &rm2;
ra.type = rm1.type;
cgen(&ra, &n6);
+
+ // tmp ->real part
+ cgen(&tmp, &n5);
}